From 0ef561b031c78318a36959baf73bf48e00da4625 Mon Sep 17 00:00:00 2001 From: Will Harney <62956339+wjhsf@users.noreply.github.com> Date: Tue, 28 May 2024 13:33:09 -0400 Subject: [PATCH] feat(config): add better support for TypeScript (#368) * feat(config): add support for typescript files * feat(config): use more jest-preset --- src/config.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/config.js b/src/config.js index b815e20..4664545 100644 --- a/src/config.js +++ b/src/config.js @@ -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'), + ], + // Specific to sfdx-lwc-jest + collectCoverageFrom: getCoveragePaths(), + resolver: path.join(__dirname, './resolver.js'), + rootDir: PROJECT_ROOT, + testPathIgnorePatterns: ['/node_modules/', '/test/specs/'], transformIgnorePatterns: [ '/node_modules/(?!(.*@salesforce/sfdx-lwc-jest/src/lightning-stubs)/)', ], - setupFilesAfterEnv: jestPreset.setupFilesAfterEnv || [], - resolver: path.resolve(__dirname, './resolver.js'), - testPathIgnorePatterns: ['/node_modules/', '/test/specs/'], - collectCoverageFrom: getCoveragePaths(), - snapshotSerializers: [require.resolve('@lwc/jest-serializer')], }; const expectedApiVersion = '61.0';