diff --git a/angular.json b/angular.json index df1d20294..636ec70c8 100644 --- a/angular.json +++ b/angular.json @@ -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": { diff --git a/e2e/app.e2e-spec.ts b/e2e/app.e2e-spec.ts deleted file mode 100644 index 5cd698f85..000000000 --- a/e2e/app.e2e-spec.ts +++ /dev/null @@ -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 !'); - }); -}); diff --git a/e2e/app.po.ts b/e2e/app.po.ts deleted file mode 100644 index 2dedeae92..000000000 --- a/e2e/app.po.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { browser, element, by } from 'protractor'; - -/* tslint:disable */ -export class AngularElectronPage { - navigateTo(route: string) { - return browser.get(route); - } -} diff --git a/e2e/common-setup.ts b/e2e/common-setup.ts new file mode 100644 index 000000000..7f6ebfd11 --- /dev/null +++ b/e2e/common-setup.ts @@ -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(); + } + }); +} diff --git a/e2e/main.spec.ts b/e2e/main.spec.ts new file mode 100644 index 000000000..8b3c356d2 --- /dev/null +++ b/e2e/main.spec.ts @@ -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); + }); + +}); diff --git a/e2e/protractor.conf.js b/e2e/protractor.conf.js deleted file mode 100644 index e46f106b8..000000000 --- a/e2e/protractor.conf.js +++ /dev/null @@ -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 } })); - } -}; diff --git a/e2e/tsconfig.e2e.json b/e2e/tsconfig.e2e.json index ac7a37325..acf240be4 100644 --- a/e2e/tsconfig.e2e.json +++ b/e2e/tsconfig.e2e.json @@ -2,11 +2,10 @@ "extends": "../tsconfig.json", "compilerOptions": { "outDir": "../out-tsc/e2e", - "module": "commonjs", - "target": "es5", - "types":[ - "jasmine", - "node" - ] - } + "module": "es2015", + "types":[] + }, + "include": [ + "**/*.ts" + ] } diff --git a/package.json b/package.json index 21869a212..3b831157f 100644 --- a/package.json +++ b/package.json @@ -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.2.1", @@ -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", @@ -69,9 +69,10 @@ "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", "rxjs": "6.3.3", + "spectron": "^5.0.0", "ts-node": "7.0.1", "tslint": "5.11.0", "typescript": "3.2.2",