Compile PDF and EPUB files from static Web assets.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

98 lines
1.9 KiB

  1. import {
  2. describe,
  3. it,
  4. expect,
  5. vi,
  6. beforeEach,
  7. Mock, afterEach,
  8. } from 'vitest';
  9. import { readFile, readdir } from 'fs/promises';
  10. import { compileFromInput } from '../../src/compilers/path';
  11. vi.mock('fs/promises');
  12. const completeBookFile = {
  13. title: 'Astro Sandbox',
  14. publisher: '',
  15. creator: 'John Doe',
  16. contributors: [
  17. 'Jane Doe'
  18. ],
  19. description: 'Retrieve from package.json',
  20. subjects: [
  21. 'A subject of the publication',
  22. 'Another subject of the publication'
  23. ],
  24. rights: '© copyright notice or get from package.json LICENSE'
  25. };
  26. describe('path compiler', () => {
  27. let mockReaddir: Mock;
  28. beforeEach(() => {
  29. mockReaddir = readdir as Mock;
  30. });
  31. afterEach(() => {
  32. mockReaddir.mockReset();
  33. });
  34. let mockReadFile: Mock;
  35. beforeEach(() => {
  36. mockReadFile = readFile as Mock;
  37. });
  38. afterEach(() => {
  39. mockReadFile.mockReset();
  40. });
  41. it('gets a list of file buffers', async () => {
  42. mockReaddir.mockResolvedValue([
  43. 'patchouli.book.json',
  44. 'patchouli.binding.json',
  45. ]);
  46. mockReadFile.mockImplementation(async (path: string) => {
  47. if (path.endsWith('/patchouli.book.json')) {
  48. return JSON.stringify(completeBookFile);
  49. }
  50. if (path.endsWith('/patchouli.binding.json')) {
  51. return JSON.stringify({
  52. });
  53. }
  54. return '';
  55. });
  56. await compileFromInput({
  57. path: 'path/to/project',
  58. });
  59. });
  60. describe('astro', () => {
  61. it('reads the binding file', async () => {
  62. mockReaddir.mockResolvedValue([
  63. 'patchouli.book.json',
  64. 'patchouli.binding.json',
  65. ]);
  66. mockReadFile.mockImplementation(async (path: string) => {
  67. if (path.endsWith('/patchouli.book.json')) {
  68. return JSON.stringify(completeBookFile);
  69. }
  70. if (path.endsWith('/patchouli.binding.json')) {
  71. return JSON.stringify({
  72. generatorDistDirectory: './custom-dir',
  73. });
  74. }
  75. return '';
  76. });
  77. await compileFromInput({
  78. path: 'path/to/project',
  79. });
  80. });
  81. });
  82. });