Skip to content

Commit e4ff0c0

Browse files
authored
feat(presets): add type definition for presets entry point (#801)
1 parent a9ad3ef commit e4ff0c0

File tree

6 files changed

+113
-21
lines changed

6 files changed

+113
-21
lines changed

presets/index.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { TsJestPresets } from 'ts-jest/dist/types';
2+
3+
declare const _default: {
4+
defaults: TsJestPresets;
5+
defaultsESM: TsJestPresets;
6+
};
7+
export = _default;

presets/index.js

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,22 @@ const basePreset = {
2222
}
2323

2424
module.exports = {
25-
get defaults() {
26-
return basePreset;
27-
},
28-
get defaultsESM() {
29-
return {
30-
...basePreset,
31-
extensionsToTreatAsEsm: ['.ts'],
32-
globals: {
33-
'ts-jest': {
34-
...basePreset.globals['ts-jest'],
35-
useESM: true,
36-
},
37-
},
38-
moduleNameMapper: {
39-
...basePreset.moduleNameMapper,
40-
'tslib': '<rootDir>/node_modules/tslib/tslib.es6.js',
25+
defaults: basePreset,
26+
defaultsESM: {
27+
...basePreset,
28+
extensionsToTreatAsEsm: ['.ts'],
29+
globals: {
30+
'ts-jest': {
31+
...basePreset.globals['ts-jest'],
32+
useESM: true,
4133
},
42-
transformIgnorePatterns: [
43-
'node_modules/(?!tslib)',
44-
],
45-
}
46-
},
34+
},
35+
moduleNameMapper: {
36+
...basePreset.moduleNameMapper,
37+
'tslib': '<rootDir>/node_modules/tslib/tslib.es6.js',
38+
},
39+
transformIgnorePatterns: [
40+
'node_modules/(?!tslib)',
41+
],
42+
}
4743
}

src/__tests__/__snapshots__/ng-jest-config.spec.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
exports[`NgJestConfig _resolveTsConfig should return config including Angular compiler config with tsconfig as a string from ts-jest option 1`] = `
44
Object {
5+
"allowSyntheticDefaultImports": true,
56
"annotationsAs": "decorators",
67
"declaration": false,
78
"enableIvy": true,
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Presets should return the correct ESM preset value: esm-preset 1`] = `
4+
Object {
5+
"extensionsToTreatAsEsm": Array [
6+
".ts",
7+
],
8+
"globals": Object {
9+
"ts-jest": Object {
10+
"stringifyContentPathRegex": "\\\\.html$",
11+
"tsconfig": "<rootDir>/tsconfig.spec.json",
12+
"useESM": true,
13+
},
14+
},
15+
"moduleFileExtensions": Array [
16+
"ts",
17+
"html",
18+
"js",
19+
"json",
20+
],
21+
"moduleNameMapper": Object {
22+
"^app/(.*)$": "<rootDir>/src/app/$1",
23+
"^assets/(.*)$": "<rootDir>/src/assets/$1",
24+
"^environments/(.*)$": "<rootDir>/src/environments/$1",
25+
"^src/(.*)$": "<rootDir>/src/$1",
26+
"tslib": "<rootDir>/node_modules/tslib/tslib.es6.js",
27+
},
28+
"snapshotSerializers": Array [
29+
"jest-preset-angular/build/serializers/html-comment",
30+
"jest-preset-angular/build/serializers/ng-snapshot",
31+
"jest-preset-angular/build/serializers/no-ng-attributes",
32+
],
33+
"testEnvironment": "jsdom",
34+
"transform": Object {
35+
"^.+\\\\.(ts|js|html)$": "jest-preset-angular",
36+
},
37+
"transformIgnorePatterns": Array [
38+
"node_modules/(?!tslib)",
39+
],
40+
}
41+
`;
42+
43+
exports[`Presets should return the correct default preset value: default-preset 1`] = `
44+
Object {
45+
"globals": Object {
46+
"ts-jest": Object {
47+
"stringifyContentPathRegex": "\\\\.html$",
48+
"tsconfig": "<rootDir>/tsconfig.spec.json",
49+
},
50+
},
51+
"moduleFileExtensions": Array [
52+
"ts",
53+
"html",
54+
"js",
55+
"json",
56+
],
57+
"moduleNameMapper": Object {
58+
"^app/(.*)$": "<rootDir>/src/app/$1",
59+
"^assets/(.*)$": "<rootDir>/src/assets/$1",
60+
"^environments/(.*)$": "<rootDir>/src/environments/$1",
61+
"^src/(.*)$": "<rootDir>/src/$1",
62+
},
63+
"snapshotSerializers": Array [
64+
"jest-preset-angular/build/serializers/html-comment",
65+
"jest-preset-angular/build/serializers/ng-snapshot",
66+
"jest-preset-angular/build/serializers/no-ng-attributes",
67+
],
68+
"testEnvironment": "jsdom",
69+
"transform": Object {
70+
"^.+\\\\.(ts|js|html)$": "jest-preset-angular",
71+
},
72+
}
73+
`;

src/__tests__/presets.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import presets from '../../presets';
2+
3+
describe('Presets', () => {
4+
test('should return the correct default preset value', () => {
5+
expect(presets.defaults).toMatchSnapshot('default-preset');
6+
});
7+
8+
test('should return the correct ESM preset value', () => {
9+
expect(presets.defaultsESM).toMatchSnapshot('esm-preset');
10+
});
11+
});

tsconfig.spec.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
{
22
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"allowSyntheticDefaultImports": true,
5+
"esModuleInterop": true
6+
}
37
}

0 commit comments

Comments
 (0)