Skip to content

Commit

Permalink
feat: add support for zone.js 0.11.1 (#448)
Browse files Browse the repository at this point in the history
zone.js 0.11.1 support jest, so all logic of `zone-patch` are no longer needed,
also zone.js 0.11.1 change the `dist` bundles to `Angular Package Format`, so the
current `require` absolute path will not work any longer.

So this PR make the following changes.
1. Add logic in `setup-jest.ts`, to load `zone.js` and `zone.js/testing` moudles,
if the jest patch is already available which means zone.js is 0.11.1+, we don't need to
import zone.js module and patch ourselves. If the jest patch is not available, we
still need to use the current logic as fallback.
2. Add e2e test for Angular 10 with zone.js 0.11.1
  • Loading branch information
JiaLiPassion authored Aug 23, 2020
1 parent d499303 commit 3879976
Show file tree
Hide file tree
Showing 31 changed files with 11,056 additions and 10 deletions.
4 changes: 1 addition & 3 deletions e2e/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# E2E tests


## Directory structure

- `test-app-v10-zone-v11`: test app using Angular v10 and zone.js v0.11.1 with basic setup with `jest` and `jest-preset-angular`.
- `test-app-v10`: test app using Angular v10 with basic setup with `jest` and `jest-preset-angular`.
- `test-app-v9`: test app using Angular v9 with basic setup with `jest` and `jest-preset-angular`.


## Running tests

You run the tests on test apps with `yarn test:e2e` (or `npm run test:e2e)`. In `scripts/lib/paths.js`,
Expand All @@ -17,7 +16,6 @@ What will happen in order is as following:
1. Each test project will install its dependencies
2. Each test suite in each test project runs according to `jest` config of that project.


## Why

E2E tests being in a temporary folder of the operating system ensure none of the parents would be containing `node_modules`.
Expand Down
18 changes: 18 additions & 0 deletions e2e/test-app-v10-zone-v11/.browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries

# For the full list of supported browsers by the Angular framework, please see:
# https://angular.io/guide/browser-support

# You can see what browsers were selected by your queries by running:
# npx browserslist

last 1 Chrome version
last 1 Firefox version
last 2 Edge major versions
last 2 Safari major versions
last 2 iOS major versions
Firefox ESR
not IE 9-10 # Angular support for IE 9-10 has been deprecated and will be removed as of Angular v11. To opt-in, remove the 'not' prefix on this line.
not IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line.
16 changes: 16 additions & 0 deletions e2e/test-app-v10-zone-v11/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Editor configuration, see https://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.ts]
quote_type = single

[*.md]
max_line_length = off
trim_trailing_whitespace = false
46 changes: 46 additions & 0 deletions e2e/test-app-v10-zone-v11/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist
/tmp
/out-tsc
# Only exists if Bazel was run
/bazel-out

# dependencies
/node_modules

# profiling files
chrome-profiler-events*.json
speed-measure-plugin*.json

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history/*

# misc
/.sass-cache
/connect.lock
/coverage
/libpeerconnection.log
npm-debug.log
yarn-error.log
testem.log
/typings

# System Files
.DS_Store
Thumbs.db
27 changes: 27 additions & 0 deletions e2e/test-app-v10-zone-v11/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# TestAppV10

This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 10.0.2.

## Development server

Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.

## Code scaffolding

Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.

## Build

Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.

## Running unit tests

Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).

## Running end-to-end tests

Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).

## Further help

To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
98 changes: 98 additions & 0 deletions e2e/test-app-v10-zone-v11/angular.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"test-app-v10": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "scss"
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/test-app-v10",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": true,
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "test-app-v10:build"
},
"configurations": {
"production": {
"browserTarget": "test-app-v10:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "test-app-v10:build"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.app.json",
"tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
}},
"defaultProject": "test-app-v10"
}
24 changes: 24 additions & 0 deletions e2e/test-app-v10-zone-v11/jest-global-mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Object.defineProperty(window, 'CSS', {value: null});
Object.defineProperty(document, 'doctype', {
value: '<!DOCTYPE html>'
});
Object.defineProperty(window, 'getComputedStyle', {
value: () => {
return {
display: 'none',
appearance: ['-webkit-appearance']
};
}
});
/**
* ISSUE: https://github.com/angular/material2/issues/7101
* Workaround for JSDOM missing transform property
*/
Object.defineProperty(document.body.style, 'transform', {
value: () => {
return {
enumerable: true,
configurable: true,
};
},
});
7 changes: 7 additions & 0 deletions e2e/test-app-v10-zone-v11/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
preset: 'jest-preset-angular',
setupFilesAfterEnv: [
'<rootDir>/setup-jest.ts',
],
};
38 changes: 38 additions & 0 deletions e2e/test-app-v10-zone-v11/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "test-app-v10-zone-v11",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "jest",
"lint": "ng lint"
},
"private": true,
"dependencies": {
"@angular/animations": "~10.0.8",
"@angular/common": "~10.0.8",
"@angular/compiler": "~10.0.8",
"@angular/core": "~10.0.8",
"@angular/forms": "~10.0.8",
"@angular/platform-browser": "~10.0.8",
"@angular/platform-browser-dynamic": "~10.0.8",
"@angular/router": "~10.0.8",
"rxjs": "~6.6.2",
"tslib": "^2.0.1",
"zone.js": "~0.11.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.1000.5",
"@angular/cli": "~10.0.5",
"@angular/compiler-cli": "~10.0.8",
"@types/jest": "^26.0.9",
"@types/node": "^12.12.54",
"codelyzer": "^6.0.0",
"jest": "^26.3.0",
"jest-preset-angular": "file:../../src",
"ts-node": "~8.10.2",
"tslint": "~6.1.3",
"typescript": "~3.9.7"
}
}
2 changes: 2 additions & 0 deletions e2e/test-app-v10-zone-v11/setup-jest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import 'jest-preset-angular';
import './jest-global-mocks';
Loading

0 comments on commit 3879976

Please sign in to comment.