Skip to content

Commit

Permalink
feat(config): remove hardcoded logic setting target to ES2015
Browse files Browse the repository at this point in the history
  • Loading branch information
anh.pham committed Sep 25, 2022
1 parent da0ad0a commit 188d3b1
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 25 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ Adjust your `tsconfig.spec.json` to be:
}
```

**IMPORTANT**

Angular doesn't support native `async/await` with `target` higher than `ES2015`, see https://github.com/angular/components/issues/21632#issuecomment-764975917

## Migration from Angular < 13

Check out our [Migration from Angular < 13 guidance](https://thymikee.github.io/jest-preset-angular/docs/guides/angular-13+)
Expand Down
71 changes: 71 additions & 0 deletions e2e/__tests__/__snapshots__/async.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`fail the tests inside async with isolatedModules: false 1`] = `
[
" ● ButtonPageComponent › should create
Expected to be running in 'ProxyZone', but it was not found.
42 | }).compileComponents();
43 | fixture = TestBed.createComponent(ButtonPageComponent);
> 44 | loader = TestbedHarnessEnvironment.loader(fixture);
| ^
45 | });
46 |
47 | beforeEach(() => {
at Function.Object.<anonymous>.ProxyZoneSpec.assertPresent (../../node_modules/zone.js/bundles/zone-testing-bundle.umd.js:3744:23)
at __tests__/async.spec.ts:44:40
● ButtonPageComponent › should click
Expected to be running in 'ProxyZone', but it was not found.
42 | }).compileComponents();
43 | fixture = TestBed.createComponent(ButtonPageComponent);
> 44 | loader = TestbedHarnessEnvironment.loader(fixture);
| ^
45 | });
46 |
47 | beforeEach(() => {
at Function.Object.<anonymous>.ProxyZoneSpec.assertPresent (../../node_modules/zone.js/bundles/zone-testing-bundle.umd.js:3744:23)
at __tests__/async.spec.ts:44:40
",
]
`;
exports[`fail the tests inside async with isolatedModules: true 1`] = `
[
" ● ButtonPageComponent › should create
Expected to be running in 'ProxyZone', but it was not found.
42 | }).compileComponents();
43 | fixture = TestBed.createComponent(ButtonPageComponent);
> 44 | loader = TestbedHarnessEnvironment.loader(fixture);
| ^
45 | });
46 |
47 | beforeEach(() => {
at Function.Object.<anonymous>.ProxyZoneSpec.assertPresent (../../node_modules/zone.js/bundles/zone-testing-bundle.umd.js:3744:23)
at __tests__/async.spec.ts:44:40
● ButtonPageComponent › should click
Expected to be running in 'ProxyZone', but it was not found.
42 | }).compileComponents();
43 | fixture = TestBed.createComponent(ButtonPageComponent);
> 44 | loader = TestbedHarnessEnvironment.loader(fixture);
| ^
45 | });
46 |
47 | beforeEach(() => {
at Function.Object.<anonymous>.ProxyZoneSpec.assertPresent (../../node_modules/zone.js/bundles/zone-testing-bundle.umd.js:3744:23)
at __tests__/async.spec.ts:44:40
",
]
`;
8 changes: 4 additions & 4 deletions e2e/__tests__/async.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ beforeAll(() => {
runYarnInstall(path.join(__dirname, '..', DIR));
});

test(`successfully run the tests inside ${DIR} with isolatedModules: false`, () => {
test(`fail the tests inside ${DIR} with isolatedModules: false`, () => {
const { json } = runWithJsonNoCache(DIR);

expect(json.success).toBe(true);
expect(json.testResults.map((testResult) => testResult.message)).toMatchSnapshot();
});

test(`successfully run the tests inside ${DIR} with isolatedModules: true`, () => {
test(`fail the tests inside ${DIR} with isolatedModules: true`, () => {
const { json } = runWithJsonNoCache(DIR, ['-c=jest-isolated.config.js']);

expect(json.success).toBe(true);
expect(json.testResults.map((testResult) => testResult.message)).toMatchSnapshot();
});
15 changes: 0 additions & 15 deletions src/config/ng-jest-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,4 @@ describe('NgJestConfig', () => {
expect(compilerOptions.allowJs).toBe(true);
expect(compilerOptions.target).toBe(ScriptTarget.ES2015);
});

test('should set typescript target to ES2015 if user is using target higher than ES2016', () => {
expect(
new NgJestConfig({
globals: {
'ts-jest': {
tsconfig: {
target: 'ES2017',
},
},
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any).parsedTsConfig.options.target,
).toBe(ScriptTarget.ES2015);
});
});
6 changes: 0 additions & 6 deletions src/config/ng-jest-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ export class NgJestConfig extends ConfigSet {
result.options.enableResourceInlining = false;
// Since we define preset default also transform `js` so we need to set `allowJs` true
result.options.allowJs = true;
const ts = this.compilerModule;
const scriptTarget = result.options.target ?? ts.ScriptTarget?.ES2015;
if (scriptTarget > ts.ScriptTarget?.ES2016) {
// See https://github.com/angular/components/issues/21632#issuecomment-764975917
result.options.target = ts.ScriptTarget?.ES2015;
}

return result;
}
Expand Down
6 changes: 6 additions & 0 deletions website/docs/getting-started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ Adjust your `tsconfig.spec.json` to be:
}
```

:::important

Angular doesn't support native `async/await` with `target` higher than `ES2015`, see https://github.com/angular/components/issues/21632#issuecomment-764975917

:::

### Customizing

#### Global mocks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ Adjust your `tsconfig.spec.json` to be:
}
```

:::important

Angular doesn't support native `async/await` with `target` higher than `ES2015`, see https://github.com/angular/components/issues/21632#issuecomment-764975917

:::

### Customizing

#### Global mocks
Expand Down

0 comments on commit 188d3b1

Please sign in to comment.