chore: Spectron for e2e tests

This commit is contained in:
Artem Vasiliev
2019-03-01 15:07:37 +03:00
parent 3b9b80822f
commit 901438aab4
8 changed files with 79 additions and 77 deletions

View File

@@ -125,13 +125,6 @@
"root": "e2e", "root": "e2e",
"projectType": "application", "projectType": "application",
"architect": { "architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "angular-electron:serve"
}
},
"lint": { "lint": {
"builder": "@angular-devkit/build-angular:tslint", "builder": "@angular-devkit/build-angular:tslint",
"options": { "options": {

View File

@@ -1,15 +0,0 @@
import { AngularElectronPage } from './app.po';
import { browser, element, by } from 'protractor';
describe('angular-electron App', () => {
let page: AngularElectronPage;
beforeEach(() => {
page = new AngularElectronPage();
});
it('should display message saying App works !', () => {
page.navigateTo('/');
expect(element(by.css('app-home h1')).getText()).toMatch('App works !');
});
});

View File

@@ -1,8 +0,0 @@
import { browser, element, by } from 'protractor';
/* tslint:disable */
export class AngularElectronPage {
navigateTo(route: string) {
return browser.get(route);
}
}

41
e2e/common-setup.ts Normal file
View File

@@ -0,0 +1,41 @@
const Application = require('spectron').Application;
const electronPath = require('electron'); // Require Electron from the binaries included in node_modules.
const path = require('path');
export default function setup() {
beforeEach(async function () {
this.app = new Application({
// Your electron path can be any binary
// i.e for OSX an example path could be '/Applications/MyApp.app/Contents/MacOS/MyApp'
// But for the sake of the example we fetch it from our node_modules.
path: electronPath,
// Assuming you have the following directory structure
// |__ my project
// |__ ...
// |__ main.js
// |__ package.json
// |__ index.html
// |__ ...
// |__ test
// |__ spec.js <- You are here! ~ Well you should be.
// The following line tells spectron to look and use the main.js file
// and the package.json located 1 level above.
args: [path.join(__dirname, '..')],
webdriverOptions: {}
});
await this.app.start();
const browser = this.app.client;
await browser.waitUntilWindowLoaded();
browser.timeouts('script', 15000);
});
afterEach(function () {
if (this.app && this.app.isRunning()) {
return this.app.stop();
}
});
}

28
e2e/main.spec.ts Normal file
View File

@@ -0,0 +1,28 @@
import {expect, assert} from 'chai';
import {SpectronClient} from 'spectron';
import commonSetup from './common-setup';
describe('angular-electron App', function () {
commonSetup.apply(this);
let browser: any;
let client: SpectronClient;
beforeEach(function () {
client = this.app.client;
browser = client as any;
});
it('should display message saying App works !', async function () {
const text = await browser.getText('app-home h1');
expect(text).to.equal('App works !');
});
it('creates initial windows', async function () {
const count = await client.getWindowCount();
expect(count).to.equal(2);
});
});

View File

@@ -1,37 +0,0 @@
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
const { SpecReporter } = require('jasmine-spec-reporter');
exports.config = {
allScriptsTimeout: 25000,
delayBrowserTimeInSeconds: 0,
specs: [
'./**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome',
chromeOptions: {
args: ["--no-sandbox", "--headless", "--disable-gpu"]
}
},
chromeOnly: true,
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine2',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function () { },
realtimeFailure: true
},
useAllAngular2AppRoots: true,
beforeLaunch: function () {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
},
onPrepare() {
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
}
};

View File

@@ -2,11 +2,10 @@
"extends": "../tsconfig.json", "extends": "../tsconfig.json",
"compilerOptions": { "compilerOptions": {
"outDir": "../out-tsc/e2e", "outDir": "../out-tsc/e2e",
"module": "commonjs", "module": "es2015",
"target": "es5", "types":[]
"types":[ },
"jasmine", "include": [
"node" "**/*.ts"
] ]
}
} }

View File

@@ -34,10 +34,9 @@
"electron:windows": "npm run build:prod && electron-builder build --windows", "electron:windows": "npm run build:prod && electron-builder build --windows",
"electron:mac": "npm run build:prod && electron-builder build --mac", "electron:mac": "npm run build:prod && electron-builder build --mac",
"test": "npm run postinstall:web && ng test", "test": "npm run postinstall:web && ng test",
"e2e": "npm run postinstall:web && ng e2e", "e2e": "npm run build:prod && mocha --timeout 300000 --require ts-node/register e2e/**/*.spec.ts",
"version": "conventional-changelog -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md" "version": "conventional-changelog -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md"
}, },
"dependencies": {},
"devDependencies": { "devDependencies": {
"@angular-devkit/build-angular": "0.12.1", "@angular-devkit/build-angular": "0.12.1",
"@angular/cli": "7.2.1", "@angular/cli": "7.2.1",
@@ -56,6 +55,7 @@
"@types/jasmine": "2.8.7", "@types/jasmine": "2.8.7",
"@types/jasminewd2": "2.0.3", "@types/jasminewd2": "2.0.3",
"@types/node": "8.9.4", "@types/node": "8.9.4",
"chai": "^4.2.0",
"codelyzer": "4.5.0", "codelyzer": "4.5.0",
"conventional-changelog-cli": "2.0.11", "conventional-changelog-cli": "2.0.11",
"core-js": "2.6.1", "core-js": "2.6.1",
@@ -69,9 +69,10 @@
"karma-coverage-istanbul-reporter": "2.0.4", "karma-coverage-istanbul-reporter": "2.0.4",
"karma-jasmine": "2.0.1", "karma-jasmine": "2.0.1",
"karma-jasmine-html-reporter": "1.4.0", "karma-jasmine-html-reporter": "1.4.0",
"mocha": "^6.0.2",
"npm-run-all": "4.1.5", "npm-run-all": "4.1.5",
"protractor": "5.4.1",
"rxjs": "6.3.3", "rxjs": "6.3.3",
"spectron": "^5.0.0",
"ts-node": "7.0.1", "ts-node": "7.0.1",
"tslint": "5.11.0", "tslint": "5.11.0",
"typescript": "3.2.2", "typescript": "3.2.2",