Is 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`
}
Hey, thanks for reporting! It is actually a known issue. You're not supposed to run it with a custom jest-preset-angular version, the builder is tied to a specific version.
You're right regarding supporting it in the builder, as a matter of fact there is an ongoing work here.
The problem is that it would be a breaking change, therefore it's problematic to release it with a minor version update (like 7.4.0). It makes much more sense to release it with version 8.0.0.
On the other hand the plan is to release version 8.0.0 along with Angular 8.0.0 which will have breaking changes anyways.
Nevertheless I see that it becomes more and more common problem, so I might consider releasing it with a minor version.
Would you like to make a PR with changes you propose or cooperate with @wesleygrimes on the existing one?
You're not supposed to run it with a custom jest-preset-angular version, the builder is tied to a specific version.
...
The problem is that it would be a breaking change, therefore it's problematic to release it with a minor version update.
How about move jest-preset-angular as peer dependency and update DefaultConfigResolver to generate a jest config according to jest version 23 or 24? That can be an alternative while waiting for angular v8.
Would you like to make a PR with changes you propose or cooperate with @wesleygrimes on the existing one?
I think it can be easier to open a new PR. What do you prefer?
How about move jest-preset-angular as peer dependency and update DefaultConfigResolver to generate a jest config according to jest version 23 or 24? That can be an alternative while waiting for angular v8.
It is a possibility. The only concern is that it will complicate things. The purpose of Jest builder is to hide the complexity behind the Jest setup and jest-preset-angular is one of those.
Moreover, doing it as a temporary workaround until Angular 8 is released is going to confuse people.
Today they don't have to install jest preset, tomorrow they'll have to and the day after tomorrow they won't have to again.
Thoughts?
I think it can be easier to open a new PR. What do you prefer?
It's definitely easier, I just don't want you guys to do a duplicate work.
@enten are you planning on opening a new PR? I was going to take a look at this today, but I don't want to duplicate efforts.
@meltedspark
You're right and finally I'm agree with you.
@wesleygrimes
are you planning on opening a new PR
Initially yes because @meltedspark suggested it. But If you prefer I can collaborate to the existing PR. What do you prefer?
@enten I'm good with keeping the existing PR. I actually went ahead and updated the PR to include the changes you suggest here. Can you take a look? (Not trying to steal your credit either, so I will update the PR to mention you as well if you'd like)
@wesleygrimes Yes, I will take a look (and don't worry about credit sir).
Hello there, am i able to help with this somehow? Let me know if there is anything i can do.
Hello there, am i able to help with this somehow? Let me know if there is anything i can do.
I'm going to try and find time today to update PR #246 based on @meltedspark feedback. If I run into issues I will let you know. Thanks for offering!
Available in 7.4.0