jest-preset-angular 14.2.3 → 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.
- package/CHANGELOG.md +48 -0
- package/README.md +1 -1
- package/build/compiler/ng-jest-compiler.d.ts +11 -0
- package/build/compiler/ng-jest-compiler.js +71 -0
- package/build/config/global-setup.d.ts +1 -0
- package/build/config/global-setup.js +21 -0
- package/build/config/ng-jest-config.d.ts +9 -0
- package/build/config/ng-jest-config.js +29 -0
- package/build/constants.d.ts +7 -0
- package/build/constants.js +10 -0
- package/build/index.d.ts +6 -0
- package/build/index.js +6 -0
- package/build/ng-jest-transformer.d.ts +9 -0
- package/build/ng-jest-transformer.js +66 -0
- package/build/presets/index.d.ts +39 -0
- package/build/presets/index.js +30 -0
- package/build/resolvers/ng-jest-resolver.d.ts +3 -0
- package/build/resolvers/ng-jest-resolver.js +7 -0
- package/build/serializers/html-comment.d.ts +5 -0
- package/build/serializers/html-comment.js +8 -0
- package/build/serializers/index.d.ts +2 -0
- package/build/serializers/index.js +6 -0
- package/build/serializers/ng-snapshot.d.ts +11 -0
- package/build/serializers/ng-snapshot.js +48 -0
- package/build/serializers/no-ng-attributes.d.ts +5 -0
- package/build/serializers/no-ng-attributes.js +57 -0
- package/build/transformers/esm_interop_inject.cjs +4 -0
- package/build/transformers/esm_interop_inject.d.cts +1 -0
- package/build/transformers/jit_transform.js +173 -0
- package/build/transformers/replace-resources.d.ts +2 -0
- package/build/transformers/replace-resources.js +206 -0
- package/build/utils/ngcc-jest-processor.d.ts +1 -0
- package/build/utils/ngcc-jest-processor.js +75 -0
- package/package.json +26 -25
- package/setup-env/utils.mjs +19 -0
- package/setup-env/zone/index.d.mts +3 -0
- package/setup-env/zone/index.d.ts +6 -0
- package/setup-env/zone/index.js +43 -0
- package/setup-env/zone/index.mjs +18 -0
- package/setup-env/zoneless/index.d.mts +3 -0
- package/setup-env/zoneless/index.d.ts +6 -0
- package/setup-env/zoneless/index.js +11 -0
- package/setup-env/zoneless/index.mjs +39 -0
- package/setup-jest.js +10 -0
- package/setup-jest.mjs +12 -1
- package/jest-cjs.config.ts +0 -8
- package/jest-esm.config.ts +0 -8
- package/jest-src.config.ts +0 -18
- package/jest-transpile-cjs.config.ts +0 -8
- package/jest-transpile-esm.config.ts +0 -8
- package/tsconfig-base.spec.json +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,51 @@
|
|
|
1
|
+
## [14.3.0](https://github.com/thymikee/jest-preset-angular/compare/v14.2.4...v14.3.0) (2024-11-15)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* feat: add new setup test env functions ([21c0238](https://github.com/thymikee/jest-preset-angular/commit/21c0238)), closes [#354](https://github.com/thymikee/jest-preset-angular/issues/354) [#2755](https://github.com/thymikee/jest-preset-angular/issues/2755)
|
|
7
|
+
* feat: build package with type definitions ([a269daa](https://github.com/thymikee/jest-preset-angular/commit/a269daa))
|
|
8
|
+
* feat: deprecate `setup-jest.js` and `setup-jest.mjs` ([a304036](https://github.com/thymikee/jest-preset-angular/commit/a304036))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Code Refactoring
|
|
12
|
+
|
|
13
|
+
* test: switch example app test config files to ts ([e61f1ff](https://github.com/thymikee/jest-preset-angular/commit/e61f1ff))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## DEPRECATIONS
|
|
17
|
+
|
|
18
|
+
Importing `setup-jest.js`/`setup-jest.mjs` directly is deprecated. The files will be removed in the future.
|
|
19
|
+
|
|
20
|
+
Please use "setupZoneTestEnv" function instead. Example:
|
|
21
|
+
|
|
22
|
+
For CJS
|
|
23
|
+
```
|
|
24
|
+
// setup-jest.ts
|
|
25
|
+
import { setupZoneTestEnv } from 'jest-preset-angular/setup-env';
|
|
26
|
+
|
|
27
|
+
setupZoneTestEnv();
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
For ESM
|
|
31
|
+
```
|
|
32
|
+
// setup-jest.ts
|
|
33
|
+
import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/index.mjs';
|
|
34
|
+
|
|
35
|
+
setupZoneTestEnv();
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
## [14.2.4](https://github.com/thymikee/jest-preset-angular/compare/v14.2.3...v14.2.4) (2024-09-12)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
### Bug Fixes
|
|
44
|
+
|
|
45
|
+
* build: ensure build step runs before publishing ([3a602db](https://github.com/thymikee/jest-preset-angular/commit/3a602db))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
1
49
|
## [14.2.3](https://github.com/thymikee/jest-preset-angular/compare/v14.2.2...v14.2.3) (2024-09-12)
|
|
2
50
|
|
|
3
51
|
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<p align="center">
|
|
6
6
|
<a href="https://actions-badge.atrox.dev/thymikee/jest-preset-angular/goto?ref=main"><img alt="Build Status" src="https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fthymikee%2Fjest-preset-angular%2Fbadge%3Fref%3Dmain&style=flat-square" /></a>
|
|
7
7
|
<a href="https://www.npmjs.com/package/jest-preset-angular"><img src="https://img.shields.io/npm/v/jest-preset-angular/latest.svg?style=flat-square" alt="NPM Version" /></a>
|
|
8
|
-
<a href="https://github.com/thymikee/jest-preset-angular/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/jest-preset-angular.svg?style=flat-square" alt="GitHub license" /></a>
|
|
8
|
+
<a href="https://github.com/thymikee/jest-preset-angular/blob/main/LICENSE.md"><img src="https://img.shields.io/npm/l/jest-preset-angular.svg?style=flat-square" alt="GitHub license" /></a>
|
|
9
9
|
</p>
|
|
10
10
|
|
|
11
11
|
> Our online documentation is available at https://thymikee.github.io/jest-preset-angular/
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type TsJestAstTransformer, TsCompiler, type ConfigSet } from 'ts-jest';
|
|
2
|
+
import type ts from 'typescript';
|
|
3
|
+
export declare class NgJestCompiler extends TsCompiler {
|
|
4
|
+
readonly configSet: ConfigSet;
|
|
5
|
+
readonly jestCacheFS: Map<string, string>;
|
|
6
|
+
private readonly _defaultLibDirPath;
|
|
7
|
+
private readonly _libSourceFileCache;
|
|
8
|
+
constructor(configSet: ConfigSet, jestCacheFS: Map<string, string>);
|
|
9
|
+
protected _transpileOutput(fileContent: string, filePath: string): ts.TranspileOutput;
|
|
10
|
+
protected _makeTransformers(customTransformers: TsJestAstTransformer): ts.CustomTransformers;
|
|
11
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NgJestCompiler = void 0;
|
|
7
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const ts_jest_1 = require("ts-jest");
|
|
10
|
+
const jit_transform_1 = require("../transformers/jit_transform");
|
|
11
|
+
const replace_resources_1 = require("../transformers/replace-resources");
|
|
12
|
+
class NgJestCompiler extends ts_jest_1.TsCompiler {
|
|
13
|
+
constructor(configSet, jestCacheFS) {
|
|
14
|
+
super(configSet, jestCacheFS);
|
|
15
|
+
this.configSet = configSet;
|
|
16
|
+
this.jestCacheFS = jestCacheFS;
|
|
17
|
+
this._libSourceFileCache = new Map();
|
|
18
|
+
this._logger.debug('created NgJestCompiler');
|
|
19
|
+
this._defaultLibDirPath = node_path_1.default.dirname(this._ts.getDefaultLibFilePath(this._compilerOptions));
|
|
20
|
+
}
|
|
21
|
+
_transpileOutput(fileContent, filePath) {
|
|
22
|
+
var _a;
|
|
23
|
+
const scriptTarget = (_a = this._compilerOptions.target) !== null && _a !== void 0 ? _a : this._ts.ScriptTarget.Latest;
|
|
24
|
+
const sourceFile = this._ts.createSourceFile(filePath, fileContent, scriptTarget);
|
|
25
|
+
const compilerHost = {
|
|
26
|
+
getSourceFile: (fileName) => {
|
|
27
|
+
var _a;
|
|
28
|
+
if (fileName === node_path_1.default.normalize(filePath)) {
|
|
29
|
+
return sourceFile;
|
|
30
|
+
}
|
|
31
|
+
let libSourceFile = this._libSourceFileCache.get(fileName);
|
|
32
|
+
if (!libSourceFile) {
|
|
33
|
+
const libFilePath = node_path_1.default.join(this._defaultLibDirPath, fileName);
|
|
34
|
+
const libFileContent = (_a = this._ts.sys.readFile(libFilePath)) !== null && _a !== void 0 ? _a : '';
|
|
35
|
+
if (libFileContent) {
|
|
36
|
+
libSourceFile = this._ts.createSourceFile(fileName, libFileContent, scriptTarget);
|
|
37
|
+
this._libSourceFileCache.set(fileName, libSourceFile);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return libSourceFile;
|
|
41
|
+
},
|
|
42
|
+
writeFile: () => { },
|
|
43
|
+
getDefaultLibFileName: () => 'lib.d.ts',
|
|
44
|
+
useCaseSensitiveFileNames: () => false,
|
|
45
|
+
getCanonicalFileName: (fileName) => fileName,
|
|
46
|
+
getCurrentDirectory: () => '',
|
|
47
|
+
getNewLine: () => node_os_1.default.EOL,
|
|
48
|
+
fileExists: (fileName) => fileName === filePath,
|
|
49
|
+
readFile: () => '',
|
|
50
|
+
directoryExists: () => true,
|
|
51
|
+
getDirectories: () => [],
|
|
52
|
+
};
|
|
53
|
+
this.program = this._ts.createProgram([filePath], this._compilerOptions, compilerHost);
|
|
54
|
+
return this._ts.transpileModule(fileContent, {
|
|
55
|
+
fileName: filePath,
|
|
56
|
+
transformers: this._makeTransformers(this.configSet.resolvedTransformers),
|
|
57
|
+
compilerOptions: this._compilerOptions,
|
|
58
|
+
reportDiagnostics: this.configSet.shouldReportDiagnostics(filePath),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
_makeTransformers(customTransformers) {
|
|
62
|
+
var _a;
|
|
63
|
+
const allTransformers = super._makeTransformers(customTransformers);
|
|
64
|
+
return Object.assign(Object.assign(Object.assign({}, allTransformers.after), allTransformers.afterDeclarations), { before: [
|
|
65
|
+
...((_a = allTransformers.before) !== null && _a !== void 0 ? _a : []),
|
|
66
|
+
(0, replace_resources_1.replaceResources)(this.program),
|
|
67
|
+
(0, jit_transform_1.angularJitApplicationTransform)(this.program),
|
|
68
|
+
] });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.NgJestCompiler = NgJestCompiler;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const globalSetup: () => Promise<void>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.globalSetup = void 0;
|
|
13
|
+
const ngcc_jest_processor_1 = require("../utils/ngcc-jest-processor");
|
|
14
|
+
const globalSetup = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const ngJestConfig = globalThis.ngJest;
|
|
16
|
+
const tsconfig = ngJestConfig === null || ngJestConfig === void 0 ? void 0 : ngJestConfig.tsconfig;
|
|
17
|
+
if (!(ngJestConfig === null || ngJestConfig === void 0 ? void 0 : ngJestConfig.skipNgcc)) {
|
|
18
|
+
(0, ngcc_jest_processor_1.runNgccJestProcessor)(tsconfig);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
exports.globalSetup = globalSetup;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Logger } from 'bs-logger';
|
|
2
|
+
import { globsToMatcher } from 'jest-util';
|
|
3
|
+
import { type RawCompilerOptions, ConfigSet, type TsJestTransformOptions } from 'ts-jest';
|
|
4
|
+
import type { ParsedCommandLine } from 'typescript';
|
|
5
|
+
export declare class NgJestConfig extends ConfigSet {
|
|
6
|
+
readonly processWithEsbuild: ReturnType<typeof globsToMatcher>;
|
|
7
|
+
constructor(jestConfig: TsJestTransformOptions['config'] | undefined, parentLogger?: Logger | undefined);
|
|
8
|
+
protected _resolveTsConfig(compilerOptions?: RawCompilerOptions, resolvedConfigFile?: string): ParsedCommandLine;
|
|
9
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NgJestConfig = void 0;
|
|
4
|
+
const jest_util_1 = require("jest-util");
|
|
5
|
+
const ts_jest_1 = require("ts-jest");
|
|
6
|
+
const defaultProcessWithEsbuildPatterns = ['**/*.mjs'];
|
|
7
|
+
class NgJestConfig extends ts_jest_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
|
+
}
|
|
17
|
+
_resolveTsConfig(compilerOptions, resolvedConfigFile) {
|
|
18
|
+
const result = super._resolveTsConfig(compilerOptions, resolvedConfigFile);
|
|
19
|
+
result.options.enableIvy = true;
|
|
20
|
+
result.options.noEmitOnError = false;
|
|
21
|
+
result.options.suppressOutputPathCheck = true;
|
|
22
|
+
result.options.allowEmptyCodegenFiles = false;
|
|
23
|
+
result.options.annotationsAs = 'decorators';
|
|
24
|
+
result.options.enableResourceInlining = false;
|
|
25
|
+
result.options.allowJs = true;
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.NgJestConfig = NgJestConfig;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const TEMPLATE_URL = "templateUrl";
|
|
2
|
+
export declare const STYLE_URLS = "styleUrls";
|
|
3
|
+
export declare const STYLE_URL = "styleUrl";
|
|
4
|
+
export declare const STYLES = "styles";
|
|
5
|
+
export declare const TEMPLATE = "template";
|
|
6
|
+
export declare const REQUIRE = "require";
|
|
7
|
+
export declare const COMPONENT = "Component";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.COMPONENT = exports.REQUIRE = exports.TEMPLATE = exports.STYLES = exports.STYLE_URL = exports.STYLE_URLS = exports.TEMPLATE_URL = void 0;
|
|
4
|
+
exports.TEMPLATE_URL = 'templateUrl';
|
|
5
|
+
exports.STYLE_URLS = 'styleUrls';
|
|
6
|
+
exports.STYLE_URL = 'styleUrl';
|
|
7
|
+
exports.STYLES = 'styles';
|
|
8
|
+
exports.TEMPLATE = 'template';
|
|
9
|
+
exports.REQUIRE = 'require';
|
|
10
|
+
exports.COMPONENT = 'Component';
|
package/build/index.d.ts
ADDED
package/build/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TransformedSource } from '@jest/transform';
|
|
2
|
+
import { type TsJestTransformerOptions, ConfigSet, TsJestTransformer, type TsJestTransformOptions } from 'ts-jest';
|
|
3
|
+
export declare class NgJestTransformer extends TsJestTransformer {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(tsJestConfig?: TsJestTransformerOptions);
|
|
6
|
+
protected _createConfigSet(config: TsJestTransformOptions['config'] | undefined): ConfigSet;
|
|
7
|
+
protected _createCompiler(configSet: ConfigSet, cacheFS: Map<string, string>): void;
|
|
8
|
+
process(fileContent: string, filePath: string, transformOptions: TsJestTransformOptions): TransformedSource;
|
|
9
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _NgJestTransformer_ngJestLogger;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.NgJestTransformer = void 0;
|
|
16
|
+
const bs_logger_1 = require("bs-logger");
|
|
17
|
+
const esbuild_1 = require("esbuild");
|
|
18
|
+
const ts_jest_1 = require("ts-jest");
|
|
19
|
+
const ng_jest_compiler_1 = require("./compiler/ng-jest-compiler");
|
|
20
|
+
const ng_jest_config_1 = require("./config/ng-jest-config");
|
|
21
|
+
class NgJestTransformer extends ts_jest_1.TsJestTransformer {
|
|
22
|
+
constructor(tsJestConfig) {
|
|
23
|
+
var _a;
|
|
24
|
+
super(tsJestConfig);
|
|
25
|
+
_NgJestTransformer_ngJestLogger.set(this, void 0);
|
|
26
|
+
__classPrivateFieldSet(this, _NgJestTransformer_ngJestLogger, (0, bs_logger_1.createLogger)({
|
|
27
|
+
context: {
|
|
28
|
+
[bs_logger_1.LogContexts.package]: 'jest-preset-angular',
|
|
29
|
+
[bs_logger_1.LogContexts.logLevel]: bs_logger_1.LogLevels.trace,
|
|
30
|
+
version: require('../package.json').version,
|
|
31
|
+
},
|
|
32
|
+
targets: (_a = process.env.NG_JEST_LOG) !== null && _a !== void 0 ? _a : undefined,
|
|
33
|
+
}), "f");
|
|
34
|
+
}
|
|
35
|
+
_createConfigSet(config) {
|
|
36
|
+
return new ng_jest_config_1.NgJestConfig(config);
|
|
37
|
+
}
|
|
38
|
+
_createCompiler(configSet, cacheFS) {
|
|
39
|
+
this._compiler = new ng_jest_compiler_1.NgJestCompiler(configSet, cacheFS);
|
|
40
|
+
}
|
|
41
|
+
process(fileContent, filePath, transformOptions) {
|
|
42
|
+
const configSet = super._configsFor(transformOptions);
|
|
43
|
+
if (configSet.processWithEsbuild(filePath)) {
|
|
44
|
+
__classPrivateFieldGet(this, _NgJestTransformer_ngJestLogger, "f").debug({ filePath }, 'process with esbuild');
|
|
45
|
+
const compilerOpts = configSet.parsedTsConfig.options;
|
|
46
|
+
const { code, map } = (0, esbuild_1.transformSync)(fileContent, {
|
|
47
|
+
loader: 'js',
|
|
48
|
+
format: transformOptions.supportsStaticESM && configSet.useESM ? 'esm' : 'cjs',
|
|
49
|
+
target: compilerOpts.target === configSet.compilerModule.ScriptTarget.ES2015 ? 'es2015' : 'es2016',
|
|
50
|
+
sourcemap: compilerOpts.sourceMap,
|
|
51
|
+
sourcefile: filePath,
|
|
52
|
+
sourcesContent: true,
|
|
53
|
+
sourceRoot: compilerOpts.sourceRoot,
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
code,
|
|
57
|
+
map,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return super.process(fileContent, filePath, transformOptions);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.NgJestTransformer = NgJestTransformer;
|
|
66
|
+
_NgJestTransformer_ngJestLogger = new WeakMap();
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { TsJestTransformerOptions } from 'ts-jest';
|
|
2
|
+
declare const defaultTransformerOptions: TsJestTransformerOptions;
|
|
3
|
+
declare const defaultPreset: {
|
|
4
|
+
transformIgnorePatterns: string[];
|
|
5
|
+
transform: {
|
|
6
|
+
'^.+\\.(ts|js|mjs|html|svg)$': (string | import("ts-jest").TsJestGlobalOptions)[];
|
|
7
|
+
};
|
|
8
|
+
testEnvironment?: string | undefined;
|
|
9
|
+
moduleFileExtensions?: string[] | undefined;
|
|
10
|
+
snapshotSerializers?: string[] | undefined;
|
|
11
|
+
};
|
|
12
|
+
declare const defaultEsmPreset: {
|
|
13
|
+
extensionsToTreatAsEsm: string[];
|
|
14
|
+
moduleNameMapper: {
|
|
15
|
+
tslib: string;
|
|
16
|
+
};
|
|
17
|
+
transform: {
|
|
18
|
+
'^.+\\.(ts|js|html|svg)$': (string | {
|
|
19
|
+
useESM: boolean;
|
|
20
|
+
tsconfig?: boolean | string | import("ts-jest").RawCompilerOptions;
|
|
21
|
+
isolatedModules?: boolean;
|
|
22
|
+
compiler?: "typescript" | "ttypescript" | string;
|
|
23
|
+
astTransformers?: import("ts-jest").ConfigCustomTransformer;
|
|
24
|
+
diagnostics?: boolean | {
|
|
25
|
+
pretty?: boolean;
|
|
26
|
+
ignoreCodes?: number | string | Array<number | string>;
|
|
27
|
+
exclude?: string[];
|
|
28
|
+
warnOnly?: boolean;
|
|
29
|
+
};
|
|
30
|
+
babelConfig?: boolean | string | import("ts-jest").BabelConfig;
|
|
31
|
+
stringifyContentPathRegex?: string | RegExp;
|
|
32
|
+
})[];
|
|
33
|
+
};
|
|
34
|
+
transformIgnorePatterns: string[];
|
|
35
|
+
testEnvironment?: string | undefined;
|
|
36
|
+
moduleFileExtensions?: string[] | undefined;
|
|
37
|
+
snapshotSerializers?: string[] | undefined;
|
|
38
|
+
};
|
|
39
|
+
export { defaultPreset, defaultEsmPreset, defaultTransformerOptions };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.defaultTransformerOptions = exports.defaultEsmPreset = exports.defaultPreset = void 0;
|
|
7
|
+
const serializers_1 = __importDefault(require("../serializers"));
|
|
8
|
+
const baseConfig = {
|
|
9
|
+
testEnvironment: 'jsdom',
|
|
10
|
+
moduleFileExtensions: ['ts', 'html', 'js', 'json', 'mjs'],
|
|
11
|
+
snapshotSerializers: serializers_1.default,
|
|
12
|
+
};
|
|
13
|
+
const defaultTransformerOptions = {
|
|
14
|
+
tsconfig: '<rootDir>/tsconfig.spec.json',
|
|
15
|
+
stringifyContentPathRegex: '\\.(html|svg)$',
|
|
16
|
+
};
|
|
17
|
+
exports.defaultTransformerOptions = defaultTransformerOptions;
|
|
18
|
+
const defaultPreset = Object.assign(Object.assign({}, baseConfig), { transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'], transform: {
|
|
19
|
+
'^.+\\.(ts|js|mjs|html|svg)$': ['jest-preset-angular', defaultTransformerOptions],
|
|
20
|
+
} });
|
|
21
|
+
exports.defaultPreset = defaultPreset;
|
|
22
|
+
const defaultEsmPreset = Object.assign(Object.assign({}, baseConfig), { extensionsToTreatAsEsm: ['.ts'], moduleNameMapper: {
|
|
23
|
+
tslib: 'tslib/tslib.es6.js',
|
|
24
|
+
}, transform: {
|
|
25
|
+
'^.+\\.(ts|js|html|svg)$': [
|
|
26
|
+
'jest-preset-angular',
|
|
27
|
+
Object.assign(Object.assign({}, defaultTransformerOptions), { useESM: true }),
|
|
28
|
+
],
|
|
29
|
+
}, transformIgnorePatterns: ['node_modules/(?!tslib)'] });
|
|
30
|
+
exports.defaultEsmPreset = defaultEsmPreset;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
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
|
+
};
|
|
7
|
+
module.exports = ngJestResolver;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const HTML_ELEMENT_REGEXP = /Comment/;
|
|
3
|
+
const test = (value) => (value === null || value === void 0 ? void 0 : value.nodeType) === 8 && value.constructor !== undefined && HTML_ELEMENT_REGEXP.test(value.constructor.name);
|
|
4
|
+
const serialize = () => '';
|
|
5
|
+
module.exports = {
|
|
6
|
+
serialize,
|
|
7
|
+
test,
|
|
8
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { OldPlugin } from 'pretty-format';
|
|
2
|
+
type PluginPrintFnArgs = Parameters<OldPlugin['print']>;
|
|
3
|
+
type NgSnapshotOptions = {
|
|
4
|
+
omitAllCompAttrs?: boolean;
|
|
5
|
+
};
|
|
6
|
+
type PluginPrintFn = (fixture: PluginPrintFnArgs[0], printer: PluginPrintFnArgs[1], indent: PluginPrintFnArgs[2], opts: PluginPrintFnArgs[3] & NgSnapshotOptions, colors: PluginPrintFnArgs[4]) => string;
|
|
7
|
+
declare const _default: {
|
|
8
|
+
print: PluginPrintFn;
|
|
9
|
+
test: (arg0: any) => boolean;
|
|
10
|
+
};
|
|
11
|
+
export = _default;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const attributesToRemovePatterns = ['__ngContext__'];
|
|
3
|
+
const removeTrailingWhiteSpaces = (serializedComponent) => {
|
|
4
|
+
return serializedComponent.replace(/\n^\s*\n/gm, '\n');
|
|
5
|
+
};
|
|
6
|
+
const print = (fixture, printer, indent, opts, colors) => {
|
|
7
|
+
const { componentRef, componentInstance } = fixture;
|
|
8
|
+
const componentDef = componentRef.componentType.ɵcmp;
|
|
9
|
+
const componentName = componentDef.selectors[0][0];
|
|
10
|
+
const nodes = Array.from(componentRef.location.nativeElement.childNodes).map(printer).join('');
|
|
11
|
+
let serializedComponent = '';
|
|
12
|
+
if (opts.omitAllCompAttrs) {
|
|
13
|
+
serializedComponent = '<' + componentName + '>\n' + indent(nodes) + '\n</' + componentName + '>';
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
const attributes = Object.keys(componentInstance).filter((key) => !attributesToRemovePatterns.includes(key));
|
|
17
|
+
const componentAttrs = attributes
|
|
18
|
+
.sort()
|
|
19
|
+
.map((attribute) => {
|
|
20
|
+
const compAttrVal = componentInstance[attribute];
|
|
21
|
+
return (opts.spacing +
|
|
22
|
+
indent(`${colors.prop.open}${attribute}${colors.prop.close}=`) +
|
|
23
|
+
colors.value.open +
|
|
24
|
+
(compAttrVal && compAttrVal.constructor
|
|
25
|
+
? `{[Function ${compAttrVal.constructor.name}]}`
|
|
26
|
+
: `"${compAttrVal}"`) +
|
|
27
|
+
colors.value.close);
|
|
28
|
+
})
|
|
29
|
+
.join('');
|
|
30
|
+
serializedComponent =
|
|
31
|
+
'<' +
|
|
32
|
+
componentName +
|
|
33
|
+
componentAttrs +
|
|
34
|
+
(componentAttrs.length ? '\n' : '') +
|
|
35
|
+
'>\n' +
|
|
36
|
+
indent(nodes) +
|
|
37
|
+
'\n</' +
|
|
38
|
+
componentName +
|
|
39
|
+
'>';
|
|
40
|
+
}
|
|
41
|
+
serializedComponent = removeTrailingWhiteSpaces(serializedComponent);
|
|
42
|
+
return serializedComponent;
|
|
43
|
+
};
|
|
44
|
+
const test = (val) => !!val && typeof val === 'object' && 'componentRef' in val;
|
|
45
|
+
module.exports = {
|
|
46
|
+
print,
|
|
47
|
+
test,
|
|
48
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
serialize: (val: any, config: import("pretty-format").Config, indentation: string, depth: number, refs: import("pretty-format").Refs, printer: import("pretty-format").Printer) => string;
|
|
3
|
+
test: (arg0: any) => boolean;
|
|
4
|
+
};
|
|
5
|
+
export = _default;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const pretty_format_1 = require("pretty-format");
|
|
3
|
+
const jestDOMElementSerializer = pretty_format_1.plugins.DOMElement;
|
|
4
|
+
const attributesToRemovePatterns = ['ng-reflect', '_nghost', '_ngcontent', 'ng-version'];
|
|
5
|
+
const attributesToClean = {
|
|
6
|
+
class: [/^(?:mat|cdk|ng).*-\w*\d+-\d+$/, /^ng-star-inserted$/],
|
|
7
|
+
id: [/^(?:mat|cdk|ng).*-\d+$/],
|
|
8
|
+
for: [/^(?:mat|cdk|ng).*-\d+$/],
|
|
9
|
+
'aria-owns': [/^(?:mat|cdk|ng).*-\d+$/],
|
|
10
|
+
'aria-labelledby': [/^(?:mat|cdk|ng).*-\d+$/],
|
|
11
|
+
'aria-controls': [/^(?:mat|cdk|ng).*-\d+$/],
|
|
12
|
+
};
|
|
13
|
+
const hasAttributesToRemove = (attribute) => attributesToRemovePatterns.some((removePattern) => attribute.name.startsWith(removePattern));
|
|
14
|
+
const hasAttributesToClean = (attribute) => Object.keys(attributesToClean).some((removePatternKey) => attribute.name === removePatternKey);
|
|
15
|
+
const removeAngularAttributes = (node) => {
|
|
16
|
+
const nodeCopy = node.cloneNode(true);
|
|
17
|
+
Object.values(nodeCopy.attributes)
|
|
18
|
+
.filter(hasAttributesToRemove)
|
|
19
|
+
.forEach((attribute) => nodeCopy.attributes.removeNamedItem(attribute.name));
|
|
20
|
+
return nodeCopy;
|
|
21
|
+
};
|
|
22
|
+
const cleanAngularClasses = (node) => {
|
|
23
|
+
const nodeCopy = node.cloneNode(true);
|
|
24
|
+
Object.values(nodeCopy.attributes)
|
|
25
|
+
.filter(hasAttributesToClean)
|
|
26
|
+
.forEach((attribute) => {
|
|
27
|
+
attribute.value = attribute.value
|
|
28
|
+
.split(' ')
|
|
29
|
+
.filter((attrValue) => !attributesToClean[attribute.name].some((attributeCleanRegex) => attributeCleanRegex.test(attrValue)))
|
|
30
|
+
.join(' ');
|
|
31
|
+
if (attribute.value === '') {
|
|
32
|
+
nodeCopy.attributes.removeNamedItem(attribute.name);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
nodeCopy.attributes.setNamedItem(attribute);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return nodeCopy;
|
|
39
|
+
};
|
|
40
|
+
const shouldSerializeElement = (val) => {
|
|
41
|
+
return Object.values(val.attributes).some((attribute) => hasAttributesToRemove(attribute) || hasAttributesToClean(attribute));
|
|
42
|
+
};
|
|
43
|
+
const serialize = (node, ...rest) => {
|
|
44
|
+
let nodeCopy = removeAngularAttributes(node);
|
|
45
|
+
nodeCopy = cleanAngularClasses(nodeCopy);
|
|
46
|
+
return jestDOMElementSerializer.serialize(nodeCopy, ...rest);
|
|
47
|
+
};
|
|
48
|
+
const test = (val) => {
|
|
49
|
+
if (!val || !(val instanceof Element)) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return jestDOMElementSerializer.test(val) && shouldSerializeElement(val);
|
|
53
|
+
};
|
|
54
|
+
module.exports = {
|
|
55
|
+
serialize,
|
|
56
|
+
test,
|
|
57
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const import_meta_url: import("url").URL;
|