Skip to content

Commit dd94bc5

Browse files
committed
Added e2e tests
1 parent d138d10 commit dd94bc5

8 files changed

+172
-8
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
dist/
3+
dist-e2e/
34
coverage/

bs-config.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"./intern.json"
55
],
66
"open": false,
7+
"logLevel": "silent",
78
"logConnections": false,
89
"server": {
910
"baseDir": [ "dist", "." ],

e2e/app.e2e-spec.ts

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const { describe, it, before } = intern.getPlugin('interface.bdd');
2+
const { expect } = intern.getPlugin('chai');
3+
4+
import Home from './pages/Home';
5+
6+
describe('E2E Tests', () => {
7+
let page: Home;
8+
9+
before(async ({ remote }) => {
10+
page = new Home(remote);
11+
await page.load();
12+
});
13+
14+
it('should begin at /dashboard', async () => {
15+
expect(await page.getCurrentUrl()).to.match(/\/dashboard$/);
16+
expect(await page.getDashboard()).to.exist;
17+
});
18+
19+
it('should navigate to /heroes when clicking Heroes', async () => {
20+
await page.clickHeroesNav();
21+
await page.waitForHeroes();
22+
expect(await page.getCurrentUrl()).to.match(/\/heroes$/);
23+
});
24+
25+
it('should navigate to /about when clicking About', async () => {
26+
await page.clickAboutNav();
27+
await page.waitForAbout();
28+
expect(await page.getCurrentUrl()).to.match(/\/about$/);
29+
});
30+
});

e2e/pages/Home.ts

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import Page from './Page';
2+
3+
export async function load() {
4+
const { parent: remote } = this;
5+
await remote.setFindTimeout(5000);
6+
await remote.get('dist/index.html');
7+
await remote.findDisplayedByCssSelector('my-app[ng-version]');
8+
}
9+
10+
export default class Home extends Page {
11+
protected _app = 'my-app[ng-version]';
12+
protected _dashboard = 'my-app app-dashboard';
13+
protected _heroes = 'my-app app-heroes';
14+
protected _about = 'my-app app-about';
15+
16+
async load() {
17+
const { _remote: remote } = this;
18+
await remote.setFindTimeout(5000);
19+
await remote.get('dist/index.html');
20+
await this.waitForApp();
21+
}
22+
23+
async getApp() {
24+
return this._find(this._app);
25+
}
26+
27+
async getNav() {
28+
return this._find('my-app > nav');
29+
}
30+
31+
async getDashboard() {
32+
return this._find(this._dashboard);
33+
}
34+
35+
async getHeroes() {
36+
return this._find(this._heroes);
37+
}
38+
39+
async getAbout() {
40+
return this._find(this._about);
41+
}
42+
43+
async getCurrentUrl() {
44+
return this._remote.getCurrentUrl();
45+
}
46+
47+
async clickHeroesNav() {
48+
await this._clickNav('/heroes');
49+
}
50+
51+
async clickAboutNav() {
52+
await this._clickNav('/about');
53+
}
54+
55+
async waitForApp() {
56+
return this._findDisplayed(this._app);
57+
}
58+
59+
async waitForDashboard() {
60+
return this._findDisplayed(this._dashboard);
61+
}
62+
63+
async waitForHeroes() {
64+
return this._findDisplayed(this._heroes);
65+
}
66+
67+
async waitForAbout() {
68+
return this._findDisplayed(this._about);
69+
}
70+
71+
protected async _clickNav(route: string) {
72+
const nav = await this.getNav();
73+
const link = await nav.findByCssSelector(`a[routerLink="${route}"]`);
74+
await link.click();
75+
}
76+
}

e2e/pages/Page.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Remote } from 'intern/lib/executors/Node';
2+
3+
export default class Page {
4+
constructor (protected _remote: Remote) {}
5+
6+
protected async _find(selector: string) {
7+
const { _remote } = this;
8+
return _remote.findByCssSelector(selector);
9+
}
10+
11+
protected async _findDisplayed(selector: string) {
12+
const { _remote } = this;
13+
return _remote.findDisplayedByCssSelector(selector);
14+
}
15+
}

e2e/tsconfig.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"module": "commonjs",
5+
"moduleResolution": "node",
6+
"sourceMap": true,
7+
"removeComments": true,
8+
"emitDecoratorMetadata": true,
9+
"experimentalDecorators": true,
10+
"lib": [
11+
"es5",
12+
"es2015.core",
13+
"es2015.collection",
14+
"es2015.symbol",
15+
"es2015.symbol.wellknown",
16+
"es2015.iterable",
17+
"dom"
18+
],
19+
"importHelpers": true,
20+
"noImplicitAny": true,
21+
"noUnusedLocals": true,
22+
"noUnusedParameters": true,
23+
"suppressImplicitAnyIndexErrors": true,
24+
"outDir": "../dist-e2e",
25+
"typeRoots": [
26+
"../node_modules/@types",
27+
"../node_modules/intern/types"
28+
],
29+
"types": [
30+
"intern"
31+
]
32+
}
33+
}

intern.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@
3131
"app/shared/twain.component.spec"
3232
]
3333
},
34+
"functionalSuites": [
35+
"dist-e2e/app.e2e-spec"
36+
],
3437
"configs": {
3538
"coverage": {
3639
"reporters+": "htmlcoverage",
37-
"excludeInstrumentation": "(?:node_modules|testing)\\/|\\.spec\\.js$|dist\\/[^\\/]+\\.js$"
40+
"excludeInstrumentation": "(?:node_modules|testing|e2e)\\/|[.-]spec\\.js$|dist\\/[^\\/]+\\.js$"
3841
},
3942

4043
"wd": {

package.json

+12-7
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,23 @@
44
"main": "index.js",
55
"license": "BSD-3-Clause",
66
"scripts": {
7-
"preci": "npm run clean && npm run lint && npm run dist",
7+
"preci": "npm run clean && npm run lint && npm run build",
88
"ci": "npm run test",
9-
"clean": "rimraf dist coverage",
9+
"clean": "rimraf dist dist-e2e coverage",
1010
"copy": "cpx \"src/**/*.{js,html,css}\" dist",
1111
"copy:watch": "cpx \"src/**/*.{js,html,css}\" dist --watch",
12-
"build": "tsc -p src/",
13-
"build:watch": "tsc -p src/ -w",
14-
"dist": "concurrently \"npm run build\" \"npm run copy\"",
12+
13+
"build": "concurrently --names \"tsc-src,tsc-e2e,copy\" \"npm run build:src\" \"npm run build:e2e\" \"npm run copy\"",
14+
"build:watch": "concurrently --names \"tsc-src,tsc-e2e,copy\" \"npm run build:src:watch\" \"npm run build:e2e:watch\" \"npm run copy:watch\"",
15+
16+
"build:src": "tsc -p src/",
17+
"build:src:watch": "tsc -p src/ -w",
18+
"build:e2e": "tsc -p e2e/",
19+
"build:e2e:watch": "tsc -p e2e/ -w",
20+
1521
"lint": "tslint -c tslint.json \"./src/**/*.ts\"",
1622
"serve": "lite-server -c=bs-config.json",
17-
"prestart": "npm run dist",
18-
"start": "concurrently \"npm run build:watch\" \"npm run copy:watch\" \"npm run serve\"",
23+
"start": "concurrently \"npm run build:watch\" \"npm run serve\"",
1924
"test": "intern config=@wdcoverage"
2025
},
2126
"dependencies": {

0 commit comments

Comments
 (0)