Skip to content

Commit

Permalink
fix(config): set allowJs: true internally always (#976)
Browse files Browse the repository at this point in the history
Closes #974
  • Loading branch information
ahnpnl authored Jul 31, 2021
1 parent cf3874b commit 9900c8b
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 14 deletions.
3 changes: 1 addition & 2 deletions examples/example-app-v10/tsconfig-esm.spec.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "./tsconfig.spec.json",
"compilerOptions": {
"module": "ESNext",
"allowJs": true
"module": "ESNext"
}
}
3 changes: 1 addition & 2 deletions examples/example-app-v11/tsconfig-esm.spec.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "./tsconfig.spec.json",
"compilerOptions": {
"module": "ESNext",
"allowJs": true
"module": "ESNext"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "./tsconfig.spec.json",
"compilerOptions": {
"module": "ESNext",
"allowJs": true
"module": "ESNext"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "./tsconfig.spec.json",
"compilerOptions": {
"module": "ESNext",
"allowJs": true
"module": "ESNext"
}
}
3 changes: 1 addition & 2 deletions examples/example-app-v12/tsconfig-esm.spec.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "./tsconfig.spec.json",
"compilerOptions": {
"module": "ESNext",
"allowJs": true
"module": "ESNext"
}
}
3 changes: 1 addition & 2 deletions examples/example-app-v9/tsconfig-esm.spec.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "./tsconfig.spec.json",
"compilerOptions": {
"module": "ESNext",
"allowJs": true
"module": "ESNext"
}
}
15 changes: 15 additions & 0 deletions src/__tests__/ng-jest-config.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { NgJestConfig } from '../config/ng-jest-config';

describe('NgJestConfig', () => {
test('should override some compiler options', () => {
const compilerOptions = new NgJestConfig(Object.create(null)).parsedTsConfig.options;

expect(compilerOptions.enableIvy).toBe(true);
expect(compilerOptions.noEmitOnError).toBe(false);
expect(compilerOptions.suppressOutputPathCheck).toBe(true);
expect(compilerOptions.allowEmptyCodegenFiles).toBe(false);
expect(compilerOptions.annotationsAs).toBe('decorators');
expect(compilerOptions.enableResourceInlining).toBe(false);
expect(compilerOptions.allowJs).toBe(true);
});
});
2 changes: 2 additions & 0 deletions src/__tests__/ng-jest-transformer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NgJestCompiler } from '../compiler/ng-jest-compiler';
import { NgJestConfig } from '../config/ng-jest-config';
import { NgJestTransformer } from '../ng-jest-transformer';

describe('NgJestTransformer', () => {
Expand All @@ -18,6 +19,7 @@ describe('NgJestTransformer', () => {

// @ts-expect-error testing purpose
expect(tr._compiler).toBeInstanceOf(NgJestCompiler);
expect(cs).toBeInstanceOf(NgJestConfig);
});
});
});
22 changes: 22 additions & 0 deletions src/config/ng-jest-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ConfigSet } from 'ts-jest/dist/config/config-set';
import type { RawCompilerOptions } from 'ts-jest/dist/raw-compiler-options';
import type { ParsedCommandLine } from 'typescript';

export class NgJestConfig extends ConfigSet {
/**
* Override `ts-jest` behavior because we use `readConfiguration` which will read and resolve tsconfig.
*/
protected _resolveTsConfig(compilerOptions?: RawCompilerOptions, resolvedConfigFile?: string): ParsedCommandLine {
const result = super._resolveTsConfig(compilerOptions, resolvedConfigFile);
result.options.enableIvy = true;
result.options.noEmitOnError = false;
result.options.suppressOutputPathCheck = true;
result.options.allowEmptyCodegenFiles = false;
result.options.annotationsAs = 'decorators';
result.options.enableResourceInlining = false;
// Since we define preset default also transform `js` so we need to set `allowJs` true
result.options.allowJs = true;

return result as ParsedCommandLine;
}
}
6 changes: 6 additions & 0 deletions src/ng-jest-transformer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { ConfigSet } from 'ts-jest/dist/config/config-set';
import { TsJestTransformer } from 'ts-jest/dist/ts-jest-transformer';
import type { ProjectConfigTsJest } from 'ts-jest/dist/types';

import { NgJestCompiler } from './compiler/ng-jest-compiler';
import { NgJestConfig } from './config/ng-jest-config';

export class NgJestTransformer extends TsJestTransformer {
protected _createConfigSet(config: ProjectConfigTsJest | undefined): ConfigSet {
return new NgJestConfig(config);
}

protected _createCompiler(configSet: ConfigSet, cacheFS: Map<string, string>): void {
this._compiler = new NgJestCompiler(configSet, cacheFS);
}
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"allowJs": true
"esModuleInterop": true
}
}

0 comments on commit 9900c8b

Please sign in to comment.