diff --git a/.gitignore b/.gitignore index 5e70f99..a5da22d 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ /release main.js src/**/*.js +!src/karma.conf.js *.js.map # dependencies diff --git a/.travis.yml b/.travis.yml index 346884f..9bfad5d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,11 +3,13 @@ os: - osx language: node_js node_js: - - 10 - - 8 + - '12' + - '11' + - '10' +dist: xenial sudo: required addons: - chrome: stable + chrome: stable before_script: - if [ "${TRAVIS_OS_NAME}" = "linux" ]; then export DISPLAY=:99.0; sh -e /etc/init.d/xvfb start; fi install: diff --git a/README.md b/README.md index 1cdf498..529dd73 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Bootstrap and package your project with Angular 7 and Electron (Typescript + SAS Currently runs with: -- Angular v7.1.4 +- Angular v7.2.0 - Electron v4.0.0 - Electron Builder v20.28.1 @@ -90,7 +90,7 @@ Note that you can't use Electron or NodeJS native libraries in this case. Please - Angular 7 & Electron 3 : (master) [build-badge]: https://travis-ci.org/maximegris/angular-electron.svg?branch=master -[build]: https://travis-ci.org/maximegris/angular-electron.svg?branch=master +[build]: https://travis-ci.org/maximegris/angular-electron [dependencyci-badge]: https://dependencyci.com/github/maximegris/angular-electron/badge [dependencyci]: https://dependencyci.com/github/maximegris/angular-electron [license-badge]: https://img.shields.io/badge/license-Apache2-blue.svg?style=flat diff --git a/angular.json b/angular.json index df1d202..636ec70 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 5cd698f..0000000 --- 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 2dedeae..0000000 --- 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 0000000..7f6ebfd --- /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 0000000..a20d484 --- /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(1); + }); + +}); diff --git a/e2e/protractor.conf.js b/e2e/protractor.conf.js deleted file mode 100644 index e46f106..0000000 --- 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 ac7a373..fa5f5d3 100644 --- a/e2e/tsconfig.e2e.json +++ b/e2e/tsconfig.e2e.json @@ -2,11 +2,12 @@ "extends": "../tsconfig.json", "compilerOptions": { "outDir": "../out-tsc/e2e", - "module": "commonjs", - "target": "es5", - "types":[ - "jasmine", - "node" + "module": "es2015", + "types": [ + "mocha" ] - } + }, + "include": [ + "**/*.ts" + ] } diff --git a/main.ts b/main.ts index 44f897b..71bd586 100644 --- a/main.ts +++ b/main.ts @@ -16,7 +16,10 @@ function createWindow() { x: 0, y: 0, width: size.width, - height: size.height + height: size.height, + webPreferences: { + nodeIntegration: true, + }, }); if (serve) { @@ -32,7 +35,9 @@ function createWindow() { })); } - win.webContents.openDevTools(); + if (serve) { + win.webContents.openDevTools(); + } // Emitted when the window is closed. win.on('closed', () => { diff --git a/package.json b/package.json index 2c5faf7..250522b 100644 --- a/package.json +++ b/package.json @@ -34,28 +34,29 @@ "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.11.4", - "@angular/cli": "7.1.4", - "@angular/common": "7.1.4", - "@angular/compiler": "7.1.4", - "@angular/compiler-cli": "7.1.4", - "@angular/core": "7.1.4", - "@angular/forms": "7.1.4", - "@angular/http": "7.1.4", - "@angular/language-service": "7.1.4", - "@angular/platform-browser": "7.1.4", - "@angular/platform-browser-dynamic": "7.1.4", - "@angular/router": "7.1.4", + "@angular-devkit/build-angular": "0.12.1", + "@angular/cli": "7.3.3", + "@angular/common": "7.2.7", + "@angular/compiler": "7.2.7", + "@angular/compiler-cli": "7.2.7", + "@angular/core": "7.2.7", + "@angular/forms": "7.2.7", + "@angular/http": "7.2.7", + "@angular/language-service": "7.2.7", + "@angular/platform-browser": "7.2.7", + "@angular/platform-browser-dynamic": "7.2.7", + "@angular/router": "7.2.7", "@ngx-translate/core": "11.0.1", "@ngx-translate/http-loader": "4.0.0", "@types/jasmine": "2.8.7", "@types/jasminewd2": "2.0.3", + "@types/mocha": "^5.2.6", "@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,14 +70,15 @@ "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", + "rxjs": "6.4.0", + "spectron": "5.0.0", "ts-node": "7.0.1", "tslint": "5.11.0", - "typescript": "3.1.6", + "typescript": "3.2.4", "wait-on": "3.2.0", "webdriver-manager": "12.1.0", - "zone.js": "0.8.26" + "zone.js": "0.8.29" } } diff --git a/tsconfig-serve.json b/tsconfig-serve.json index 56d7a0a..f9874f4 100644 --- a/tsconfig-serve.json +++ b/tsconfig-serve.json @@ -6,8 +6,8 @@ "emitDecoratorMetadata": true, "experimentalDecorators": true, "target": "es5", - "typeRoots": [ - "node_modules/@types" + "types": [ + "node" ], "lib": [ "es2017",