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

jest snapshotSerializers not loaded from jest-preset-angular (can't use <rootDir>) #813

Closed
llwt opened this issue Oct 12, 2018 · 4 comments

Comments

@llwt
Copy link
Contributor

llwt commented Oct 12, 2018

It looks like there are issues using <rooDir> in paths inside the jest.config.js.

I had to do the following in the root jest.config.js to get it working:

  • remove rootDir references from our transformIgnorePatterns (see How to set transformIgnorePatterns to fix "Jest encountered an unexpected token" #812)
  • update our local transform references to use path.resolve and re-add snapshotSerializers
    • before: 'sass-to-ts.scss': '<rootDir>/tools/sass-extract-preprocessor.js',
    • after: 'sass-to-ts.scss': path.resolve(__dirname, 'tools/sass-extract-preprocessor.js'),
  • re-add snapshotSerializers from jest-preset-angular without rootDir:
  snapshotSerializers: [
    'jest-preset-angular/AngularSnapshotSerializer.js',
    'jest-preset-angular/HTMLCommentSerializer.js',
  ],

@FrozenPandaz Is there a better way to handle this?

@FrozenPandaz
Copy link
Collaborator

I like adding this. Do you have a particular issue with it?

snapshotSerializers: [
    'jest-preset-angular/AngularSnapshotSerializer.js',
    'jest-preset-angular/HTMLCommentSerializer.js',
  ],

If something is a node_module, I would personally always use the above approach. If it is your own transformer or jest plugin, I think adding them to tools is a good solution (and that's really cool).

@llwt
Copy link
Contributor Author

llwt commented Nov 27, 2018

👍 That sounds good to me.

It doesn't currently cause issues, but this basically just duplicates the snapshotSerializers defined in jest-preset-angular, imported by the generated in <lib>/src/test-setup.ts, sans <root-dir>. It seems to silently fail when defining a serializer who's path doesn't exist. Just something to be aware of in case that functionality changes within jest.

@FrozenPandaz
Copy link
Collaborator

This issue seems resolved now. Please let us know if you continue having issues.

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants