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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,25 @@ function getCoveragePaths() {
}

const jestConfig = {
rootDir: PROJECT_ROOT,
moduleFileExtensions: ['js', 'html'],
// Inherited from @lwc/jest-preset
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'),
],
Comment on lines +32 to +41
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.

// Specific to sfdx-lwc-jest
collectCoverageFrom: getCoveragePaths(),
resolver: path.join(__dirname, './resolver.js'),
rootDir: PROJECT_ROOT,
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/test/specs/'],
transformIgnorePatterns: [
'/node_modules/(?!(.*@salesforce/sfdx-lwc-jest/src/lightning-stubs)/)',
],
setupFilesAfterEnv: jestPreset.setupFilesAfterEnv || [],
resolver: path.resolve(__dirname, './resolver.js'),
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/test/specs/'],
collectCoverageFrom: getCoveragePaths(),
snapshotSerializers: [require.resolve('@lwc/jest-serializer')],
};

const expectedApiVersion = '61.0';
Expand Down