jest-preset-angular 12.0.0-next.0 → 12.0.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.
- package/CHANGELOG.md +36 -3
- package/build/compiler/ng-jest-compiler.js +1 -1
- package/build/config/global-setup.js +6 -1
- package/build/config/ng-jest-config.js +12 -1
- package/build/ng-jest-transformer.js +1 -3
- package/build/presets/index.js +28 -0
- package/build/resolvers/ng-jest-resolver.js +5 -1
- package/build/utils/ngcc-jest-processor.js +12 -7
- package/package.json +27 -26
- package/presets/defaults-esm/jest-preset.js +1 -1
- package/presets/index.d.ts +44 -5
- package/presets/index.js +3 -38
- package/setup-jest.js +9 -1
- package/setup-jest.mjs +5 -0
- package/build/config/setup-jest.js +0 -20
- package/build/utils/reflect-metadata.js +0 -19
- package/build/zone-patch/index.js +0 -98
package/CHANGELOG.md
CHANGED
|
@@ -1,15 +1,48 @@
|
|
|
1
|
-
# [12.0.0
|
|
1
|
+
# [12.0.0](https://github.com/thymikee/jest-preset-angular/compare/v12.0.0-next.2...v12.0.0) (2022-05-10)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* add missing `jest` and `typescript` to peer deps ([#1442](https://github.com/thymikee/jest-preset-angular/issues/1442)) ([6a652af](https://github.com/thymikee/jest-preset-angular/commit/6a652afbe893e344c2d4ed2f00528ab80ed52760)), closes [#1441](https://github.com/thymikee/jest-preset-angular/issues/1441)
|
|
7
|
+
* set range supported version for Angular peer deps ([#1449](https://github.com/thymikee/jest-preset-angular/issues/1449)) ([f3e97d7](https://github.com/thymikee/jest-preset-angular/commit/f3e97d7be377a8099fa183b9e6de00a84786e471))
|
|
2
8
|
|
|
3
9
|
|
|
4
10
|
### Features
|
|
5
11
|
|
|
12
|
+
* **config:** add `setup-jest.mjs` for ESM mode ([#1463](https://github.com/thymikee/jest-preset-angular/issues/1463)) ([cc6ce3f](https://github.com/thymikee/jest-preset-angular/commit/cc6ce3fd92d00d8b5d71bec535ce2d625a4cc48c))
|
|
13
|
+
* add an option to configure which file processed by `esbuild` ([#1455](https://github.com/thymikee/jest-preset-angular/issues/1455)) ([b58d089](https://github.com/thymikee/jest-preset-angular/commit/b58d089c255a600707a35cabcfa62fb413f8153b)), closes [#1413](https://github.com/thymikee/jest-preset-angular/issues/1413) [#1437](https://github.com/thymikee/jest-preset-angular/issues/1437)
|
|
14
|
+
* drop support Node 12 ([04195d5](https://github.com/thymikee/jest-preset-angular/commit/04195d5326e370e76e6f76d1e2c9cf277cf975a0))
|
|
15
|
+
* exclude `ng-jest-resolver` from default/esm presets ([#1440](https://github.com/thymikee/jest-preset-angular/issues/1440)) ([56673c4](https://github.com/thymikee/jest-preset-angular/commit/56673c4c086e6a4bf8fada5c196c5a50481b04f0))
|
|
16
|
+
* remove `reflect-metadata` in `setup-jest` ([#1428](https://github.com/thymikee/jest-preset-angular/issues/1428)) ([5a36729](https://github.com/thymikee/jest-preset-angular/commit/5a367293ba490d7d717963b099db7531c347d1f4))
|
|
17
|
+
* remove `zone-patch` and its fallback ([#1427](https://github.com/thymikee/jest-preset-angular/issues/1427)) ([bf9ea44](https://github.com/thymikee/jest-preset-angular/commit/bf9ea44a643311f3bbfbcbc67b493aa000336bee))
|
|
18
|
+
* allow running `ngcc` with specific `tsconfig` path ([#1418](https://github.com/thymikee/jest-preset-angular/issues/1418)) ([5f535b5](https://github.com/thymikee/jest-preset-angular/commit/5f535b59227daea6e64e4886b0ea0bd5fd7c1365)), closes [#1348](https://github.com/thymikee/jest-preset-angular/issues/1348)
|
|
19
|
+
* allow skip `ngcc` via `skipNgcc` option via `globalThis` ([#1417](https://github.com/thymikee/jest-preset-angular/issues/1417)) ([7950b5c](https://github.com/thymikee/jest-preset-angular/commit/7950b5cedfab066a268b16f5c87b5ad3670c6888)), closes [#1396](https://github.com/thymikee/jest-preset-angular/issues/1396)
|
|
6
20
|
* remove `ngcc-jest-processor` entry file ([#1414](https://github.com/thymikee/jest-preset-angular/issues/1414)) ([2c5fd20](https://github.com/thymikee/jest-preset-angular/commit/2c5fd20f0535f5441d8bcb477538defdd9529926))
|
|
7
21
|
|
|
8
22
|
|
|
9
23
|
## BREAKING CHANGES
|
|
10
24
|
|
|
11
|
-
*
|
|
12
|
-
|
|
25
|
+
* Since **Angular 11**, the minimum version of `zone.js` is **0.11.x** and Angular 10 is EOL, so now we can use zone patch directly from `zone.js`.
|
|
26
|
+
If one is not using `zone.js@0.11.x`, please upgrade.
|
|
27
|
+
* Now we are using Angular AST transformers, `reflect-metadata` is not needed anymore.
|
|
28
|
+
* **Jest 28** correctly resolves Angular package format files so the `ng-jest-resolver` is now optional.
|
|
29
|
+
* **Node 12** is no longer support
|
|
30
|
+
* Previously, we always checked file extension `.mjs` and any files from `node_modules` excluding `tslib` to be processed with `esbuild`.
|
|
31
|
+
With the new option `processWithEsbuild`, now we put default all `.mjs` files to be processed by `esbuild`. Files like `lodash-es` default isn't processed by `esbuild`.
|
|
32
|
+
If you wish to use `esbuild` to process such files, please configure in your Jest config like
|
|
33
|
+
```
|
|
34
|
+
// jest.config.js
|
|
35
|
+
module.exports = {
|
|
36
|
+
//...
|
|
37
|
+
globals: {
|
|
38
|
+
ngJest: {
|
|
39
|
+
processWithEsbuild: ['**/node_modules/lodash-es/*.js],
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
* **Angular 10** is no longer support
|
|
45
|
+
* Require **Jest 28**
|
|
13
46
|
* `ngcc-jest-processor` entry file is now removed. One should use `jest-preset-angular/global-setup` instead.
|
|
14
47
|
|
|
15
48
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NgJestCompiler = void 0;
|
|
4
|
-
const ts_compiler_1 = require("ts-jest/dist/compiler/ts-compiler");
|
|
4
|
+
const ts_compiler_1 = require("ts-jest/dist/legacy/compiler/ts-compiler");
|
|
5
5
|
const downlevel_ctor_1 = require("../transformers/downlevel-ctor");
|
|
6
6
|
const replace_resources_1 = require("../transformers/replace-resources");
|
|
7
7
|
class NgJestCompiler extends ts_compiler_1.TsCompiler {
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const tslib_1 = require("tslib");
|
|
3
|
+
const ngcc_jest_processor_1 = require("../utils/ngcc-jest-processor");
|
|
3
4
|
module.exports = () => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
|
|
4
|
-
|
|
5
|
+
const ngJestConfig = globalThis.ngJest;
|
|
6
|
+
const tsconfig = ngJestConfig === null || ngJestConfig === void 0 ? void 0 : ngJestConfig.tsconfig;
|
|
7
|
+
if (!(ngJestConfig === null || ngJestConfig === void 0 ? void 0 : ngJestConfig.skipNgcc)) {
|
|
8
|
+
(0, ngcc_jest_processor_1.runNgccJestProcessor)(tsconfig);
|
|
9
|
+
}
|
|
5
10
|
});
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NgJestConfig = void 0;
|
|
4
|
-
const
|
|
4
|
+
const jest_util_1 = require("jest-util");
|
|
5
|
+
const config_set_1 = require("ts-jest/dist/legacy/config/config-set");
|
|
6
|
+
const defaultProcessWithEsbuildPatterns = ['**/*.mjs'];
|
|
5
7
|
class NgJestConfig extends config_set_1.ConfigSet {
|
|
8
|
+
constructor(jestConfig, parentLogger) {
|
|
9
|
+
var _a, _b, _c;
|
|
10
|
+
super(jestConfig, parentLogger);
|
|
11
|
+
const jestGlobalsConfig = (_b = (_a = jestConfig === null || jestConfig === void 0 ? void 0 : jestConfig.globals) === null || _a === void 0 ? void 0 : _a.ngJest) !== null && _b !== void 0 ? _b : Object.create(null);
|
|
12
|
+
this.processWithEsbuild = (0, jest_util_1.globsToMatcher)([
|
|
13
|
+
...((_c = jestGlobalsConfig.processWithEsbuild) !== null && _c !== void 0 ? _c : []),
|
|
14
|
+
...defaultProcessWithEsbuildPatterns,
|
|
15
|
+
]);
|
|
16
|
+
}
|
|
6
17
|
_resolveTsConfig(compilerOptions, resolvedConfigFile) {
|
|
7
18
|
var _a, _b, _c, _d;
|
|
8
19
|
const result = super._resolveTsConfig(compilerOptions, resolvedConfigFile);
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.NgJestTransformer = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const child_process_1 = require("child_process");
|
|
7
|
-
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
8
7
|
const bs_logger_1 = require("bs-logger");
|
|
9
8
|
const ts_jest_transformer_1 = require("ts-jest/dist/legacy/ts-jest-transformer");
|
|
10
9
|
const ng_jest_compiler_1 = require("./compiler/ng-jest-compiler");
|
|
@@ -44,8 +43,7 @@ class NgJestTransformer extends ts_jest_transformer_1.TsJestTransformer {
|
|
|
44
43
|
}
|
|
45
44
|
process(fileContent, filePath, transformOptions) {
|
|
46
45
|
const configSet = super._configsFor(transformOptions);
|
|
47
|
-
if (
|
|
48
|
-
(/node_modules\/(.*.js$)/.test(filePath.replace(/\\/g, '/')) && !filePath.includes('tslib'))) {
|
|
46
|
+
if (configSet.processWithEsbuild(filePath)) {
|
|
49
47
|
(0, tslib_1.__classPrivateFieldGet)(this, _NgJestTransformer_ngJestLogger, "f").debug({ filePath }, 'process with esbuild');
|
|
50
48
|
const compilerOpts = configSet.parsedTsConfig.options;
|
|
51
49
|
const { code, map } = (0, tslib_1.__classPrivateFieldGet)(this, _NgJestTransformer_esbuildImpl, "f").transformSync(fileContent, {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultEsmPreset = exports.defaultPreset = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const serializers_1 = (0, tslib_1.__importDefault)(require("../serializers"));
|
|
6
|
+
const baseConfig = {
|
|
7
|
+
globals: {
|
|
8
|
+
'ts-jest': {
|
|
9
|
+
tsconfig: '<rootDir>/tsconfig.spec.json',
|
|
10
|
+
stringifyContentPathRegex: '\\.(html|svg)$',
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
testEnvironment: 'jsdom',
|
|
14
|
+
moduleFileExtensions: ['ts', 'html', 'js', 'json', 'mjs'],
|
|
15
|
+
snapshotSerializers: serializers_1.default,
|
|
16
|
+
};
|
|
17
|
+
const defaultPreset = Object.assign(Object.assign({}, baseConfig), { transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'], transform: {
|
|
18
|
+
'^.+\\.(ts|js|mjs|html|svg)$': 'jest-preset-angular',
|
|
19
|
+
} });
|
|
20
|
+
exports.defaultPreset = defaultPreset;
|
|
21
|
+
const defaultEsmPreset = Object.assign(Object.assign({}, baseConfig), { extensionsToTreatAsEsm: ['.ts'], globals: {
|
|
22
|
+
'ts-jest': Object.assign(Object.assign({}, baseConfig.globals['ts-jest']), { useESM: true }),
|
|
23
|
+
}, moduleNameMapper: {
|
|
24
|
+
tslib: 'tslib/tslib.es6.js',
|
|
25
|
+
}, transform: {
|
|
26
|
+
'^.+\\.(ts|js|html|svg)$': 'jest-preset-angular',
|
|
27
|
+
}, transformIgnorePatterns: ['node_modules/(?!tslib)'] });
|
|
28
|
+
exports.defaultEsmPreset = defaultEsmPreset;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const ngJestResolver = (path, options) =>
|
|
2
|
+
const ngJestResolver = (path, options) => {
|
|
3
|
+
return options.defaultResolver(path, Object.assign(Object.assign({}, options), { packageFilter(pkg) {
|
|
4
|
+
return Object.assign(Object.assign({}, pkg), { main: pkg.main || pkg.es2015 || pkg.module });
|
|
5
|
+
} }));
|
|
6
|
+
};
|
|
3
7
|
module.exports = ngJestResolver;
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _a;
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runNgccJestProcessor = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const child_process_1 = require("child_process");
|
|
6
6
|
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
7
|
-
const IGNORE_ARGS = ['--clearCache', '--help', '--init', '--listTests', '--showConfig'];
|
|
8
7
|
const ANGULAR_COMPILER_CLI_PKG_NAME = `@angular${path_1.default.sep}compiler-cli`;
|
|
9
8
|
let ngccPath = '';
|
|
10
9
|
try {
|
|
11
10
|
ngccPath = require.resolve('@angular/compiler-cli/ngcc/main-ngcc.js');
|
|
12
11
|
}
|
|
13
|
-
catch (
|
|
12
|
+
catch (_a) {
|
|
14
13
|
const compilerCliNgccPath = require.resolve('@angular/compiler-cli/ngcc');
|
|
15
14
|
ngccPath = path_1.default.resolve(compilerCliNgccPath.substring(0, compilerCliNgccPath.lastIndexOf(path_1.default.sep)), 'main-ngcc.js');
|
|
16
15
|
}
|
|
@@ -18,10 +17,11 @@ function findNodeModulesDirectory() {
|
|
|
18
17
|
return ngccPath.substring(0, ngccPath.indexOf(ANGULAR_COMPILER_CLI_PKG_NAME));
|
|
19
18
|
}
|
|
20
19
|
const nodeModuleDirPath = findNodeModulesDirectory();
|
|
21
|
-
|
|
20
|
+
const runNgccJestProcessor = (tsconfigPath) => {
|
|
21
|
+
var _a;
|
|
22
22
|
if (nodeModuleDirPath) {
|
|
23
23
|
process.stdout.write('\nngcc-jest-processor: running ngcc\n');
|
|
24
|
-
const
|
|
24
|
+
const ngccBaseArgs = [
|
|
25
25
|
ngccPath,
|
|
26
26
|
'--source',
|
|
27
27
|
nodeModuleDirPath,
|
|
@@ -30,7 +30,11 @@ if (!process.argv.find((arg) => IGNORE_ARGS.includes(arg))) {
|
|
|
30
30
|
'--first-only',
|
|
31
31
|
'false',
|
|
32
32
|
'--async',
|
|
33
|
-
]
|
|
33
|
+
];
|
|
34
|
+
if (tsconfigPath) {
|
|
35
|
+
ngccBaseArgs.push(...['--tsconfig', tsconfigPath]);
|
|
36
|
+
}
|
|
37
|
+
const { status, error } = (0, child_process_1.spawnSync)(process.execPath, ngccBaseArgs, {
|
|
34
38
|
stdio: ['inherit', process.stderr, process.stderr],
|
|
35
39
|
});
|
|
36
40
|
if (status !== 0) {
|
|
@@ -43,4 +47,5 @@ if (!process.argv.find((arg) => IGNORE_ARGS.includes(arg))) {
|
|
|
43
47
|
`Please make sure you are running 'ngcc-jest-processor.js' from root level of your project.` +
|
|
44
48
|
`'ngcc' must be run before running Jest`);
|
|
45
49
|
}
|
|
46
|
-
}
|
|
50
|
+
};
|
|
51
|
+
exports.runNgccJestProcessor = runNgccJestProcessor;
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jest-preset-angular",
|
|
3
|
-
"version": "12.0.0
|
|
3
|
+
"version": "12.0.0",
|
|
4
4
|
"description": "Jest preset configuration for Angular projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
7
|
-
"node": "^
|
|
7
|
+
"node": "^14.15.0 || >=16.10.0"
|
|
8
8
|
},
|
|
9
9
|
"main": "build/index.js",
|
|
10
10
|
"repository": {
|
|
@@ -27,7 +27,6 @@
|
|
|
27
27
|
"testing"
|
|
28
28
|
],
|
|
29
29
|
"scripts": {
|
|
30
|
-
"prepare": "yarn build",
|
|
31
30
|
"build": "node scripts/prebuild.js && tsc -p tsconfig.build.json",
|
|
32
31
|
"_postinstall": "husky install",
|
|
33
32
|
"lint": "eslint --ext .js,.ts .",
|
|
@@ -47,41 +46,43 @@
|
|
|
47
46
|
"dependencies": {
|
|
48
47
|
"bs-logger": "^0.2.6",
|
|
49
48
|
"esbuild-wasm": ">=0.13.8",
|
|
50
|
-
"jest-environment-jsdom": "28.0.0
|
|
51
|
-
"pretty-format": "28.0.0
|
|
52
|
-
"ts-jest": "28.0.0
|
|
49
|
+
"jest-environment-jsdom": "^28.0.0",
|
|
50
|
+
"pretty-format": "^28.0.0",
|
|
51
|
+
"ts-jest": "^28.0.0"
|
|
53
52
|
},
|
|
54
53
|
"optionalDependencies": {
|
|
55
54
|
"esbuild": ">=0.13.8"
|
|
56
55
|
},
|
|
57
56
|
"peerDependencies": {
|
|
58
|
-
"@angular-devkit/build-angular": ">=0.1102.19",
|
|
59
|
-
"@angular/compiler-cli": ">=11.2.14",
|
|
60
|
-
"@angular/core": ">=11.2.14",
|
|
61
|
-
"@angular/platform-browser-dynamic": ">=11.2.14"
|
|
57
|
+
"@angular-devkit/build-angular": ">=0.1102.19 <14.0.0",
|
|
58
|
+
"@angular/compiler-cli": ">=11.2.14 <14.0.0",
|
|
59
|
+
"@angular/core": ">=11.2.14 <14.0.0",
|
|
60
|
+
"@angular/platform-browser-dynamic": ">=11.2.14 <14.0.0",
|
|
61
|
+
"jest": "^28.0.0",
|
|
62
|
+
"typescript": ">=4.3"
|
|
62
63
|
},
|
|
63
64
|
"devDependencies": {
|
|
64
|
-
"@angular-devkit/build-angular": "~13.3.
|
|
65
|
-
"@angular/animations": "^13.3.
|
|
66
|
-
"@angular/common": "^13.3.
|
|
67
|
-
"@angular/compiler": "^13.3.
|
|
68
|
-
"@angular/compiler-cli": "~13.3.
|
|
69
|
-
"@angular/core": "~13.3.
|
|
70
|
-
"@angular/platform-browser": "^13.3.
|
|
71
|
-
"@angular/platform-browser-dynamic": "~13.3.
|
|
65
|
+
"@angular-devkit/build-angular": "~13.3.5",
|
|
66
|
+
"@angular/animations": "^13.3.6",
|
|
67
|
+
"@angular/common": "^13.3.6",
|
|
68
|
+
"@angular/compiler": "^13.3.6",
|
|
69
|
+
"@angular/compiler-cli": "~13.3.6",
|
|
70
|
+
"@angular/core": "~13.3.6",
|
|
71
|
+
"@angular/platform-browser": "^13.3.6",
|
|
72
|
+
"@angular/platform-browser-dynamic": "~13.3.6",
|
|
72
73
|
"@commitlint/cli": "^16.2.3",
|
|
73
74
|
"@commitlint/config-angular": "^16.2.3",
|
|
74
|
-
"@jest/transform": "28.
|
|
75
|
-
"@jest/types": "28.
|
|
75
|
+
"@jest/transform": "^28.1.0",
|
|
76
|
+
"@jest/types": "^28.1.0",
|
|
76
77
|
"@types/jest": "^27.4.1",
|
|
77
|
-
"@types/node": "^16.11.
|
|
78
|
+
"@types/node": "^16.11.33",
|
|
78
79
|
"@types/semver": "^7.3.9",
|
|
79
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
80
|
-
"@typescript-eslint/parser": "^5.
|
|
80
|
+
"@typescript-eslint/eslint-plugin": "^5.23.0",
|
|
81
|
+
"@typescript-eslint/parser": "^5.23.0",
|
|
81
82
|
"chalk": "^4.1.2",
|
|
82
83
|
"conventional-changelog-cli": "^2.2.2",
|
|
83
84
|
"cross-env": "^7.0.3",
|
|
84
|
-
"eslint": "^8.
|
|
85
|
+
"eslint": "^8.15.0",
|
|
85
86
|
"eslint-config-prettier": "^8.5.0",
|
|
86
87
|
"eslint-plugin-import": "^2.26.0",
|
|
87
88
|
"eslint-plugin-jest": "^26.1.4",
|
|
@@ -92,8 +93,8 @@
|
|
|
92
93
|
"fs-extra": "^10.0.1",
|
|
93
94
|
"github-files-fetcher": "^1.6.0",
|
|
94
95
|
"glob": "^8.0.1",
|
|
95
|
-
"husky": "^
|
|
96
|
-
"jest": "28.
|
|
96
|
+
"husky": "^8.0.1",
|
|
97
|
+
"jest": "^28.1.0",
|
|
97
98
|
"jest-snapshot-serializer-raw": "^1.2.0",
|
|
98
99
|
"pinst": "^3.0.0",
|
|
99
100
|
"prettier": "^2.6.2",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require('
|
|
1
|
+
module.exports = require('../index').defaultsESM;
|
package/presets/index.d.ts
CHANGED
|
@@ -1,7 +1,46 @@
|
|
|
1
|
-
import type { InitialOptionsTsJest } from 'ts-jest/dist/types';
|
|
2
|
-
|
|
3
1
|
declare const _default: {
|
|
4
|
-
defaults:
|
|
5
|
-
|
|
2
|
+
defaults: {
|
|
3
|
+
transformIgnorePatterns: string[];
|
|
4
|
+
transform: {
|
|
5
|
+
'^.+\\.(ts|js|mjs|html|svg)$': string;
|
|
6
|
+
};
|
|
7
|
+
globals: import('ts-jest').GlobalConfigTsJest;
|
|
8
|
+
testEnvironment: string;
|
|
9
|
+
moduleFileExtensions: string[];
|
|
10
|
+
snapshotSerializers: string[];
|
|
11
|
+
};
|
|
12
|
+
defaultsESM: {
|
|
13
|
+
extensionsToTreatAsEsm: string[];
|
|
14
|
+
globals: {
|
|
15
|
+
'ts-jest': {
|
|
16
|
+
useESM: boolean;
|
|
17
|
+
tsconfig?: string | boolean | import('ts-jest').RawCompilerOptions | undefined;
|
|
18
|
+
isolatedModules?: boolean | undefined;
|
|
19
|
+
compiler?: string | undefined;
|
|
20
|
+
astTransformers?: import('ts-jest').ConfigCustomTransformer | undefined;
|
|
21
|
+
diagnostics?:
|
|
22
|
+
| boolean
|
|
23
|
+
| {
|
|
24
|
+
pretty?: boolean | undefined;
|
|
25
|
+
ignoreCodes?: string | number | Array<string | number> | undefined;
|
|
26
|
+
exclude?: string[] | undefined;
|
|
27
|
+
warnOnly?: boolean | undefined;
|
|
28
|
+
}
|
|
29
|
+
| undefined;
|
|
30
|
+
babelConfig?: string | boolean | import('@babel/core').TransformOptions | undefined;
|
|
31
|
+
stringifyContentPathRegex?: string | RegExp | undefined;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
moduleNameMapper: {
|
|
35
|
+
tslib: string;
|
|
36
|
+
};
|
|
37
|
+
transform: {
|
|
38
|
+
'^.+\\.(ts|js|html|svg)$': string;
|
|
39
|
+
};
|
|
40
|
+
transformIgnorePatterns: string[];
|
|
41
|
+
testEnvironment: string;
|
|
42
|
+
moduleFileExtensions: string[];
|
|
43
|
+
snapshotSerializers: string[];
|
|
44
|
+
};
|
|
6
45
|
};
|
|
7
|
-
export
|
|
46
|
+
export default _default;
|
package/presets/index.js
CHANGED
|
@@ -1,41 +1,6 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
const basePreset = {
|
|
4
|
-
globals: {
|
|
5
|
-
'ts-jest': {
|
|
6
|
-
tsconfig: '<rootDir>/tsconfig.spec.json',
|
|
7
|
-
stringifyContentPathRegex: '\\.(html|svg)$',
|
|
8
|
-
},
|
|
9
|
-
},
|
|
10
|
-
resolver: 'jest-preset-angular/build/resolvers/ng-jest-resolver.js',
|
|
11
|
-
testEnvironment: 'jsdom',
|
|
12
|
-
moduleFileExtensions: ['ts', 'html', 'js', 'json', 'mjs'],
|
|
13
|
-
snapshotSerializers,
|
|
14
|
-
};
|
|
1
|
+
const ngJestPresets = require('../build/presets');
|
|
15
2
|
|
|
16
3
|
module.exports = {
|
|
17
|
-
defaults:
|
|
18
|
-
|
|
19
|
-
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
|
|
20
|
-
transform: {
|
|
21
|
-
'^.+\\.(ts|js|mjs|html|svg)$': 'jest-preset-angular',
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
defaultsESM: {
|
|
25
|
-
...basePreset,
|
|
26
|
-
extensionsToTreatAsEsm: ['.ts'],
|
|
27
|
-
globals: {
|
|
28
|
-
'ts-jest': {
|
|
29
|
-
...basePreset.globals['ts-jest'],
|
|
30
|
-
useESM: true,
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
moduleNameMapper: {
|
|
34
|
-
tslib: 'tslib/tslib.es6.js',
|
|
35
|
-
},
|
|
36
|
-
transform: {
|
|
37
|
-
'^.+\\.(ts|js|html|svg)$': 'jest-preset-angular',
|
|
38
|
-
},
|
|
39
|
-
transformIgnorePatterns: ['node_modules/(?!tslib)'],
|
|
40
|
-
},
|
|
4
|
+
defaults: ngJestPresets.defaultPreset,
|
|
5
|
+
defaultsESM: ngJestPresets.defaultEsmPreset,
|
|
41
6
|
};
|
package/setup-jest.js
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
require('zone.js/bundles/zone-testing-bundle.umd');
|
|
2
|
+
|
|
3
|
+
const { getTestBed } = require('@angular/core/testing');
|
|
4
|
+
const {
|
|
5
|
+
BrowserDynamicTestingModule,
|
|
6
|
+
platformBrowserDynamicTesting,
|
|
7
|
+
} = require('@angular/platform-browser-dynamic/testing');
|
|
8
|
+
|
|
9
|
+
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
|
package/setup-jest.mjs
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import 'zone.js/fesm2015/zone-testing-bundle.min.js';
|
|
2
|
+
import { getTestBed } from '@angular/core/testing';
|
|
3
|
+
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
|
|
4
|
+
|
|
5
|
+
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
require('../utils/reflect-metadata');
|
|
3
|
-
try {
|
|
4
|
-
!process.execArgv.includes('--experimental-vm-modules')
|
|
5
|
-
? require('zone.js/bundles/zone-testing-bundle.umd.js')
|
|
6
|
-
: require('zone.js/fesm2015/zone-testing-bundle.min.js');
|
|
7
|
-
}
|
|
8
|
-
catch (err) {
|
|
9
|
-
require('zone.js/dist/zone');
|
|
10
|
-
require('zone.js/dist/proxy');
|
|
11
|
-
require('zone.js/dist/sync-test');
|
|
12
|
-
require('zone.js/dist/async-test');
|
|
13
|
-
require('zone.js/dist/fake-async-test');
|
|
14
|
-
require('../zone-patch');
|
|
15
|
-
}
|
|
16
|
-
const getTestBed = require('@angular/core/testing').getTestBed;
|
|
17
|
-
const BrowserDynamicTestingModule = require('@angular/platform-browser-dynamic/testing').BrowserDynamicTestingModule;
|
|
18
|
-
const platformBrowserDynamicTesting = require('@angular/platform-browser-dynamic/testing')
|
|
19
|
-
.platformBrowserDynamicTesting;
|
|
20
|
-
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const METADATA_KEY_PARAMTYPES = 'design:paramtypes';
|
|
3
|
-
global.globalThis = global.globalThis || undefined;
|
|
4
|
-
const globalRef = globalThis || global;
|
|
5
|
-
const reflect = globalRef['Reflect'];
|
|
6
|
-
const metadataValueStore = new WeakMap();
|
|
7
|
-
if (!reflect.metadata && !reflect.getOwnMetadata) {
|
|
8
|
-
reflect.metadata =
|
|
9
|
-
(metadataKey, metadataValue) => (target, key) => {
|
|
10
|
-
if (metadataKey === METADATA_KEY_PARAMTYPES && key === undefined) {
|
|
11
|
-
metadataValueStore.set(target, metadataValue);
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
reflect.getOwnMetadata = (metadata, target, key) => {
|
|
15
|
-
if (metadata === METADATA_KEY_PARAMTYPES && key === undefined && metadataValueStore.has(target)) {
|
|
16
|
-
return metadataValueStore.get(target);
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
if (Zone === undefined) {
|
|
3
|
-
throw new Error('Missing: Zone (zone.js)');
|
|
4
|
-
}
|
|
5
|
-
if (jest === undefined) {
|
|
6
|
-
throw new Error('Missing: jest.\n' +
|
|
7
|
-
'This patch must be included in a script called with ' +
|
|
8
|
-
'`setupTestFrameworkScriptFile` in Jest config.');
|
|
9
|
-
}
|
|
10
|
-
if (jest['__zone_patch__'] === true) {
|
|
11
|
-
throw new Error("'jest' has already been patched with 'Zone'.");
|
|
12
|
-
}
|
|
13
|
-
jest['__zone_patch__'] = true;
|
|
14
|
-
const SyncTestZoneSpec = Zone['SyncTestZoneSpec'];
|
|
15
|
-
const ProxyZoneSpec = Zone['ProxyZoneSpec'];
|
|
16
|
-
if (SyncTestZoneSpec === undefined) {
|
|
17
|
-
throw new Error('Missing: SyncTestZoneSpec (zone.js/dist/sync-test)');
|
|
18
|
-
}
|
|
19
|
-
if (ProxyZoneSpec === undefined) {
|
|
20
|
-
throw new Error('Missing: ProxyZoneSpec (zone.js/dist/proxy.js)');
|
|
21
|
-
}
|
|
22
|
-
const env = global;
|
|
23
|
-
const ambientZone = Zone.current;
|
|
24
|
-
const syncZone = ambientZone.fork(new SyncTestZoneSpec('jest.describe'));
|
|
25
|
-
function wrapDescribeInZone(describeBody) {
|
|
26
|
-
return function (...args) {
|
|
27
|
-
return syncZone.run(describeBody, null, args);
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
const testProxyZone = ambientZone.fork(new ProxyZoneSpec());
|
|
31
|
-
function wrapTestInZone(testBody) {
|
|
32
|
-
if (testBody === undefined) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const wrappedFunc = function () {
|
|
36
|
-
return testProxyZone.run(testBody, null, arguments);
|
|
37
|
-
};
|
|
38
|
-
try {
|
|
39
|
-
Object.defineProperty(wrappedFunc, 'length', {
|
|
40
|
-
configurable: true,
|
|
41
|
-
writable: true,
|
|
42
|
-
enumerable: false,
|
|
43
|
-
});
|
|
44
|
-
wrappedFunc.length = testBody.length;
|
|
45
|
-
}
|
|
46
|
-
catch (e) {
|
|
47
|
-
return testBody.length === 0
|
|
48
|
-
? () => testProxyZone.run(testBody, null)
|
|
49
|
-
: (done) => testProxyZone.run(testBody, null, [done]);
|
|
50
|
-
}
|
|
51
|
-
return wrappedFunc;
|
|
52
|
-
}
|
|
53
|
-
const bindDescribe = (originalJestFn) => function (...eachArgs) {
|
|
54
|
-
return function (...args) {
|
|
55
|
-
args[1] = wrapDescribeInZone(args[1]);
|
|
56
|
-
return originalJestFn.apply(this, eachArgs).apply(this, args);
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
const bindTest = (originalJestFn) => function (...eachArgs) {
|
|
60
|
-
return function (...args) {
|
|
61
|
-
args[1] = wrapTestInZone(args[1]);
|
|
62
|
-
return originalJestFn.apply(this, eachArgs).apply(this, args);
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
['xdescribe', 'fdescribe', 'describe'].forEach((methodName) => {
|
|
66
|
-
const originaljestFn = env[methodName];
|
|
67
|
-
env[methodName] = function (...args) {
|
|
68
|
-
args[1] = wrapDescribeInZone(args[1]);
|
|
69
|
-
return originaljestFn.apply(this, args);
|
|
70
|
-
};
|
|
71
|
-
env[methodName].each = bindDescribe(originaljestFn.each);
|
|
72
|
-
if (methodName === 'describe') {
|
|
73
|
-
env[methodName].only = env['fdescribe'];
|
|
74
|
-
env[methodName].skip = env['xdescribe'];
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
['xit', 'fit', 'xtest', 'test', 'it'].forEach((methodName) => {
|
|
78
|
-
const originaljestFn = env[methodName];
|
|
79
|
-
env[methodName] = function (...args) {
|
|
80
|
-
args[1] = wrapTestInZone(args[1]);
|
|
81
|
-
return originaljestFn.apply(this, args);
|
|
82
|
-
};
|
|
83
|
-
env[methodName].each = bindTest(originaljestFn.each);
|
|
84
|
-
if (methodName === 'test' || methodName === 'it') {
|
|
85
|
-
env[methodName].only = env['fit'];
|
|
86
|
-
env[methodName].skip = env['xit'];
|
|
87
|
-
env[methodName].todo = function (...args) {
|
|
88
|
-
return originaljestFn.todo.apply(this, args);
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
['beforeEach', 'afterEach', 'beforeAll', 'afterAll'].forEach((methodName) => {
|
|
93
|
-
const originaljestFn = env[methodName];
|
|
94
|
-
env[methodName] = function (...args) {
|
|
95
|
-
args[0] = wrapTestInZone(args[0]);
|
|
96
|
-
return originaljestFn.apply(this, args);
|
|
97
|
-
};
|
|
98
|
-
});
|