Skip to content

Commit

Permalink
perf(config): set skipLibCheck: true if not defined in tsconfig (#678)
Browse files Browse the repository at this point in the history
BREAKING CHANGE
By default, `skipLibCheck` is `true` if not defined in tsconfig. If one wants to have it as `false`, one can define it explicitly in tsconfig
  • Loading branch information
ahnpnl committed Dec 18, 2020
1 parent 1a6b10e commit 0df3ce1
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 26 deletions.
43 changes: 39 additions & 4 deletions src/__tests__/__snapshots__/ng-jest-config.spec.ts.snap
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`NgJestConfig readTsConfig should return config including Angular compiler config with tsconfig as a string from ts-jest option 1`] = `
exports[`NgJestConfig _resolveTsConfig should return config including Angular compiler config with tsconfig as a string from ts-jest option 1`] = `
Object {
"annotationsAs": "decorators",
"declaration": false,
Expand Down Expand Up @@ -36,7 +36,7 @@ Object {
}
`;

exports[`NgJestConfig readTsConfig should return config including Angular compiler config with tsconfig as an object from ts-jest option 1`] = `
exports[`NgJestConfig _resolveTsConfig should return config including Angular compiler config with tsconfig as an object from ts-jest option 1`] = `
Object {
"annotationsAs": "decorators",
"declaration": false,
Expand All @@ -60,7 +60,6 @@ Object {
"noUnusedParameters": true,
"outDir": "",
"removeComments": false,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
Expand All @@ -73,7 +72,43 @@ Object {
}
`;

exports[`NgJestConfig readTsConfig should return config including Angular compiler config without tsconfig defined in ts-jest option 1`] = `
exports[`NgJestConfig _resolveTsConfig should return config including Angular compiler config with tsconfig as an object from ts-jest option 2`] = `
Object {
"annotationsAs": "decorators",
"declaration": false,
"enableIvy": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"importsNotUsedAsValues": 2,
"inlineSourceMap": false,
"inlineSources": true,
"lib": Array [
"lib.esnext.d.ts",
"lib.dom.d.ts",
],
"module": 1,
"noEmit": false,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "",
"removeComments": false,
"skipLibCheck": false,
"sourceMap": true,
"strict": true,
"suppressOutputPathCheck": true,
"target": 2,
"types": Array [
"node",
"jest",
],
}
`;

exports[`NgJestConfig _resolveTsConfig should return config including Angular compiler config without tsconfig defined in ts-jest option 1`] = `
Object {
"annotationsAs": "decorators",
"declaration": false,
Expand Down
50 changes: 28 additions & 22 deletions src/__tests__/ng-jest-config.spec.ts
Expand Up @@ -7,7 +7,7 @@ describe('NgJestConfig', () => {
const specifiedTsCfgPath = join(__dirname, '..', '..', 'tsconfig.spec.json');
const defaultTsCfgPath = join(__dirname, '..', '..', 'tsconfig.json');

describe('readTsConfig', () => {
describe('_resolveTsConfig', () => {
test('should return config including Angular compiler config with tsconfig as a string from ts-jest option', () => {
const ngJestConfig = new NgJestConfig({
testMatch: [],
Expand All @@ -30,30 +30,36 @@ describe('NgJestConfig', () => {
expect(config.options).toMatchSnapshot();
});

test('should return config including Angular compiler config with tsconfig as an object from ts-jest option', () => {
const ngJestConfig = new NgJestConfig({
cwd: '.',
testMatch: [],
testRegex: [],
extensionsToTreatAsEsm: [],
globals: {
'ts-jest': {
tsconfig: {
resolveJsonModule: true,
test.each([
{},
{
skipLibCheck: false,
},
])(
'should return config including Angular compiler config with tsconfig as an object from ts-jest option',
(tsconfig) => {
const ngJestConfig = new NgJestConfig({
cwd: '.',
testMatch: [],
testRegex: [],
extensionsToTreatAsEsm: [],
globals: {
'ts-jest': {
tsconfig,
},
},
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any);
const config = ngJestConfig.parsedTsConfig;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any);
const config = ngJestConfig.parsedTsConfig;

delete config.options.basePath;
delete config.options.baseUrl;
expect(config.options.configFilePath).toEqual(normalizeSeparators(defaultTsCfgPath));
delete config.options.configFilePath;
delete config.options.genDir;
expect(config.options).toMatchSnapshot();
});
delete config.options.basePath;
delete config.options.baseUrl;
expect(config.options.configFilePath).toEqual(normalizeSeparators(defaultTsCfgPath));
delete config.options.configFilePath;
delete config.options.genDir;
expect(config.options).toMatchSnapshot();
},
);

test('should return config including Angular compiler config without tsconfig defined in ts-jest option', () => {
const ngJestConfig = new NgJestConfig({
Expand Down
1 change: 1 addition & 0 deletions src/config/ng-jest-config.ts
Expand Up @@ -49,6 +49,7 @@ export class NgJestConfig extends ConfigSet {
// Overwrite outDir so we can find generated files next to their .ts origin in compilerHost.
outDir: '',
suppressOutputPathCheck: true,
skipLibCheck: result.options.skipLibCheck ?? true,
// For performance, disable AOT decorator downleveling transformer for applications in the CLI.
// The transformer is not needed for VE or Ivy in this plugin since Angular decorators are removed.
// While the transformer would make no changes, it would still need to walk each source file AST.
Expand Down

0 comments on commit 0df3ce1

Please sign in to comment.