jest-preset-angular 14.3.2 → 14.3.3
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 +9 -0
- package/package.json +1 -1
- package/setup-env/{utils.mjs → utils.js} +8 -3
- package/setup-env/zone/index.js +2 -20
- package/setup-env/zone/index.mjs +7 -3
- package/setup-env/zoneless/index.js +44 -4
- package/setup-env/zoneless/index.mjs +28 -19
- package/setup-jest.js +5 -1
- package/setup-jest.mjs +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
## [14.3.3](https://github.com/thymikee/jest-preset-angular/compare/v14.3.2...v14.3.3) (2024-11-22)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* feat: support configuring zoneless test env for CJS ([7a270b1](https://github.com/thymikee/jest-preset-angular/commit/7a270b1))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
1
10
|
## [14.3.2](https://github.com/thymikee/jest-preset-angular/compare/v14.3.1...v14.3.2) (2024-11-20)
|
|
2
11
|
|
|
3
12
|
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
const { TextDecoder, TextEncoder } = require('util');
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const polyfillEncoder = () => {
|
|
4
4
|
if (typeof globalThis.TextEncoder === 'undefined') {
|
|
5
5
|
globalThis.TextEncoder = TextEncoder;
|
|
6
6
|
globalThis.TextDecoder = TextDecoder;
|
|
7
7
|
}
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
const resolveTestEnvOptions = (options) => {
|
|
11
11
|
const globalTestEnvOptions = globalThis.ngJest?.testEnvironmentOptions;
|
|
12
12
|
if (globalTestEnvOptions) {
|
|
13
13
|
console.warn(
|
|
@@ -17,3 +17,8 @@ export const resolveTestEnvOptions = (options) => {
|
|
|
17
17
|
|
|
18
18
|
return globalTestEnvOptions ?? options;
|
|
19
19
|
};
|
|
20
|
+
|
|
21
|
+
module.exports = {
|
|
22
|
+
polyfillEncoder,
|
|
23
|
+
resolveTestEnvOptions,
|
|
24
|
+
};
|
package/setup-env/zone/index.js
CHANGED
|
@@ -1,38 +1,20 @@
|
|
|
1
1
|
require('zone.js');
|
|
2
2
|
require('zone.js/testing');
|
|
3
3
|
|
|
4
|
-
const { TextEncoder, TextDecoder } = require('util');
|
|
5
|
-
|
|
6
4
|
const { getTestBed } = require('@angular/core/testing');
|
|
7
5
|
const {
|
|
8
6
|
BrowserDynamicTestingModule,
|
|
9
7
|
platformBrowserDynamicTesting,
|
|
10
8
|
} = require('@angular/platform-browser-dynamic/testing');
|
|
11
9
|
|
|
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
|
-
};
|
|
10
|
+
const { polyfillEncoder, resolveTestEnvOptions } = require('../utils');
|
|
29
11
|
|
|
30
12
|
const setupZoneTestEnv = (options) => {
|
|
31
13
|
polyfillEncoder();
|
|
32
14
|
const testEnvironmentOptions = resolveTestEnvOptions(options);
|
|
33
15
|
|
|
34
16
|
getTestBed().initTestEnvironment(
|
|
35
|
-
BrowserDynamicTestingModule,
|
|
17
|
+
[BrowserDynamicTestingModule],
|
|
36
18
|
platformBrowserDynamicTesting(),
|
|
37
19
|
testEnvironmentOptions,
|
|
38
20
|
);
|
package/setup-env/zone/index.mjs
CHANGED
|
@@ -4,15 +4,19 @@ import 'zone.js/testing';
|
|
|
4
4
|
import { getTestBed } from '@angular/core/testing';
|
|
5
5
|
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
|
|
6
6
|
|
|
7
|
-
import { polyfillEncoder, resolveTestEnvOptions } from '../utils
|
|
7
|
+
import { polyfillEncoder, resolveTestEnvOptions } from '../utils';
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
const setupZoneTestEnv = (options) => {
|
|
10
10
|
polyfillEncoder();
|
|
11
11
|
const testEnvironmentOptions = resolveTestEnvOptions(options);
|
|
12
12
|
|
|
13
13
|
getTestBed().initTestEnvironment(
|
|
14
|
-
BrowserDynamicTestingModule,
|
|
14
|
+
[BrowserDynamicTestingModule],
|
|
15
15
|
platformBrowserDynamicTesting(),
|
|
16
16
|
testEnvironmentOptions,
|
|
17
17
|
);
|
|
18
18
|
};
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
setupZoneTestEnv,
|
|
22
|
+
}
|
|
@@ -1,8 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
1
|
+
const { provideExperimentalZonelessChangeDetection, NgModule, ErrorHandler } = require('@angular/core');
|
|
2
|
+
const { getTestBed } = require('@angular/core/testing');
|
|
3
|
+
const {
|
|
4
|
+
BrowserDynamicTestingModule,
|
|
5
|
+
platformBrowserDynamicTesting,
|
|
6
|
+
} = require('@angular/platform-browser-dynamic/testing');
|
|
7
|
+
|
|
8
|
+
const { polyfillEncoder, resolveTestEnvOptions } = require('../utils');
|
|
9
|
+
|
|
10
|
+
const provideZonelessConfig = () => {
|
|
11
|
+
class TestModule {}
|
|
12
|
+
NgModule({
|
|
13
|
+
providers: [
|
|
14
|
+
provideExperimentalZonelessChangeDetection(),
|
|
15
|
+
{
|
|
16
|
+
provide: ErrorHandler,
|
|
17
|
+
useValue: {
|
|
18
|
+
handleError: (e) => {
|
|
19
|
+
throw e;
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
})(TestModule);
|
|
25
|
+
|
|
26
|
+
return TestModule;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const setupZonelessTestEnv = (options) => {
|
|
30
|
+
polyfillEncoder();
|
|
31
|
+
if (typeof provideExperimentalZonelessChangeDetection !== 'undefined') {
|
|
32
|
+
const testEnvironmentOptions = resolveTestEnvOptions(options);
|
|
33
|
+
|
|
34
|
+
getTestBed().initTestEnvironment(
|
|
35
|
+
[BrowserDynamicTestingModule, provideZonelessConfig()],
|
|
36
|
+
platformBrowserDynamicTesting(),
|
|
37
|
+
testEnvironmentOptions,
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
3
43
|
throw Error(
|
|
4
|
-
'
|
|
5
|
-
'
|
|
44
|
+
'Cannot find provideExperimentalZonelessChangeDetection() to setup zoneless testing environment. ' +
|
|
45
|
+
'Please use setupZoneTestEnv() from jest-preset-angular/setup-env/setup-zone-env.mjs instead.',
|
|
6
46
|
);
|
|
7
47
|
};
|
|
8
48
|
|
|
@@ -2,29 +2,34 @@ import { ErrorHandler, NgModule, provideExperimentalZonelessChangeDetection } fr
|
|
|
2
2
|
import { getTestBed } from '@angular/core/testing';
|
|
3
3
|
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
|
|
4
4
|
|
|
5
|
-
import { polyfillEncoder, resolveTestEnvOptions } from '../utils
|
|
5
|
+
import { polyfillEncoder, resolveTestEnvOptions } from '../utils';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
{
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
handleError: (e) => {
|
|
18
|
-
throw e;
|
|
19
|
-
},
|
|
7
|
+
const provideZonelessConfig = () => {
|
|
8
|
+
class TestModule {}
|
|
9
|
+
NgModule({
|
|
10
|
+
providers: [
|
|
11
|
+
provideExperimentalZonelessChangeDetection(),
|
|
12
|
+
{
|
|
13
|
+
provide: ErrorHandler,
|
|
14
|
+
useValue: {
|
|
15
|
+
handleError: (e) => {
|
|
16
|
+
throw e;
|
|
20
17
|
},
|
|
21
18
|
},
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
})(TestModule);
|
|
22
|
+
|
|
23
|
+
return TestModule;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const setupZonelessTestEnv = (options) => {
|
|
27
|
+
polyfillEncoder();
|
|
28
|
+
if (typeof provideExperimentalZonelessChangeDetection !== 'undefined') {
|
|
29
|
+
const testEnvironmentOptions = resolveTestEnvOptions(options);
|
|
25
30
|
|
|
26
31
|
getTestBed().initTestEnvironment(
|
|
27
|
-
[BrowserDynamicTestingModule,
|
|
32
|
+
[BrowserDynamicTestingModule, provideZonelessConfig()],
|
|
28
33
|
platformBrowserDynamicTesting(),
|
|
29
34
|
testEnvironmentOptions,
|
|
30
35
|
);
|
|
@@ -34,6 +39,10 @@ export const setupZonelessTestEnv = (options) => {
|
|
|
34
39
|
|
|
35
40
|
throw Error(
|
|
36
41
|
'Cannot find provideExperimentalZonelessChangeDetection() to setup zoneless testing environment. ' +
|
|
37
|
-
|
|
42
|
+
'Please use setupZoneTestEnv() from jest-preset-angular/setup-env/setup-zone-env.mjs instead.',
|
|
38
43
|
);
|
|
39
44
|
};
|
|
45
|
+
|
|
46
|
+
export {
|
|
47
|
+
setupZonelessTestEnv
|
|
48
|
+
}
|
package/setup-jest.js
CHANGED
|
@@ -25,4 +25,8 @@ if (typeof globalThis.TextEncoder === 'undefined') {
|
|
|
25
25
|
|
|
26
26
|
const testEnvironmentOptions = globalThis.ngJest?.testEnvironmentOptions ?? Object.create(null);
|
|
27
27
|
|
|
28
|
-
getTestBed().initTestEnvironment(
|
|
28
|
+
getTestBed().initTestEnvironment(
|
|
29
|
+
[BrowserDynamicTestingModule],
|
|
30
|
+
platformBrowserDynamicTesting(),
|
|
31
|
+
testEnvironmentOptions,
|
|
32
|
+
);
|
package/setup-jest.mjs
CHANGED
|
@@ -22,4 +22,4 @@ if (typeof globalThis.TextEncoder === 'undefined') {
|
|
|
22
22
|
|
|
23
23
|
const testEnvironmentOptions = globalThis.ngJest?.testEnvironmentOptions ?? Object.create(null);
|
|
24
24
|
|
|
25
|
-
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), testEnvironmentOptions);
|
|
25
|
+
getTestBed().initTestEnvironment([BrowserDynamicTestingModule], platformBrowserDynamicTesting(), testEnvironmentOptions);
|