question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Jest builder with jest-preset-angular v7

See original GitHub issue

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`
   }

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
rroncommented, Mar 20, 2019

Hello there, am i able to help with this somehow? Let me know if there is anything i can do.

1reaction
entencommented, Mar 13, 2019

@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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found