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

feat(config): add better support for TypeScript #368

Merged
merged 2 commits into from
May 28, 2024
Merged

Conversation

wjhsf
Copy link
Contributor

@wjhsf wjhsf commented May 22, 2024

TypeScript is supported by @lwc/jest-preset, but not by sfdx-lwc-jest, even though sfdx-lwc-jest builds on @lwc/jest-preset.

moduleFileExtensions: ['js', 'html'],
testEnvironment: jestPreset.testEnvironment || 'jsdom',
transform: {
'^.+\\.(js|html|css)$': require.resolve('@lwc/jest-transformer'),
},

This PR updates the config provided by sfdx-lwc-jest to support TypeScript by using more of @lwc/jest-preset.

Comment on lines +32 to +41
moduleFileExtensions: jestPreset.moduleFileExtensions || ['ts', 'js', 'html'],
testEnvironment: jestPreset.testEnvironment || 'jsdom',
transform: {
'^.+\\.(js|html|css)$': require.resolve('@lwc/jest-transformer'),
...jestPreset.transform,
'^.+\\.(js|ts|html|css)$': require.resolve('@lwc/jest-transformer'),
},
setupFilesAfterEnv: jestPreset.setupFilesAfterEnv || [],
snapshotSerializers: jestPreset.snapshotSerializers || [
require.resolve('@lwc/jest-serializer'),
],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why we have the pattern of jestPreset.prop || 'hard-coded value matching jestPreset' when we depend on a version of jestPreset where it's always defined, but I kept the pattern.

I also considered changing this section to just ...jestPreset, but that would add in testMatch and coveragePathIgnorePatterns, and I don't know whether we want to do that.

@wjhsf wjhsf requested a review from jmsjtu May 22, 2024 20:26
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

Successfully merging this pull request may close these issues.

2 participants