Jest builder with jest-preset-angular v7
See original GitHub issueIs your feature request related to a problem? Please describe.
I can’t run tests with jest-preset-angular@^7.0.0
.
Describe the solution you’d like
Update @angular-builders/jest
to support jest-preset-angular v7.
Describe alternatives you’ve considered None.
Additional context Changes:
diff --git a/packages/jest/package.json b/packages/jest/package.json
index c56f049..8772b7c 100644
--- a/packages/jest/package.json
+++ b/packages/jest/package.json
@@ -29,11 +29,11 @@
"e2e": "../../node_modules/.bin/jest --config ../../jest-e2e.config.js"
},
"dependencies": {
- "jest-preset-angular": "^6.0.0",
+ "jest-preset-angular": "^7.0.0",
"lodash": "^4.17.10"
},
"peerDependencies": {
"@angular-devkit/build-angular": ">=0.13.2",
- "jest": ">= 23"
+ "jest": ">= 24"
}
}
diff --git a/packages/jest/src/default-config.resolver.spec.ts b/packages/jest/src/default-config.resolver.spec.ts
index db90fac..2aad037 100644
--- a/packages/jest/src/default-config.resolver.spec.ts
+++ b/packages/jest/src/default-config.resolver.spec.ts
@@ -8,7 +8,7 @@ const defaultConfigResolver = new DefaultConfigResolver();
describe('Resolve project default configuration', () => {
it('Should resolve tsconfig relatively to project root', () => {
const config = defaultConfigResolver.resolveForProject(normalize('/some/cool/directory'));
- expect(config.globals['ts-jest'].tsConfigFile).toEqual(getSystemPath(normalize(`/some/cool/directory/${tsConfigName}`)));
+ expect(config.globals['ts-jest'].tsConfig).toEqual(getSystemPath(normalize(`/some/cool/directory/${tsConfigName}`)));
});
it('Should resolve testMatch pattern relatively to project root', () => {
@@ -29,9 +29,6 @@ describe('Resolve global default configuration', () => {
getSystemPath(join(workSpaceRoot, `node_modules/jest-preset-angular/AngularSnapshotSerializer.js`)),
getSystemPath(join(workSpaceRoot, `node_modules/jest-preset-angular/HTMLCommentSerializer.js`))
],
- transform: {
- "^.+\\.(ts|js|html)$": getSystemPath(join(workSpaceRoot, `node_modules/jest-preset-angular/preprocessor.js`))
- },
})
});
});
diff --git a/packages/jest/src/default-config.resolver.ts b/packages/jest/src/default-config.resolver.ts
index 5e1175d..7f92823 100644
--- a/packages/jest/src/default-config.resolver.ts
+++ b/packages/jest/src/default-config.resolver.ts
@@ -4,19 +4,14 @@ import defaultConfig from "./jest-config/default-config";
export const testPattern = `/**/+(*.)+(spec|test).+(ts|js)?(x)`;
export const tsConfigName = 'tsconfig.spec.json';
export const jestPresetRootPath = `node_modules/jest-preset-angular`;
-export const preprocessor = 'preprocessor.js';
export const snapshotSerializer = 'AngularSnapshotSerializer.js';
export const htmlCommentSerializer = 'HTMLCommentSerializer.js';
-export const transformRegex = '^.+\\.(ts|js|html)$';
export class DefaultConfigResolver {
resolveGlobal(workspaceRoot: Path): any {
const jestPresetFullPath = join(workspaceRoot, jestPresetRootPath);
return {...defaultConfig,
- transform: {
- [transformRegex] : getSystemPath(join(jestPresetFullPath, preprocessor))
- },
snapshotSerializers: [
getSystemPath(join(jestPresetFullPath, snapshotSerializer)),
getSystemPath(join(jestPresetFullPath, htmlCommentSerializer))
@@ -28,7 +23,7 @@ export class DefaultConfigResolver {
return {
globals: {
'ts-jest': {
- tsConfigFile: getSystemPath(join(projectRoot, tsConfigName))
+ tsConfig: getSystemPath(join(projectRoot, tsConfigName))
}
},
testMatch: [
diff --git a/packages/jest/src/jest-config/default-config.ts b/packages/jest/src/jest-config/default-config.ts
index 5b14d6a..2da8ff5 100644
--- a/packages/jest/src/jest-config/default-config.ts
+++ b/packages/jest/src/jest-config/default-config.ts
@@ -1,10 +1,7 @@
export default {
- globals: {
- "__TRANSFORM_HTML__": true
- },
preset: 'jest-preset-angular',
testURL: 'https://github.com/@angular-cli-builders',
- setupTestFrameworkScriptFile: `${__dirname}/setup.js`,
+ setupFilesAfterEnv: [`${__dirname}/setup.js`],
moduleNameMapper: {
'\\.(jpg|jpeg|png)$': `${__dirname}/mock-module.js`
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:10 (6 by maintainers)
Top Results From Across the Web
@angular-builders/jest - npm
Jest runner for Angular build facade. Allows ng test run with Jest instead of Karma. Latest version: 14.1.0, last published: a month ago....
Read more >angular-builders/jest NPM
Jest builder for Angular build facade · Prerequisits · Installation · Updating Typescript configurations · Running with Angular CLI · Builder options ·...
Read more >Angular >=13 | jest-preset-angular - GitHub Pages
Angular 13 introduces ESM package format for Angular packages. jest-preset-angular currently supports testing with Jest in CommonJS mode with Angular 13 using ...
Read more >cannot find module '@angular/core/testing' from ... - You.com
Angular >=13. Angular 13 introduces ESM package format for Angular packages. jest-preset-angular currently supports testing with Jest in CommonJS mode ...
Read more >Preset jest.preset.js not found" when using IntelliJ to run Jest ...
spec.json' } }, setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'], snapshotSerializers : [ 'jest-preset-angular/build/serializers/no-ng- ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hello there, am i able to help with this somehow? Let me know if there is anything i can do.
@meltedspark You’re right and finally I’m agree with you.
@wesleygrimes
Initially yes because @meltedspark suggested it. But If you prefer I can collaborate to the existing PR. What do you prefer?