|
1 | 1 | import { join } from 'node:path'; |
2 | 2 | import { describe, expect, it } from 'vitest'; |
3 | | -import { importEsmModule } from './file-system'; |
| 3 | +import { importModule } from './file-system'; |
4 | 4 |
|
5 | | -describe('importEsmModule', () => { |
| 5 | +describe('importModule', () => { |
6 | 6 | const mockDir = join(process.cwd(), 'packages', 'utils', 'mocks', 'fixtures'); |
7 | 7 |
|
8 | 8 | it('should load a valid ES module', async () => { |
9 | 9 | await expect( |
10 | | - importEsmModule({ |
| 10 | + importModule({ |
11 | 11 | filepath: join(mockDir, 'valid-es-module-export.mjs'), |
12 | 12 | }), |
13 | 13 | ).resolves.toBe('valid-es-module-export'); |
14 | 14 | }); |
15 | 15 |
|
16 | | - it('should throw if the file does not exist', async () => { |
| 16 | + it('should load a valid CommonJS module', async () => { |
17 | 17 | await expect( |
18 | | - importEsmModule({ |
19 | | - filepath: 'path/to/non-existent-export.mjs', |
| 18 | + importModule({ |
| 19 | + filepath: join(mockDir, 'valid-cjs-module-export.cjs'), |
20 | 20 | }), |
21 | | - ).rejects.toThrow('non-existent-export.mjs'); |
| 21 | + ).resolves.toBe('valid-cjs-module-export'); |
22 | 22 | }); |
23 | 23 |
|
24 | | - it('should throw if the file does not have any default export', async () => { |
| 24 | + it('should load an ES module without default export', async () => { |
25 | 25 | await expect( |
26 | | - importEsmModule({ |
| 26 | + importModule({ |
27 | 27 | filepath: join(mockDir, 'no-default-export.mjs'), |
28 | 28 | }), |
29 | | - ).rejects.toThrow('No default export found'); |
| 29 | + ).resolves.toEqual( |
| 30 | + expect.objectContaining({ exportedVar: 'exported-variable' }), |
| 31 | + ); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should throw if the file does not exist', async () => { |
| 35 | + await expect( |
| 36 | + importModule({ |
| 37 | + filepath: 'path/to/non-existent-export.mjs', |
| 38 | + }), |
| 39 | + ).rejects.toThrow('non-existent-export.mjs'); |
30 | 40 | }); |
31 | 41 | }); |
0 commit comments