Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Akita 7 fails in jest #781

Closed
Yuval-Ben-Arie opened this issue Dec 20, 2021 · 7 comments
Closed

Akita 7 fails in jest #781

Yuval-Ben-Arie opened this issue Dec 20, 2021 · 7 comments

Comments

@Yuval-Ben-Arie
Copy link

Yuval-Ben-Arie commented Dec 20, 2021

Is this a regression?

No

Description

jest.config.js file:

require('jest-preset-angular/ngcc-jest-processor');
const { pathsToModuleNameMapper } = require('ts-jest/utils');
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { compilerOptions } = require('./tsconfig');
process.env.TZ = 'UTC';
module.exports = {
preset: 'jest-preset-angular',
setupFilesAfterEnv: ['/setup-jest.ts'],
reporters: [ 'default', 'jest-junit' ],
testResultsProcessor: 'jest-junit',
transformIgnorePatterns: [
'/node_modules/(?!lodash-es)',
],
globals: {
'ts-jest': {
tsconfig: '/src/tsconfig.spec.json',
diagnostics: {
ignoreCodes: [151001]
}
}
},
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '/' }),
modulePathIgnorePatterns: ['/cypress']
};

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

    Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

    By default "node_modules" folder is ignored by transformers.

    Here's what you can do:
     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
     • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/configuration
    For information about custom transformations, see:
    https://jestjs.io/docs/code-transformation

    Details:

    C:\Users\ybena\Desktop\angularApp\SL.Web.App\node_modules\@datorama\akita\src\index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export * from './lib/index';
                                                                                      ^^^^^^

    SyntaxError: Unexpected token 'export'

Please provide the environment you discovered this bug in

jest 27.3.1
akita 7.0.1
angular 12.2.13

Anything else?

No response

Do you want to create a pull request?

No

@theorlovsky
Copy link
Contributor

I've been getting the same error with angular and nx 13. Managed to fix it by changing

transformIgnorePatterns: ['node_modules/(?!.*.mjs$)']

to

transformIgnorePatterns: ['node_modules/(?!.*.mjs$|@datorama/akita)']

in jest.config.js of failing projects.

Adding it to the same regex is very important, it won't work if I keep it in separate strings.

@VolodymyrKornetskyi
Copy link

@theorlovsky Your fix is working perfectly! Thank you very much!!!!

@yonzmeer
Copy link

It works but running my tests (in nx) takes much longer

@NetanelBasal
Copy link
Collaborator

The repo is updated now. I'll release new versions soon.

@jedieaston
Copy link

@NetanelBasal I've upgraded a project to Akita 8.0.0 and I'm still getting this same issue with Jest (where it expects akita isn't going to do an export since it's a .js file). Is there something else that needs to be fixed on my end for this to work?

@mitchdowd
Copy link

Not resolved in version 8.

@madhanhere
Copy link

madhanhere commented Oct 3, 2023

@NetanelBasal Upgraded the @datorama/akita: 8.0.1, and updated
transformIgnorePatterns: [ 'node_modules/(?!.*.mjs$|@datorama/akita)'] in jest.config.ts

Unit tests take more time to run. Is there any fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants