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

test: add example test about using Babel to transform async/await #2036

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions examples/example-app-v15/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = function (api) {
api.cache(true);

const presets = ['@babel/preset-env'];
const plugins = ['@babel/plugin-transform-async-to-generator', '@babel/plugin-proposal-async-generator-functions'];

return {
presets,
plugins,
};
};
1 change: 1 addition & 0 deletions examples/example-app-v15/jest-esm.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const jestConfig = {
tsconfig: '<rootDir>/tsconfig-esm.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$',
useESM: true,
babelConfig: true,
},
],
},
Expand Down
5 changes: 5 additions & 0 deletions examples/example-app-v15/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@
"@angular-devkit/build-angular": "^15.2.4",
"@angular/cli": "^15.2.4",
"@angular/compiler-cli": "^15.2.4",
"@babel/core": "^7.21.3",
"@babel/plugin-proposal-async-generator-functions": "^7.20.7",
"@babel/plugin-transform-async-to-generator": "^7.20.7",
"@babel/preset-env": "^7.20.2",
"@types/jest": "^29.5.0",
"@types/node": "^16.18.21",
"babel-jest": "^29.5.0",
"jest": "^29.5.0",
"jest-preset-angular": "^13.0.1",
"typescript": "^4.8.4"
Expand Down
17 changes: 15 additions & 2 deletions examples/example-app-v15/src/app/app.component.router.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Location } from '@angular/common';
import { SpyLocation } from '@angular/common/testing';
import { DebugElement } from '@angular/core';
import { waitForAsync, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { Router, RouterLinkWithHref } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { jest } from '@jest/globals';
import { jest, expect } from '@jest/globals';
import { of } from 'rxjs';

import { click } from '../testing';
Expand Down Expand Up @@ -33,6 +33,19 @@ describe('AppComponent & RouterTestingModule', () => {
}).compileComponents();
}));

it('should throw an error', async () => {
expect.assertions(1);
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;

try {
await app.testFunction();
} catch (e) {
// eslint-disable-next-line jest/no-conditional-expect
expect(true).toEqual(true);
}
});

it('should navigate to "Dashboard" immediately', fakeAsync(() => {
createComponent();
tick();
Expand Down
14 changes: 13 additions & 1 deletion examples/example-app-v15/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import { Component } from '@angular/core';
import { firstValueFrom, of } from 'rxjs';
import { map } from 'rxjs/operators';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
})
export class AppComponent {}
export class AppComponent {
async testFunction() {
await firstValueFrom(
of('').pipe(
map(() => {
throw 'error';
}),
),
);
}
}
3 changes: 2 additions & 1 deletion examples/example-app-v15/tsconfig-esm.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"esModuleInterop": true,
"module": "ES2020"
"module": "ES2020",
"target": "ES2020"
},
"include": [
"src/**/*.spec.ts",
Expand Down
142 changes: 137 additions & 5 deletions examples/example-app-v15/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ __metadata:
version: 6
cacheKey: 8

"@ampproject/remapping@npm:2.2.0, @ampproject/remapping@npm:^2.1.0":
"@ampproject/remapping@npm:2.2.0, @ampproject/remapping@npm:^2.1.0, @ampproject/remapping@npm:^2.2.0":
version: 2.2.0
resolution: "@ampproject/remapping@npm:2.2.0"
dependencies:
Expand Down Expand Up @@ -395,6 +395,29 @@ __metadata:
languageName: node
linkType: hard

"@babel/core@npm:^7.21.3":
version: 7.21.3
resolution: "@babel/core@npm:7.21.3"
dependencies:
"@ampproject/remapping": ^2.2.0
"@babel/code-frame": ^7.18.6
"@babel/generator": ^7.21.3
"@babel/helper-compilation-targets": ^7.20.7
"@babel/helper-module-transforms": ^7.21.2
"@babel/helpers": ^7.21.0
"@babel/parser": ^7.21.3
"@babel/template": ^7.20.7
"@babel/traverse": ^7.21.3
"@babel/types": ^7.21.3
convert-source-map: ^1.7.0
debug: ^4.1.0
gensync: ^1.0.0-beta.2
json5: ^2.2.2
semver: ^6.3.0
checksum: bef25fbea96f461bf79bd1d0e4f0cdce679fd5ada464a89c1141ddba59ae1adfdbb23e04440c266ed525712d33d5ffd818cd8b0c25b1dee0e648d5559516153a
languageName: node
linkType: hard

"@babel/generator@npm:7.20.14, @babel/generator@npm:^7.19.3, @babel/generator@npm:^7.20.7, @babel/generator@npm:^7.7.2":
version: 7.20.14
resolution: "@babel/generator@npm:7.20.14"
Expand All @@ -406,6 +429,18 @@ __metadata:
languageName: node
linkType: hard

"@babel/generator@npm:^7.21.3":
version: 7.21.3
resolution: "@babel/generator@npm:7.21.3"
dependencies:
"@babel/types": ^7.21.3
"@jridgewell/gen-mapping": ^0.3.2
"@jridgewell/trace-mapping": ^0.3.17
jsesc: ^2.5.1
checksum: be6bb5a32a0273260b91210d4137b7b5da148a2db8dd324654275cb0af865ae59de5e1536e93ac83423b2586415059e1c24cf94293026755cf995757238da749
languageName: node
linkType: hard

"@babel/helper-annotate-as-pure@npm:7.18.6, @babel/helper-annotate-as-pure@npm:^7.18.6":
version: 7.18.6
resolution: "@babel/helper-annotate-as-pure@npm:7.18.6"
Expand Down Expand Up @@ -511,6 +546,16 @@ __metadata:
languageName: node
linkType: hard

"@babel/helper-function-name@npm:^7.21.0":
version: 7.21.0
resolution: "@babel/helper-function-name@npm:7.21.0"
dependencies:
"@babel/template": ^7.20.7
"@babel/types": ^7.21.0
checksum: d63e63c3e0e3e8b3138fa47b0cd321148a300ef12b8ee951196994dcd2a492cc708aeda94c2c53759a5c9177fffaac0fd8778791286746f72a000976968daf4e
languageName: node
linkType: hard

"@babel/helper-hoist-variables@npm:^7.18.6":
version: 7.18.6
resolution: "@babel/helper-hoist-variables@npm:7.18.6"
Expand Down Expand Up @@ -554,6 +599,22 @@ __metadata:
languageName: node
linkType: hard

"@babel/helper-module-transforms@npm:^7.21.2":
version: 7.21.2
resolution: "@babel/helper-module-transforms@npm:7.21.2"
dependencies:
"@babel/helper-environment-visitor": ^7.18.9
"@babel/helper-module-imports": ^7.18.6
"@babel/helper-simple-access": ^7.20.2
"@babel/helper-split-export-declaration": ^7.18.6
"@babel/helper-validator-identifier": ^7.19.1
"@babel/template": ^7.20.7
"@babel/traverse": ^7.21.2
"@babel/types": ^7.21.2
checksum: 8a1c129a4f90bdf97d8b6e7861732c9580f48f877aaaafbc376ce2482febebcb8daaa1de8bc91676d12886487603f8c62a44f9e90ee76d6cac7f9225b26a49e1
languageName: node
linkType: hard

"@babel/helper-optimise-call-expression@npm:^7.18.6":
version: 7.18.6
resolution: "@babel/helper-optimise-call-expression@npm:7.18.6"
Expand Down Expand Up @@ -668,6 +729,17 @@ __metadata:
languageName: node
linkType: hard

"@babel/helpers@npm:^7.21.0":
version: 7.21.0
resolution: "@babel/helpers@npm:7.21.0"
dependencies:
"@babel/template": ^7.20.7
"@babel/traverse": ^7.21.0
"@babel/types": ^7.21.0
checksum: 9370dad2bb665c551869a08ac87c8bdafad53dbcdce1f5c5d498f51811456a3c005d9857562715151a0f00b2e912ac8d89f56574f837b5689f5f5072221cdf54
languageName: node
linkType: hard

"@babel/highlight@npm:^7.18.6":
version: 7.18.6
resolution: "@babel/highlight@npm:7.18.6"
Expand All @@ -688,6 +760,15 @@ __metadata:
languageName: node
linkType: hard

"@babel/parser@npm:^7.21.3":
version: 7.21.3
resolution: "@babel/parser@npm:7.21.3"
bin:
parser: ./bin/babel-parser.js
checksum: a71e6456a1260c2a943736b56cc0acdf5f2a53c6c79e545f56618967e51f9b710d1d3359264e7c979313a7153741b1d95ad8860834cc2ab4ce4f428b13cc07be
languageName: node
linkType: hard

"@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression@npm:^7.18.6":
version: 7.18.6
resolution: "@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression@npm:7.18.6"
Expand All @@ -712,7 +793,7 @@ __metadata:
languageName: node
linkType: hard

"@babel/plugin-proposal-async-generator-functions@npm:7.20.7, @babel/plugin-proposal-async-generator-functions@npm:^7.20.1":
"@babel/plugin-proposal-async-generator-functions@npm:7.20.7, @babel/plugin-proposal-async-generator-functions@npm:^7.20.1, @babel/plugin-proposal-async-generator-functions@npm:^7.20.7":
version: 7.20.7
resolution: "@babel/plugin-proposal-async-generator-functions@npm:7.20.7"
dependencies:
Expand Down Expand Up @@ -1121,7 +1202,7 @@ __metadata:
languageName: node
linkType: hard

"@babel/plugin-transform-async-to-generator@npm:7.20.7, @babel/plugin-transform-async-to-generator@npm:^7.18.6":
"@babel/plugin-transform-async-to-generator@npm:7.20.7, @babel/plugin-transform-async-to-generator@npm:^7.18.6, @babel/plugin-transform-async-to-generator@npm:^7.20.7":
version: 7.20.7
resolution: "@babel/plugin-transform-async-to-generator@npm:7.20.7"
dependencies:
Expand Down Expand Up @@ -1504,7 +1585,7 @@ __metadata:
languageName: node
linkType: hard

"@babel/preset-env@npm:7.20.2":
"@babel/preset-env@npm:7.20.2, @babel/preset-env@npm:^7.20.2":
version: 7.20.2
resolution: "@babel/preset-env@npm:7.20.2"
dependencies:
Expand Down Expand Up @@ -1642,6 +1723,24 @@ __metadata:
languageName: node
linkType: hard

"@babel/traverse@npm:^7.21.0, @babel/traverse@npm:^7.21.2, @babel/traverse@npm:^7.21.3":
version: 7.21.3
resolution: "@babel/traverse@npm:7.21.3"
dependencies:
"@babel/code-frame": ^7.18.6
"@babel/generator": ^7.21.3
"@babel/helper-environment-visitor": ^7.18.9
"@babel/helper-function-name": ^7.21.0
"@babel/helper-hoist-variables": ^7.18.6
"@babel/helper-split-export-declaration": ^7.18.6
"@babel/parser": ^7.21.3
"@babel/types": ^7.21.3
debug: ^4.1.0
globals: ^11.1.0
checksum: 0af5bcd47a2fc501592b90ac1feae9d449afb9ab0772a4f6e68230f4cd3a475795d538c1de3f880fe3414b6c2820bac84d02c6549eea796f39d74a603717447b
languageName: node
linkType: hard

"@babel/types@npm:^7.0.0, @babel/types@npm:^7.18.6, @babel/types@npm:^7.18.9, @babel/types@npm:^7.19.0, @babel/types@npm:^7.19.3, @babel/types@npm:^7.20.2, @babel/types@npm:^7.20.7, @babel/types@npm:^7.3.0, @babel/types@npm:^7.3.3, @babel/types@npm:^7.4.4, @babel/types@npm:^7.8.3":
version: 7.20.7
resolution: "@babel/types@npm:7.20.7"
Expand All @@ -1653,6 +1752,17 @@ __metadata:
languageName: node
linkType: hard

"@babel/types@npm:^7.21.0, @babel/types@npm:^7.21.2, @babel/types@npm:^7.21.3":
version: 7.21.3
resolution: "@babel/types@npm:7.21.3"
dependencies:
"@babel/helper-string-parser": ^7.19.4
"@babel/helper-validator-identifier": ^7.19.1
to-fast-properties: ^2.0.0
checksum: b750274718ba9cefd0b81836c464009bb6ba339fccce51b9baff497a0a2d96c044c61dc90cf203cec0adc770454b53a9681c3f7716883c802b85ab84c365ba35
languageName: node
linkType: hard

"@bcoe/v8-coverage@npm:^0.2.3":
version: 0.2.3
resolution: "@bcoe/v8-coverage@npm:0.2.3"
Expand Down Expand Up @@ -2099,6 +2209,13 @@ __metadata:
languageName: node
linkType: hard

"@jridgewell/resolve-uri@npm:3.1.0":
version: 3.1.0
resolution: "@jridgewell/resolve-uri@npm:3.1.0"
checksum: b5ceaaf9a110fcb2780d1d8f8d4a0bfd216702f31c988d8042e5f8fbe353c55d9b0f55a1733afdc64806f8e79c485d2464680ac48a0d9fcadb9548ee6b81d267
languageName: node
linkType: hard

"@jridgewell/resolve-uri@npm:^3.0.3":
version: 3.0.6
resolution: "@jridgewell/resolve-uri@npm:3.0.6"
Expand All @@ -2123,7 +2240,7 @@ __metadata:
languageName: node
linkType: hard

"@jridgewell/sourcemap-codec@npm:^1.4.10, @jridgewell/sourcemap-codec@npm:^1.4.13, @jridgewell/sourcemap-codec@npm:^1.4.14":
"@jridgewell/sourcemap-codec@npm:1.4.14, @jridgewell/sourcemap-codec@npm:^1.4.10, @jridgewell/sourcemap-codec@npm:^1.4.13, @jridgewell/sourcemap-codec@npm:^1.4.14":
version: 1.4.14
resolution: "@jridgewell/sourcemap-codec@npm:1.4.14"
checksum: 61100637b6d173d3ba786a5dff019e1a74b1f394f323c1fee337ff390239f053b87266c7a948777f4b1ee68c01a8ad0ab61e5ff4abb5a012a0b091bec391ab97
Expand All @@ -2140,6 +2257,16 @@ __metadata:
languageName: node
linkType: hard

"@jridgewell/trace-mapping@npm:^0.3.17":
version: 0.3.17
resolution: "@jridgewell/trace-mapping@npm:0.3.17"
dependencies:
"@jridgewell/resolve-uri": 3.1.0
"@jridgewell/sourcemap-codec": 1.4.14
checksum: 9d703b859cff5cd83b7308fd457a431387db5db96bd781a63bf48e183418dd9d3d44e76b9e4ae13237f6abeeb25d739ec9215c1d5bfdd08f66f750a50074a339
languageName: node
linkType: hard

"@leichtgewicht/ip-codec@npm:^2.0.1":
version: 2.0.4
resolution: "@leichtgewicht/ip-codec@npm:2.0.4"
Expand Down Expand Up @@ -4544,9 +4671,14 @@ __metadata:
"@angular/platform-browser": ^15.2.4
"@angular/platform-browser-dynamic": ^15.2.4
"@angular/router": ^15.2.4
"@babel/core": ^7.21.3
"@babel/plugin-proposal-async-generator-functions": ^7.20.7
"@babel/plugin-transform-async-to-generator": ^7.20.7
"@babel/preset-env": ^7.20.2
"@types/jest": ^29.5.0
"@types/node": ^16.18.21
angular-in-memory-web-api: ^0.15.0
babel-jest: ^29.5.0
jest: ^29.5.0
jest-preset-angular: ^13.0.1
rxjs: ^7.8.0
Expand Down