jest-angular-import-meta
is a package designed to solve the issue of SyntaxError: Cannot use 'import.meta' outside a module
that occurs when using Worker with Angular 12+ and Jest. This package replaces the import.meta.url
token with __dirname
in order to make the tests pass instead of fail.
You can install jest-angular-import-meta
using npm:
npm install @hudsontavares/jest-angular-import-meta
or yarn:
yarn add @hudsontavares/jest-angular-import-meta
To use jest-angular-import-meta
, you need to configure your TypeScript compiler to apply the transformation provided by the package. Here's an example of how you can do this with ts-jest
:
// jest.config.js
module.exports = {
// ...
globals: {
'ts-jest': {
// ...
astTransformers: {
before: [
'@hudsontavares/jest-angular-import-meta',
],
},
},
},
};
After configuring ts-jest
, the import.meta.url
references in your code will be transformed to use __dirname
instead, resolving the SyntaxError
issue.
Contributions to jest-angular-import-meta
are welcome! If you find a bug or have a suggestion, please open an issue on the GitHub repository. Pull requests are also appreciated.
This package is licensed under the Apache-2.0.