-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(plugin-coverage): support non-cjs jest configs
refactored importEsmModule->importModule to be format-agnostic by default fix #726
- Loading branch information
1 parent
f9718bd
commit 3fc351c
Showing
7 changed files
with
34 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = 'valid-cjs-module-export'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,41 @@ | ||
import { join } from 'node:path'; | ||
import { describe, expect, it } from 'vitest'; | ||
import { importEsmModule } from './file-system'; | ||
import { importModule } from './file-system'; | ||
|
||
describe('importEsmModule', () => { | ||
describe('importModule', () => { | ||
const mockDir = join(process.cwd(), 'packages', 'utils', 'mocks', 'fixtures'); | ||
|
||
it('should load a valid ES module', async () => { | ||
await expect( | ||
importEsmModule({ | ||
importModule({ | ||
filepath: join(mockDir, 'valid-es-module-export.mjs'), | ||
}), | ||
).resolves.toBe('valid-es-module-export'); | ||
}); | ||
|
||
it('should throw if the file does not exist', async () => { | ||
it('should load a valid CommonJS module', async () => { | ||
await expect( | ||
importEsmModule({ | ||
filepath: 'path/to/non-existent-export.mjs', | ||
importModule({ | ||
filepath: join(mockDir, 'valid-cjs-module-export.cjs'), | ||
}), | ||
).rejects.toThrow('non-existent-export.mjs'); | ||
).resolves.toBe('valid-cjs-module-export'); | ||
}); | ||
|
||
it('should throw if the file does not have any default export', async () => { | ||
it('should load an ES module without default export', async () => { | ||
await expect( | ||
importEsmModule({ | ||
importModule({ | ||
filepath: join(mockDir, 'no-default-export.mjs'), | ||
}), | ||
).rejects.toThrow('No default export found'); | ||
).resolves.toEqual( | ||
expect.objectContaining({ exportedVar: 'exported-variable' }), | ||
); | ||
}); | ||
|
||
it('should throw if the file does not exist', async () => { | ||
await expect( | ||
importModule({ | ||
filepath: 'path/to/non-existent-export.mjs', | ||
}), | ||
).rejects.toThrow('non-existent-export.mjs'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters