0

I have done migration of angular from 13 to 16. Now I have the following config jest.prest.js

const nxPreset = require("@nx/jest/preset");
const esModules = ["@angular", "tslib", "rxjs"];

module.exports = {
  ...nxPreset,
  globals: {
    "ts-jest": {
      tsconfig: "<rootDir>/tsconfig.spec.json",
      stringifyContentPathRegex: "\\.(html|svg)$",
    },
  },
  transformIgnorePatterns: [
    `<rootDir>/node_modules/(?!.*\\.mjs$|${esModules.join("|")})`,
  ],
  transform: {
    "^.+\\.(ts|mjs|js|html)$": "jest-preset-angular",
  },
  testEnvironment: "jsdom",
  resolver: "@nx/jest/plugins/resolver",
  moduleFileExtensions: ["ts", "html", "js", "json", "mjs"],
  snapshotSerializers: [
    "jest-preset-angular/build/serializers/no-ng-attributes",
    "jest-preset-angular/build/serializers/ng-snapshot",
    "jest-preset-angular/build/serializers/html-comment",
  ],
};

then when I run npm run test I recived

ts-jest[ts-jest-transformer] (WARN) Define ts-jest config under globals is deprecated. Please do
transform: {
<transform_regex>: ['ts-jest', { /* ts-jest config goes here in Jest */ }],
},

so I change the file config to

const nxPreset = require("@nx/jest/preset");
const esModules = ["@angular", "tslib", "rxjs"];

module.exports = {
  ...nxPreset,
  transform: {
    "^.+\\.(ts|mjs|js|html)$": [
      "ts-jest",
      {
        tsconfig: "<rootDir>/tsconfig.spec.json",
        stringifyContentPathRegex: "\\.(html|svg)$",
      },
    ],
  },
  transformIgnorePatterns: [
    `<rootDir>/node_modules/(?!.*\\.mjs$|${esModules.join("|")})`,
  ],
  testEnvironment: "jsdom",
  resolver: "@nx/jest/plugins/resolver",
  moduleFileExtensions: ["ts", "html", "js", "json", "mjs"],
  snapshotSerializers: [
    "jest-preset-angular/build/serializers/no-ng-attributes",
    "jest-preset-angular/build/serializers/ng-snapshot",
    "jest-preset-angular/build/serializers/html-comment",
  ],
};

after that when I run test I received a lot of errors like unexpected token and etc..

Do you have any idea how to adjust this kind of file?

Walter White
  • 976
  • 4
  • 12
  • 29

0 Answers0