Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(presets): add type definition for presets entry point #801

Merged
merged 1 commit into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions presets/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { TsJestPresets } from 'ts-jest/dist/types';

declare const _default: {
defaults: TsJestPresets;
defaultsESM: TsJestPresets;
};
export = _default;
38 changes: 17 additions & 21 deletions presets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,22 @@ const basePreset = {
}

module.exports = {
get defaults() {
return basePreset;
},
get defaultsESM() {
return {
...basePreset,
extensionsToTreatAsEsm: ['.ts'],
globals: {
'ts-jest': {
...basePreset.globals['ts-jest'],
useESM: true,
},
},
moduleNameMapper: {
...basePreset.moduleNameMapper,
'tslib': '<rootDir>/node_modules/tslib/tslib.es6.js',
defaults: basePreset,
defaultsESM: {
...basePreset,
extensionsToTreatAsEsm: ['.ts'],
globals: {
'ts-jest': {
...basePreset.globals['ts-jest'],
useESM: true,
},
transformIgnorePatterns: [
'node_modules/(?!tslib)',
],
}
},
},
moduleNameMapper: {
...basePreset.moduleNameMapper,
'tslib': '<rootDir>/node_modules/tslib/tslib.es6.js',
},
transformIgnorePatterns: [
'node_modules/(?!tslib)',
],
}
}
1 change: 1 addition & 0 deletions src/__tests__/__snapshots__/ng-jest-config.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

exports[`NgJestConfig _resolveTsConfig should return config including Angular compiler config with tsconfig as a string from ts-jest option 1`] = `
Object {
"allowSyntheticDefaultImports": true,
"annotationsAs": "decorators",
"declaration": false,
"enableIvy": true,
Expand Down
73 changes: 73 additions & 0 deletions src/__tests__/__snapshots__/presets.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Presets should return the correct ESM preset value: esm-preset 1`] = `
Object {
"extensionsToTreatAsEsm": Array [
".ts",
],
"globals": Object {
"ts-jest": Object {
"stringifyContentPathRegex": "\\\\.html$",
"tsconfig": "<rootDir>/tsconfig.spec.json",
"useESM": true,
},
},
"moduleFileExtensions": Array [
"ts",
"html",
"js",
"json",
],
"moduleNameMapper": Object {
"^app/(.*)$": "<rootDir>/src/app/$1",
"^assets/(.*)$": "<rootDir>/src/assets/$1",
"^environments/(.*)$": "<rootDir>/src/environments/$1",
"^src/(.*)$": "<rootDir>/src/$1",
"tslib": "<rootDir>/node_modules/tslib/tslib.es6.js",
},
"snapshotSerializers": Array [
"jest-preset-angular/build/serializers/html-comment",
"jest-preset-angular/build/serializers/ng-snapshot",
"jest-preset-angular/build/serializers/no-ng-attributes",
],
"testEnvironment": "jsdom",
"transform": Object {
"^.+\\\\.(ts|js|html)$": "jest-preset-angular",
},
"transformIgnorePatterns": Array [
"node_modules/(?!tslib)",
],
}
`;

exports[`Presets should return the correct default preset value: default-preset 1`] = `
Object {
"globals": Object {
"ts-jest": Object {
"stringifyContentPathRegex": "\\\\.html$",
"tsconfig": "<rootDir>/tsconfig.spec.json",
},
},
"moduleFileExtensions": Array [
"ts",
"html",
"js",
"json",
],
"moduleNameMapper": Object {
"^app/(.*)$": "<rootDir>/src/app/$1",
"^assets/(.*)$": "<rootDir>/src/assets/$1",
"^environments/(.*)$": "<rootDir>/src/environments/$1",
"^src/(.*)$": "<rootDir>/src/$1",
},
"snapshotSerializers": Array [
"jest-preset-angular/build/serializers/html-comment",
"jest-preset-angular/build/serializers/ng-snapshot",
"jest-preset-angular/build/serializers/no-ng-attributes",
],
"testEnvironment": "jsdom",
"transform": Object {
"^.+\\\\.(ts|js|html)$": "jest-preset-angular",
},
}
`;
11 changes: 11 additions & 0 deletions src/__tests__/presets.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import presets from '../../presets';

describe('Presets', () => {
test('should return the correct default preset value', () => {
expect(presets.defaults).toMatchSnapshot('default-preset');
});

test('should return the correct ESM preset value', () => {
expect(presets.defaultsESM).toMatchSnapshot('esm-preset');
});
});
4 changes: 4 additions & 0 deletions tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
}
}