Skip to content

Commit

Permalink
Merge pull request #317 from artemv/spectron
Browse files Browse the repository at this point in the history
chore: Spectron for e2e tests
  • Loading branch information
maximegris committed Mar 3, 2019
2 parents 915b263 + 87d0483 commit 80db2e2
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 78 deletions.
7 changes: 0 additions & 7 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,6 @@
"root": "e2e",
"projectType": "application",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "angular-electron:serve"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
Expand Down
15 changes: 0 additions & 15 deletions e2e/app.e2e-spec.ts

This file was deleted.

8 changes: 0 additions & 8 deletions e2e/app.po.ts

This file was deleted.

41 changes: 41 additions & 0 deletions e2e/common-setup.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 28 additions & 0 deletions e2e/main.spec.ts
Original file line number Diff line number Diff line change
@@ -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(1);
});

});
37 changes: 0 additions & 37 deletions e2e/protractor.conf.js

This file was deleted.

13 changes: 6 additions & 7 deletions e2e/tsconfig.e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/e2e",
"module": "commonjs",
"target": "es5",
"types":[
"jasmine",
"node"
]
}
"module": "es2015",
"types":[]
},
"include": [
"**/*.ts"
]
}
4 changes: 3 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ function createWindow() {
}));
}

win.webContents.openDevTools();
if (serve) {
win.webContents.openDevTools();
}

// Emitted when the window is closed.
win.on('closed', () => {
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@
"electron:windows": "npm run build:prod && electron-builder build --windows",
"electron:mac": "npm run build:prod && electron-builder build --mac",
"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"
},
"dependencies": {},
"devDependencies": {
"@angular-devkit/build-angular": "0.12.1",
"@angular/cli": "7.3.3",
Expand All @@ -56,6 +55,7 @@
"@types/jasmine": "2.8.7",
"@types/jasminewd2": "2.0.3",
"@types/node": "8.9.4",
"chai": "^4.2.0",
"codelyzer": "4.5.0",
"conventional-changelog-cli": "2.0.11",
"core-js": "2.6.1",
Expand All @@ -69,8 +69,9 @@
"karma-coverage-istanbul-reporter": "2.0.4",
"karma-jasmine": "2.0.1",
"karma-jasmine-html-reporter": "1.4.0",
"mocha": "6.0.2",
"npm-run-all": "4.1.5",
"protractor": "5.4.1",
"spectron": "5.0.0",
"rxjs": "6.4.0",
"ts-node": "7.0.1",
"tslint": "5.11.0",
Expand Down

0 comments on commit 80db2e2

Please sign in to comment.