|
- import {
- describe,
- it,
- expect,
- vi,
- beforeEach,
- Mock, afterEach,
- } from 'vitest';
- import { readFile, readdir } from 'fs/promises';
- import { compileFromInput } from '../../src/compilers/dir';
-
- vi.mock('fs/promises');
-
- const completeBookFile = {
- title: 'Astro Sandbox',
- publisher: '',
- creator: 'John Doe',
- contributors: [
- 'Jane Doe'
- ],
- description: 'Retrieve from package.json',
- subjects: [
- 'A subject of the publication',
- 'Another subject of the publication'
- ],
- rights: '© copyright notice or get from package.json LICENSE'
- };
-
- describe('dir compiler', () => {
- let mockReaddir: Mock;
- beforeEach(() => {
- mockReaddir = readdir as Mock;
- });
- afterEach(() => {
- mockReaddir.mockReset();
- });
-
- let mockReadFile: Mock;
- beforeEach(() => {
- mockReadFile = readFile as Mock;
- });
- afterEach(() => {
- mockReadFile.mockReset();
- });
-
- it('gets a list of file buffers', async () => {
- mockReaddir.mockResolvedValue([
- 'patchouli.book.json',
- 'patchouli.binding.json',
- ]);
-
- mockReadFile.mockImplementation(async (path: string) => {
- if (path.endsWith('/patchouli.book.json')) {
- return JSON.stringify(completeBookFile);
- }
-
- if (path.endsWith('/patchouli.binding.json')) {
- return JSON.stringify({
-
- });
- }
-
- return '';
- });
-
- await compileFromInput({
- path: 'path/to/project',
- });
- });
-
- describe('astro', () => {
- it('reads the binding file', async () => {
- mockReaddir.mockResolvedValue([
- 'patchouli.book.json',
- 'patchouli.binding.json',
- ]);
-
- mockReadFile.mockImplementation(async (path: string) => {
- if (path.endsWith('/patchouli.book.json')) {
- return JSON.stringify(completeBookFile);
- }
-
- if (path.endsWith('/patchouli.binding.json')) {
- return JSON.stringify({
- generatorDistDirectory: './custom-dir',
- });
- }
-
- return '';
- });
-
- await compileFromInput({
- path: 'path/to/project',
- });
- });
- });
- });
|