diff --git a/tests/prep-now.test.ts b/tests/prep-now.test.ts new file mode 100644 index 0000000..9f33aef --- /dev/null +++ b/tests/prep-now.test.ts @@ -0,0 +1,121 @@ +import { readFileSync, writeFileSync, copyFileSync } from 'node:fs' +import { fileURLToPath } from 'node:url' +import { dirname, resolve } from 'node:path' + +import { describe, it, expect, vi, beforeEach } from 'vitest' +import { consola } from 'consola' + +import newNow from '../commands/prep-now' + +// Mock file system operations +vi.mock('path', () => ({ + resolve: vi.fn(), + readFileSync: vi.fn(), + writeFileSync: vi.fn(), + copyFileSync: vi.fn(), +})) + +// Mock consola +vi.mock('consola', () => ({ + consola: { + box: vi.fn(), + start: vi.fn(), + success: vi.fn(), + fail: vi.fn(), + error: vi.fn(), + }, +})) + +// Mock mdToHTML +vi.mock('../command/md-to-html', () => ({ + mdToHTML: vi.fn(), +})) + +describe('prep-now', () => { + // const mockNow = { + // title: 'Test Title', + // description: 'Test Description', + // publishedOn: '2023-01-01', + // publishDate: '2023-01-01', + // publishState: 'draft', + // content: '# Test Content', + // } + + beforeEach(() => { + vi.clearAllMocks() + vi.mocked(resolve).mockImplementation((...paths) => paths.join('/')) + vi.mocked(readFileSync).mockReturnValue('template content') + vi.mocked(writeFileSync).mockImplementation(() => {}) + vi.mocked(copyFileSync).mockImplementation(() => {}) + vi.mocked(consola.box).mockImplementation(() => {}) + vi.mocked(consola.start).mockImplementation(() => {}) + vi.mocked(consola.success).mockImplementation(() => {}) + vi.mocked(consola.fail).mockImplementation(() => {}) + vi.mocked(consola.error).mockImplementation(() => {}) + }) + + it('should create a new now page and clear the original files', async () => { + // Mock the mdToHTML function + const { mdToHTML } = await import('../utils/md-to-html') + vi.mocked(mdToHTML).mockResolvedValue('