Skip to content

Commit

Permalink
Angular 10 support (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
hmil committed Oct 10, 2020
1 parent 6dd4e7f commit 9b9a5bd
Show file tree
Hide file tree
Showing 43 changed files with 10,099 additions and 5 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -3,6 +3,7 @@ node_js:
- 12
script:
- yarn build
- cd "${TRAVIS_BUILD_DIR}/test/ng10" && yarn && yarn test:ci
- cd "${TRAVIS_BUILD_DIR}/test/ng9" && yarn && yarn test:ci
- cd "${TRAVIS_BUILD_DIR}/test/ng8" && yarn && yarn test:ci
- cd "${TRAVIS_BUILD_DIR}/test/ng7" && yarn && yarn test:ci
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -5,7 +5,7 @@ _Angular tests in a vacuum._
[![Build Status](https://travis-ci.org/hmil/ng-vacuum.svg?branch=master)](https://travis-ci.org/hmil/ng-vacuum)
[![Latest version](https://code.hmil.fr/ng-vacuum/img/version-badge.svg)](https://www.npmjs.com/package/ng-vacuum)

✅ Compatible with angular **7**, **8** and **9**.
✅ Compatible with angular **7**, **8**, **9** and **10**.

📖 [**Documentation**](https://code.hmil.fr/ng-vacuum)

Expand Down
4 changes: 2 additions & 2 deletions docs/docs/api-reference.md
Expand Up @@ -39,7 +39,7 @@ const dependencyService = getMock(MyServiceDependency);
when(dependencyService.greet('John')).return('Hello John').once();
```

### `renderComponent<T>(component: Type<T>, module: Type<any> | ModuleWithProviders): Promise<Rendering<T, never>>`
### `renderComponent<T>(component: Type<T>, module: Type<any> | ModuleWithProviders<any>): Promise<Rendering<T, never>>`

Shallow-renders a component, meaning that its children components are not rendered themselves, and any constructor dependency is mocked.

Expand All @@ -58,7 +58,7 @@ Any subsequent call to `getMock` with the same injection token will return the s
TODO: example


### `getShallow<T>(component: Type<T>, module: Type<any> | ModuleWithProviders): Shallow<T>`
### `getShallow<T>(component: Type<T>, module: Type<any> | ModuleWithProviders<any>): Shallow<T>`

Configures and return a [Shallow renderer](https://getsaf.github.io/shallow-render/#shallow-class).

Expand Down
8 changes: 8 additions & 0 deletions docs/docs/setup.md
Expand Up @@ -13,6 +13,14 @@ NgVacuum is officially compatible with angular 7, 8 and 9.

NgVacuum uses [OmniMock](https://github.com/hmil/omnimock) and [shallow-render](https://github.com/getsaf/shallow-render) to mock service and component dependencies. You must install all three packages separately.

## Angular 10

Use shallow-render version 10.

```
yarn add -D ng-vacuum shallow-render@10 omnimock
```

## Angular 9

Use shallow-render version 9.
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Expand Up @@ -91,7 +91,7 @@ export function getService<T>(testService: Type<T>): T {
return TestBed.get(testService);
}

export function getShallow<T>(testComponent: Type<T>, testModule: Type<any> | ModuleWithProviders): Shallow<T> {
export function getShallow<T>(testComponent: Type<T>, testModule: Type<any> | ModuleWithProviders<any>): Shallow<T> {

createMocks(testComponent);

Expand All @@ -106,7 +106,7 @@ export function getShallow<T>(testComponent: Type<T>, testModule: Type<any> | Mo
return shallow;
}

export function renderComponent<T>(testComponent: Type<T>, testModule: Type<any> | ModuleWithProviders): Promise<Rendering<T, never>> {
export function renderComponent<T>(testComponent: Type<T>, testModule: Type<any> | ModuleWithProviders<any>): Promise<Rendering<T, never>> {
return getShallow(testComponent, testModule).render();
}

Expand Down
18 changes: 18 additions & 0 deletions test/ng10/.browserslistrc
@@ -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 test/ng10/.editorconfig
@@ -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 test/ng10/.gitignore
@@ -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 test/ng10/README.md
@@ -0,0 +1,27 @@
# Ng10

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

## 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).
128 changes: 128 additions & 0 deletions test/ng10/angular.json
@@ -0,0 +1,128 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"ng10": {
"projectType": "application",
"schematics": {},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/ng10",
"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.css"
],
"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": "ng10:build"
},
"configurations": {
"production": {
"browserTarget": "ng10:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "ng10:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.app.json",
"tsconfig.spec.json",
"e2e/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
]
}
},
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "ng10:serve"
},
"configurations": {
"production": {
"devServerTarget": "ng10:serve:production"
}
}
}
}
}
},
"defaultProject": "ng10",
"cli": {
"analytics": false
}
}
36 changes: 36 additions & 0 deletions test/ng10/e2e/protractor.conf.js
@@ -0,0 +1,36 @@
// @ts-check
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts

const { SpecReporter, StacktraceOption } = require('jasmine-spec-reporter');

/**
* @type { import("protractor").Config }
*/
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./src/**/*.e2e-spec.ts'
],
capabilities: {
browserName: 'chrome'
},
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare() {
require('ts-node').register({
project: require('path').join(__dirname, './tsconfig.json')
});
jasmine.getEnv().addReporter(new SpecReporter({
spec: {
displayStacktrace: StacktraceOption.PRETTY
}
}));
}
};
23 changes: 23 additions & 0 deletions test/ng10/e2e/src/app.e2e-spec.ts
@@ -0,0 +1,23 @@
import { AppPage } from './app.po';
import { browser, logging } from 'protractor';

describe('workspace-project App', () => {
let page: AppPage;

beforeEach(() => {
page = new AppPage();
});

it('should display welcome message', () => {
page.navigateTo();
expect(page.getTitleText()).toEqual('ng10 app is running!');
});

afterEach(async () => {
// Assert that there are no errors emitted from the browser
const logs = await browser.manage().logs().get(logging.Type.BROWSER);
expect(logs).not.toContain(jasmine.objectContaining({
level: logging.Level.SEVERE,
} as logging.Entry));
});
});
11 changes: 11 additions & 0 deletions test/ng10/e2e/src/app.po.ts
@@ -0,0 +1,11 @@
import { browser, by, element } from 'protractor';

export class AppPage {
navigateTo(): Promise<unknown> {
return browser.get(browser.baseUrl) as Promise<unknown>;
}

getTitleText(): Promise<string> {
return element(by.css('app-root .content span')).getText() as Promise<string>;
}
}
14 changes: 14 additions & 0 deletions test/ng10/e2e/tsconfig.json
@@ -0,0 +1,14 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/e2e",
"module": "commonjs",
"target": "es2018",
"types": [
"jasmine",
"jasminewd2",
"node"
]
}
}

0 comments on commit 9b9a5bd

Please sign in to comment.