jest-preset-angular 14.3.0 → 14.3.2

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 CHANGED
@@ -1,3 +1,21 @@
1
+ ## [14.3.2](https://github.com/thymikee/jest-preset-angular/compare/v14.3.1...v14.3.2) (2024-11-20)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * fix: include `version` from `package.json` into cache key ([de02c79](https://github.com/thymikee/jest-preset-angular/commit/de02c79)), closes [#2844](https://github.com/thymikee/jest-preset-angular/issues/2844)
7
+
8
+
9
+
10
+ ## [14.3.1](https://github.com/thymikee/jest-preset-angular/compare/v14.3.0...v14.3.1) (2024-11-18)
11
+
12
+
13
+ ### Documentation
14
+
15
+ * docs: simplify `README.md` about installation and configuration ([79ea18b](https://github.com/thymikee/jest-preset-angular/commit/79ea18b))
16
+
17
+
18
+
1
19
  ## [14.3.0](https://github.com/thymikee/jest-preset-angular/compare/v14.2.4...v14.3.0) (2024-11-15)
2
20
 
3
21
 
@@ -22,7 +40,7 @@ Please use "setupZoneTestEnv" function instead. Example:
22
40
  For CJS
23
41
  ```
24
42
  // setup-jest.ts
25
- import { setupZoneTestEnv } from 'jest-preset-angular/setup-env';
43
+ import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/zone';
26
44
 
27
45
  setupZoneTestEnv();
28
46
  ```
@@ -30,11 +48,13 @@ setupZoneTestEnv();
30
48
  For ESM
31
49
  ```
32
50
  // setup-jest.ts
33
- import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/index.mjs';
51
+ import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/zone/index.mjs';
34
52
 
35
53
  setupZoneTestEnv();
36
54
  ```
37
55
 
56
+ See more at https://thymikee.github.io/jest-preset-angular/docs/getting-started/test-environment
57
+
38
58
 
39
59
 
40
60
  ## [14.2.4](https://github.com/thymikee/jest-preset-angular/compare/v14.2.3...v14.2.4) (2024-09-12)
package/README.md CHANGED
@@ -12,10 +12,7 @@
12
12
 
13
13
  > This is a part of the article: [Testing Angular faster with Jest](https://www.xfive.co/blog/testing-angular-faster-jest/).
14
14
 
15
- ## Getting Started
16
-
17
- These instructions will get you setup to use `jest-preset-angular` in your project. For more detailed documentation,
18
- please check [online documentation](https://thymikee.github.io/jest-preset-angular).
15
+ ## Installation
19
16
 
20
17
  Install using [`yarn`](https://yarnpkg.com/en/package/jest-preset-angular):
21
18
 
@@ -31,50 +28,7 @@ npm install -D jest jest-preset-angular @types/jest
31
28
 
32
29
  ## Configuration
33
30
 
34
- In your project root, create `setup-jest.ts` file with following contents:
35
-
36
- ```ts
37
- import 'jest-preset-angular/setup-jest';
38
- ```
39
-
40
- Add the following section:
41
-
42
- - to your root `jest.config.js`
43
-
44
- ```js
45
- // jest.config.js
46
- module.exports = {
47
- preset: 'jest-preset-angular',
48
- setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
49
- globalSetup: 'jest-preset-angular/global-setup',
50
- };
51
- ```
52
-
53
- - or to your root `package.json`
54
-
55
- ```json
56
- {
57
- "jest": {
58
- "preset": "jest-preset-angular",
59
- "setupFilesAfterEnv": ["<rootDir>/setup-jest.ts"],
60
- "globalSetup": "jest-preset-angular/global-setup"
61
- }
62
- }
63
- ```
64
-
65
- Adjust your `tsconfig.spec.json` to be:
66
-
67
- ```json
68
- {
69
- "extends": "./tsconfig.json",
70
- "compilerOptions": {
71
- "outDir": "./out-tsc/spec",
72
- "module": "CommonJs",
73
- "types": ["jest"]
74
- },
75
- "include": ["src/**/*.spec.ts", "src/**/*.d.ts"]
76
- }
77
- ```
31
+ Check out our [Configuration guidance](https://thymikee.github.io/jest-preset-angular/docs/getting-started/installation).
78
32
 
79
33
  **IMPORTANT**
80
34
 
@@ -5,5 +5,7 @@ export declare class NgJestTransformer extends TsJestTransformer {
5
5
  constructor(tsJestConfig?: TsJestTransformerOptions);
6
6
  protected _createConfigSet(config: TsJestTransformOptions['config'] | undefined): ConfigSet;
7
7
  protected _createCompiler(configSet: ConfigSet, cacheFS: Map<string, string>): void;
8
+ private get version();
8
9
  process(fileContent: string, filePath: string, transformOptions: TsJestTransformOptions): TransformedSource;
10
+ getCacheKey(fileContent: string, filePath: string, transformOptions: TsJestTransformOptions): string;
9
11
  }
@@ -13,11 +13,37 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var _NgJestTransformer_ngJestLogger;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.NgJestTransformer = void 0;
16
+ const node_crypto_1 = require("node:crypto");
16
17
  const bs_logger_1 = require("bs-logger");
17
18
  const esbuild_1 = require("esbuild");
18
19
  const ts_jest_1 = require("ts-jest");
19
20
  const ng_jest_compiler_1 = require("./compiler/ng-jest-compiler");
20
21
  const ng_jest_config_1 = require("./config/ng-jest-config");
22
+ const cache = {};
23
+ const sha1 = (...data) => {
24
+ const canCache = data.length === 1 && typeof data[0] === 'string';
25
+ let cacheKey;
26
+ if (canCache) {
27
+ cacheKey = data[0];
28
+ if (cacheKey in cache) {
29
+ return cache[cacheKey];
30
+ }
31
+ }
32
+ const hash = (0, node_crypto_1.createHash)('sha1');
33
+ data.forEach((item) => {
34
+ if (typeof item === 'string') {
35
+ hash.update(item, 'utf8');
36
+ }
37
+ else {
38
+ hash.update(item);
39
+ }
40
+ });
41
+ const res = hash.digest('hex').toString();
42
+ if (canCache) {
43
+ cache[cacheKey] = res;
44
+ }
45
+ return res;
46
+ };
21
47
  class NgJestTransformer extends ts_jest_1.TsJestTransformer {
22
48
  constructor(tsJestConfig) {
23
49
  var _a;
@@ -27,7 +53,7 @@ class NgJestTransformer extends ts_jest_1.TsJestTransformer {
27
53
  context: {
28
54
  [bs_logger_1.LogContexts.package]: 'jest-preset-angular',
29
55
  [bs_logger_1.LogContexts.logLevel]: bs_logger_1.LogLevels.trace,
30
- version: require('../package.json').version,
56
+ version: this.version,
31
57
  },
32
58
  targets: (_a = process.env.NG_JEST_LOG) !== null && _a !== void 0 ? _a : undefined,
33
59
  }), "f");
@@ -38,6 +64,9 @@ class NgJestTransformer extends ts_jest_1.TsJestTransformer {
38
64
  _createCompiler(configSet, cacheFS) {
39
65
  this._compiler = new ng_jest_compiler_1.NgJestCompiler(configSet, cacheFS);
40
66
  }
67
+ get version() {
68
+ return require('../package.json').version;
69
+ }
41
70
  process(fileContent, filePath, transformOptions) {
42
71
  const configSet = super._configsFor(transformOptions);
43
72
  if (configSet.processWithEsbuild(filePath)) {
@@ -61,6 +90,9 @@ class NgJestTransformer extends ts_jest_1.TsJestTransformer {
61
90
  return super.process(fileContent, filePath, transformOptions);
62
91
  }
63
92
  }
93
+ getCacheKey(fileContent, filePath, transformOptions) {
94
+ return sha1(super.getCacheKey(fileContent, filePath, transformOptions), this.version);
95
+ }
64
96
  }
65
97
  exports.NgJestTransformer = NgJestTransformer;
66
98
  _NgJestTransformer_ngJestLogger = new WeakMap();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jest-preset-angular",
3
- "version": "14.3.0",
3
+ "version": "14.3.2",
4
4
  "description": "Jest preset configuration for Angular projects",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -66,9 +66,9 @@
66
66
  },
67
67
  "devDependencies": {
68
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",
69
+ "@angular-eslint/eslint-plugin": "^18.4.1",
70
+ "@angular-eslint/eslint-plugin-template": "^18.4.1",
71
+ "@angular-eslint/template-parser": "^18.4.1",
72
72
  "@angular/animations": "^18.2.12",
73
73
  "@angular/cdk": "^18.2.13",
74
74
  "@angular/common": "^18.2.12",
@@ -81,17 +81,15 @@
81
81
  "@angular/platform-browser-dynamic": "^18.2.12",
82
82
  "@babel/core": "^7.26.0",
83
83
  "@babel/preset-env": "^7.26.0",
84
- "@commitlint/cli": "^19.5.0",
85
- "@commitlint/config-angular": "^19.5.0",
84
+ "@commitlint/cli": "^19.6.0",
85
+ "@commitlint/config-angular": "^19.6.0",
86
86
  "@jest/transform": "^29.7.0",
87
87
  "@jest/types": "^29.6.3",
88
- "@types/babel__core": "^7.20.5",
89
- "@types/babel__preset-env": "^7.9.7",
90
88
  "@types/jest": "^29.5.14",
91
- "@types/node": "^22.9.0",
89
+ "@types/node": "^22.9.1",
92
90
  "@types/semver": "^7.5.8",
93
- "@typescript-eslint/eslint-plugin": "^7.18.0",
94
- "@typescript-eslint/parser": "^7.18.0",
91
+ "@typescript-eslint/eslint-plugin": "^8.15.0",
92
+ "@typescript-eslint/parser": "^8.15.0",
95
93
  "babel-jest": "^29.7.0",
96
94
  "chalk": "^4.1.2",
97
95
  "conventional-changelog-cli": "^5.0.0",
@@ -106,7 +104,7 @@
106
104
  "fs-extra": "^11.2.0",
107
105
  "github-files-fetcher": "^1.6.0",
108
106
  "glob": "^10.4.5",
109
- "husky": "^9.1.6",
107
+ "husky": "^9.1.7",
110
108
  "jest": "^29.7.0",
111
109
  "pinst": "^3.0.0",
112
110
  "prettier": "^2.8.8",