jest-preset-angular 14.2.4 → 14.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +1 -1
  3. package/build/compiler/ng-jest-compiler.d.ts +11 -0
  4. package/build/config/global-setup.d.ts +1 -0
  5. package/build/config/ng-jest-config.d.ts +9 -0
  6. package/build/constants.d.ts +7 -0
  7. package/build/index.d.ts +6 -0
  8. package/build/ng-jest-transformer.d.ts +9 -0
  9. package/build/presets/index.d.ts +39 -0
  10. package/build/resolvers/ng-jest-resolver.d.ts +3 -0
  11. package/build/serializers/html-comment.d.ts +5 -0
  12. package/build/serializers/index.d.ts +2 -0
  13. package/build/serializers/ng-snapshot.d.ts +11 -0
  14. package/build/serializers/no-ng-attributes.d.ts +5 -0
  15. package/build/transformers/esm_interop_inject.d.cts +1 -0
  16. package/build/transformers/jit_transform.js +41 -41
  17. package/build/transformers/replace-resources.d.ts +2 -0
  18. package/build/utils/ngcc-jest-processor.d.ts +1 -0
  19. package/package.json +26 -25
  20. package/setup-env/utils.mjs +19 -0
  21. package/setup-env/zone/index.d.mts +3 -0
  22. package/setup-env/zone/index.d.ts +6 -0
  23. package/setup-env/zone/index.js +43 -0
  24. package/setup-env/zone/index.mjs +18 -0
  25. package/setup-env/zoneless/index.d.mts +3 -0
  26. package/setup-env/zoneless/index.d.ts +6 -0
  27. package/setup-env/zoneless/index.js +11 -0
  28. package/setup-env/zoneless/index.mjs +39 -0
  29. package/setup-jest.js +10 -0
  30. package/setup-jest.mjs +12 -1
  31. package/jest-cjs.config.ts +0 -8
  32. package/jest-esm.config.ts +0 -8
  33. package/jest-src.config.ts +0 -18
  34. package/jest-transpile-cjs.config.ts +0 -8
  35. package/jest-transpile-esm.config.ts +0 -8
  36. package/tsconfig-base.spec.json +0 -7
@@ -0,0 +1,2 @@
1
+ import ts from 'typescript';
2
+ export declare function replaceResources(program: ts.Program): ts.TransformerFactory<ts.SourceFile>;
@@ -0,0 +1 @@
1
+ export declare const runNgccJestProcessor: (tsconfigPath: string | undefined) => void;
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "jest-preset-angular",
3
- "version": "14.2.4",
3
+ "version": "14.3.0",
4
4
  "description": "Jest preset configuration for Angular projects",
5
5
  "license": "MIT",
6
6
  "engines": {
7
7
  "node": "^14.15.0 || >=16.10.0"
8
8
  },
9
9
  "main": "build/index.js",
10
+ "typings": "build/index.d.ts",
10
11
  "repository": {
11
12
  "type": "git",
12
13
  "url": "git+https://github.com/thymikee/jest-preset-angular.git"
@@ -64,30 +65,30 @@
64
65
  "typescript": ">=4.8"
65
66
  },
66
67
  "devDependencies": {
67
- "@angular-devkit/build-angular": "^18.2.4",
68
- "@angular-eslint/eslint-plugin": "^18.3.1",
69
- "@angular-eslint/eslint-plugin-template": "^18.3.1",
70
- "@angular-eslint/template-parser": "^18.3.1",
71
- "@angular/animations": "^18.2.4",
72
- "@angular/cdk": "^18.2.3",
73
- "@angular/common": "^18.2.4",
74
- "@angular/compiler": "^18.2.4",
75
- "@angular/compiler-cli": "^18.2.4",
76
- "@angular/core": "^18.2.4",
77
- "@angular/forms": "^18.2.4",
78
- "@angular/material": "^18.2.3",
79
- "@angular/platform-browser": "^18.2.4",
80
- "@angular/platform-browser-dynamic": "^18.2.4",
81
- "@babel/core": "^7.25.2",
82
- "@babel/preset-env": "^7.25.4",
68
+ "@angular-devkit/build-angular": "^18.2.12",
69
+ "@angular-eslint/eslint-plugin": "^18.4.0",
70
+ "@angular-eslint/eslint-plugin-template": "^18.4.0",
71
+ "@angular-eslint/template-parser": "^18.4.0",
72
+ "@angular/animations": "^18.2.12",
73
+ "@angular/cdk": "^18.2.13",
74
+ "@angular/common": "^18.2.12",
75
+ "@angular/compiler": "^18.2.12",
76
+ "@angular/compiler-cli": "^18.2.12",
77
+ "@angular/core": "^18.2.12",
78
+ "@angular/forms": "^18.2.12",
79
+ "@angular/material": "^18.2.13",
80
+ "@angular/platform-browser": "^18.2.12",
81
+ "@angular/platform-browser-dynamic": "^18.2.12",
82
+ "@babel/core": "^7.26.0",
83
+ "@babel/preset-env": "^7.26.0",
83
84
  "@commitlint/cli": "^19.5.0",
84
85
  "@commitlint/config-angular": "^19.5.0",
85
86
  "@jest/transform": "^29.7.0",
86
87
  "@jest/types": "^29.6.3",
87
88
  "@types/babel__core": "^7.20.5",
88
89
  "@types/babel__preset-env": "^7.9.7",
89
- "@types/jest": "^29.5.12",
90
- "@types/node": "^20.16.5",
90
+ "@types/jest": "^29.5.14",
91
+ "@types/node": "^22.9.0",
91
92
  "@types/semver": "^7.5.8",
92
93
  "@typescript-eslint/eslint-plugin": "^7.18.0",
93
94
  "@typescript-eslint/parser": "^7.18.0",
@@ -95,11 +96,11 @@
95
96
  "chalk": "^4.1.2",
96
97
  "conventional-changelog-cli": "^5.0.0",
97
98
  "cross-env": "^7.0.3",
98
- "eslint": "^8.57.0",
99
+ "eslint": "^8.57.1",
99
100
  "eslint-config-prettier": "^9.1.0",
100
- "eslint-plugin-import": "^2.30.0",
101
- "eslint-plugin-jest": "^28.8.3",
102
- "eslint-plugin-jsdoc": "^50.2.2",
101
+ "eslint-plugin-import": "^2.31.0",
102
+ "eslint-plugin-jest": "^28.9.0",
103
+ "eslint-plugin-jsdoc": "^50.5.0",
103
104
  "eslint-plugin-prettier": "^4.2.1",
104
105
  "execa": "5.1.1",
105
106
  "fs-extra": "^11.2.0",
@@ -112,9 +113,9 @@
112
113
  "rimraf": "^5.0.10",
113
114
  "rxjs": "^7.8.1",
114
115
  "ts-node": "^10.9.2",
115
- "tslib": "^2.7.0",
116
+ "tslib": "^2.8.1",
116
117
  "typescript": "~5.5.4",
117
118
  "zone.js": "~0.15.0"
118
119
  },
119
- "packageManager": "yarn@4.4.1"
120
+ "packageManager": "yarn@4.5.1"
120
121
  }
@@ -0,0 +1,19 @@
1
+ import { TextDecoder, TextEncoder } from 'util';
2
+
3
+ export const polyfillEncoder = () => {
4
+ if (typeof globalThis.TextEncoder === 'undefined') {
5
+ globalThis.TextEncoder = TextEncoder;
6
+ globalThis.TextDecoder = TextDecoder;
7
+ }
8
+ };
9
+
10
+ export const resolveTestEnvOptions = (options) => {
11
+ const globalTestEnvOptions = globalThis.ngJest?.testEnvironmentOptions;
12
+ if (globalTestEnvOptions) {
13
+ console.warn(
14
+ 'Setting testEnvironmentOptions via globalThis.ngJest is deprecated. Please provide testEnvironmentOptions via function argument',
15
+ );
16
+ }
17
+
18
+ return globalTestEnvOptions ?? options;
19
+ };
@@ -0,0 +1,3 @@
1
+ import type { TestEnvironmentOptions } from '@angular/core/testing';
2
+
3
+ export declare const setupZoneTestEnv: (options?: TestEnvironmentOptions) => void;
@@ -0,0 +1,6 @@
1
+ import type { TestEnvironmentOptions } from '@angular/core/testing';
2
+
3
+ declare const _default: {
4
+ setupZoneTestEnv: (options?: TestEnvironmentOptions) => void;
5
+ };
6
+ export = _default;
@@ -0,0 +1,43 @@
1
+ require('zone.js');
2
+ require('zone.js/testing');
3
+
4
+ const { TextEncoder, TextDecoder } = require('util');
5
+
6
+ const { getTestBed } = require('@angular/core/testing');
7
+ const {
8
+ BrowserDynamicTestingModule,
9
+ platformBrowserDynamicTesting,
10
+ } = require('@angular/platform-browser-dynamic/testing');
11
+
12
+ const polyfillEncoder = () => {
13
+ if (typeof globalThis.TextEncoder === 'undefined') {
14
+ globalThis.TextEncoder = TextEncoder;
15
+ globalThis.TextDecoder = TextDecoder;
16
+ }
17
+ };
18
+
19
+ const resolveTestEnvOptions = (options) => {
20
+ const globalTestEnvOptions = globalThis.ngJest?.testEnvironmentOptions;
21
+ if (globalTestEnvOptions) {
22
+ console.warn(
23
+ 'Setting testEnvironmentOptions via globalThis.ngJest is deprecated. Please provide testEnvironmentOptions via function argument',
24
+ );
25
+ }
26
+
27
+ return globalTestEnvOptions ?? options;
28
+ };
29
+
30
+ const setupZoneTestEnv = (options) => {
31
+ polyfillEncoder();
32
+ const testEnvironmentOptions = resolveTestEnvOptions(options);
33
+
34
+ getTestBed().initTestEnvironment(
35
+ BrowserDynamicTestingModule,
36
+ platformBrowserDynamicTesting(),
37
+ testEnvironmentOptions,
38
+ );
39
+ };
40
+
41
+ module.exports = {
42
+ setupZoneTestEnv,
43
+ };
@@ -0,0 +1,18 @@
1
+ import 'zone.js';
2
+ import 'zone.js/testing';
3
+
4
+ import { getTestBed } from '@angular/core/testing';
5
+ import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
6
+
7
+ import { polyfillEncoder, resolveTestEnvOptions } from '../utils.mjs';
8
+
9
+ export const setupZoneTestEnv = (options) => {
10
+ polyfillEncoder();
11
+ const testEnvironmentOptions = resolveTestEnvOptions(options);
12
+
13
+ getTestBed().initTestEnvironment(
14
+ BrowserDynamicTestingModule,
15
+ platformBrowserDynamicTesting(),
16
+ testEnvironmentOptions,
17
+ );
18
+ };
@@ -0,0 +1,3 @@
1
+ import type { TestEnvironmentOptions } from '@angular/core/testing';
2
+
3
+ export declare const setupZonelessTestEnv: (options?: TestEnvironmentOptions) => void;
@@ -0,0 +1,6 @@
1
+ import type { TestEnvironmentOptions } from '@angular/core/testing';
2
+
3
+ declare const _default: {
4
+ setupZonelessTestEnv: (options?: TestEnvironmentOptions) => void;
5
+ };
6
+ export = _default;
@@ -0,0 +1,11 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
+ const setupZonelessTestEnv = (_options) => {
3
+ throw Error(
4
+ 'Zoneless testing environment only works when running Jest in ESM mode with Jest 29. ' +
5
+ 'Jest 30+ will support to work with CommonJS mode.',
6
+ );
7
+ };
8
+
9
+ module.exports = {
10
+ setupZonelessTestEnv,
11
+ };
@@ -0,0 +1,39 @@
1
+ import { ErrorHandler, NgModule, provideExperimentalZonelessChangeDetection } from '@angular/core';
2
+ import { getTestBed } from '@angular/core/testing';
3
+ import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
4
+
5
+ import { polyfillEncoder, resolveTestEnvOptions } from '../utils.mjs';
6
+
7
+ export const setupZonelessTestEnv = (options) => {
8
+ if (typeof provideExperimentalZonelessChangeDetection !== 'undefined') {
9
+ polyfillEncoder();
10
+ const testEnvironmentOptions = resolveTestEnvOptions(options);
11
+ @NgModule({
12
+ providers: [
13
+ provideExperimentalZonelessChangeDetection(),
14
+ {
15
+ provide: ErrorHandler,
16
+ useValue: {
17
+ handleError: (e) => {
18
+ throw e;
19
+ },
20
+ },
21
+ },
22
+ ],
23
+ })
24
+ export class TestModule {}
25
+
26
+ getTestBed().initTestEnvironment(
27
+ [BrowserDynamicTestingModule, TestModule],
28
+ platformBrowserDynamicTesting(),
29
+ testEnvironmentOptions,
30
+ );
31
+
32
+ return;
33
+ }
34
+
35
+ throw Error(
36
+ 'Cannot find provideExperimentalZonelessChangeDetection() to setup zoneless testing environment. ' +
37
+ 'Please use setupZoneTestEnv() from jest-preset-angular/setup-env/setup-zone-env.mjs instead.',
38
+ );
39
+ };
package/setup-jest.js CHANGED
@@ -1,3 +1,13 @@
1
+ console.warn(`
2
+ Importing "setup-jest.js" directly is deprecated. The file "setup-jest.js" will be removed in the future.
3
+ Please use "setupZoneTestEnv" function instead. Example:
4
+
5
+ // setup-jest.ts
6
+ import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/zone';
7
+
8
+ setupZoneTestEnv();
9
+ `);
10
+
1
11
  require('zone.js');
2
12
  require('zone.js/testing');
3
13
  const { TextEncoder, TextDecoder } = require('util');
package/setup-jest.mjs CHANGED
@@ -1,8 +1,19 @@
1
+ console.warn(`
2
+ Importing "setup-jest.mjs" directly is deprecated. The file "setup-jest.mjs" will be removed in the future.
3
+ Please use "setupZoneTestEnv" function instead. Example:
4
+
5
+ // setup-jest.ts
6
+ import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/zone/index.mjs';
7
+
8
+ setupZoneTestEnv();
9
+ `);
10
+
1
11
  import 'zone.js';
2
12
  import 'zone.js/testing';
13
+ import { TextEncoder, TextDecoder } from 'util';
14
+
3
15
  import { getTestBed } from '@angular/core/testing';
4
16
  import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
5
- import { TextEncoder, TextDecoder } from 'util';
6
17
 
7
18
  if (typeof globalThis.TextEncoder === 'undefined') {
8
19
  globalThis.TextEncoder = TextEncoder;
@@ -1,8 +0,0 @@
1
- import type { Config } from '@jest/types';
2
-
3
- const config: Config.InitialOptions = {
4
- globalSetup: './setup-e2e-test.ts',
5
- projects: ['e2e/**/jest-cjs.config.ts'],
6
- };
7
-
8
- export default config;
@@ -1,8 +0,0 @@
1
- import type { Config } from '@jest/types';
2
-
3
- const config: Config.InitialOptions = {
4
- globalSetup: './setup-e2e-test.ts',
5
- projects: ['e2e/**/jest-esm.config.ts'],
6
- };
7
-
8
- export default config;
@@ -1,18 +0,0 @@
1
- import type { JestConfigWithTsJest } from 'ts-jest';
2
-
3
- const config: JestConfigWithTsJest = {
4
- modulePathIgnorePatterns: ['examples/.*', 'website/.*'],
5
- testMatch: ['<rootDir>/src/**/*.spec.ts'],
6
- testEnvironment: 'jsdom',
7
- transform: {
8
- '^.+\\.(ts|js|mjs|html)$': [
9
- '<rootDir>/build/index.js',
10
- {
11
- tsconfig: 'tsconfig-base.spec.json',
12
- isolatedModules: true,
13
- },
14
- ],
15
- },
16
- };
17
-
18
- export default config;
@@ -1,8 +0,0 @@
1
- import type { Config } from '@jest/types';
2
-
3
- const config: Config.InitialOptions = {
4
- globalSetup: './setup-e2e-test.ts',
5
- projects: ['jest-src.config.ts', 'e2e/**/jest-transpile-cjs.config.ts'],
6
- };
7
-
8
- export default config;
@@ -1,8 +0,0 @@
1
- import type { Config } from '@jest/types';
2
-
3
- const config: Config.InitialOptions = {
4
- globalSetup: './setup-e2e-test.ts',
5
- projects: ['e2e/**/jest-transpile-esm.config.ts'],
6
- };
7
-
8
- export default config;
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "module": "CommonJS",
5
- "types": ["jest"]
6
- }
7
- }