From 8362bea5fa43228db9bdd580e59460ff31b07a72 Mon Sep 17 00:00:00 2001 From: Darrel O'Pry Date: Fri, 9 Mar 2018 16:57:44 -0500 Subject: [PATCH 1/8] fix(ci): pass nosandbox when running headless for travis-ci see: https://docs.travis-ci.com/user/chrome --- .travis.yml | 2 +- karma.conf.js | 10 ++++++++-- package.json | 1 + travis.karma.conf.js | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 travis.karma.conf.js diff --git a/.travis.yml b/.travis.yml index ec5cdee..257766c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ before_install: script: - "commitlint-travis" - "npm run lint" - - "npm run test" + - "npm run test-travis" - "cat ./reports/coverage/lcov.info | ./node_modules/.bin/coveralls" sudo: false diff --git a/karma.conf.js b/karma.conf.js index af139fa..2c4abcc 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -27,7 +27,13 @@ module.exports = function (config) { colors: true, logLevel: config.LOG_INFO, autoWatch: true, - browsers: ['Chrome'], - singleRun: false + browsers: ['Chrome', 'ChromeHeadlessNoSandbox'], + singleRun: false, + customLaunchers: { + ChromeHeadlessNoSandbox: { + base: 'ChromeHeadless', + flags: ['--no-sandbox'] + } + } }); }; diff --git a/package.json b/package.json index 97a7c79..88036aa 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "start": "electron . | ng serve", "build": "ng build --prod", "test": "ng test", + "test-travis": "ng test -c travis.karma.conf.js", "lint": "ng lint", "e2e": "ng e2e", "pack": "npm run build && electron-packager . --platform=darwin,win32,linux --arch=x64 --overwrite --out=bin" diff --git a/travis.karma.conf.js b/travis.karma.conf.js new file mode 100644 index 0000000..72410ed --- /dev/null +++ b/travis.karma.conf.js @@ -0,0 +1,39 @@ +// Karma configuration file, see link for more information +// https://karma-runner.github.io/1.0/config/configuration-file.html + +module.exports = function (config) { + config.set({ + basePath: '', + frameworks: ['jasmine', '@angular/cli'], + plugins: [ + require('karma-jasmine'), + require('karma-chrome-launcher'), + require('karma-jasmine-html-reporter'), + require('karma-coverage-istanbul-reporter'), + require('@angular/cli/plugins/karma') + ], + client:{ + clearContext: false // leave Jasmine Spec Runner output visible in browser + }, + coverageIstanbulReporter: { + reports: [ 'html', 'lcovonly' ], + fixWebpackSourcePaths: true + }, + angularCli: { + environment: 'dev' + }, + reporters: ['progress', 'kjhtml'], + port: 9876, + colors: true, + logLevel: config.LOG_INFO, + autoWatch: true, + browsers: ['ChromeHeadlessNoSandbox'], + singleRun: false, + customLaunchers: { + ChromeHeadlessNoSandbox: { + base: 'ChromeHeadless', + flags: ['--no-sandbox'] + } + } + }); +}; From 069e3340df9941d71200d137a4e3c83a78bab9aa Mon Sep 17 00:00:00 2001 From: Darrel O'Pry Date: Fri, 9 Mar 2018 17:36:39 -0500 Subject: [PATCH 2/8] fix(ci): update node.js support to >= 6.4 There are testing failures in 4.x and 5.x from syntax issues in angular. 6.x was chosen as a base since ES6 is on the roadmap for bacstack and ES6 only has a 57% complete implementination --- .travis.yml | 5 ++--- package.json | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 257766c..fe7c637 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,8 @@ language: "node_js" node_js: - - "7" + - "9" + - "8" - "6" - - "5" - - "4" before_install: - "npm install coveralls" diff --git a/package.json b/package.json index 88036aa..f95627c 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "email": "fabio@fh1.ch" }, "engines": { - "node": ">= 0.12.0" + "node": ">= 6.4.0" }, "commitlint": { "extends": [ From 69e248987469571c2edd93df2c9fc02950eeafca Mon Sep 17 00:00:00 2001 From: Darrel O'Pry Date: Thu, 8 Mar 2018 13:37:36 -0500 Subject: [PATCH 3/8] chore: resolve unmet peer dependeny warnings npm WARN @angular-devkit/schematics@0.0.52 requires a peer of @angular-devkit/core@0.0.29 but none is installed. npm WARN @schematics/angular@0.1.17 requires a peer of @angular-devkit/core@0.0.29 but none is installed. --- package.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package.json b/package.json index f95627c..ffec21f 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ }, "homepage": "https://github.com/fh1ch/node-bacstack-browser#readme", "dependencies": { + "@angular-devkit/core": "0.0.29", "@angular/animations": "^5.0.0", "@angular/common": "^5.0.0", "@angular/compiler": "^5.0.0", @@ -51,6 +52,7 @@ "@angular/platform-browser": "^5.0.0", "@angular/platform-browser-dynamic": "^5.0.0", "@angular/router": "^5.0.0", + "ajv": "^6.0.0", "async": "^2.6.0", "bacstack": "0.0.1-beta.13", "body-parser": "^1.18.2", From 89775af9330a40c9449d84b5dccd3919546a20c6 Mon Sep 17 00:00:00 2001 From: Darrel O'Pry Date: Fri, 9 Mar 2018 17:48:44 -0500 Subject: [PATCH 4/8] fix(ci): streamline karma for ci * single run * no autoWatch * no html reports * no html coverage reports --- travis.karma.conf.js | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/travis.karma.conf.js b/travis.karma.conf.js index 72410ed..ecd8b0a 100644 --- a/travis.karma.conf.js +++ b/travis.karma.conf.js @@ -1,34 +1,24 @@ // Karma configuration file, see link for more information // https://karma-runner.github.io/1.0/config/configuration-file.html - +const baseConfig = require('./karma.conf'); module.exports = function (config) { + // apply base config. + baseConfig(config); + // travis-ci specific overrides. config.set({ - basePath: '', - frameworks: ['jasmine', '@angular/cli'], - plugins: [ - require('karma-jasmine'), - require('karma-chrome-launcher'), - require('karma-jasmine-html-reporter'), - require('karma-coverage-istanbul-reporter'), - require('@angular/cli/plugins/karma') - ], - client:{ - clearContext: false // leave Jasmine Spec Runner output visible in browser - }, coverageIstanbulReporter: { - reports: [ 'html', 'lcovonly' ], + reports: ['lcovonly'], fixWebpackSourcePaths: true }, angularCli: { environment: 'dev' }, - reporters: ['progress', 'kjhtml'], + reporters: ['progress'], port: 9876, - colors: true, logLevel: config.LOG_INFO, - autoWatch: true, + autoWatch: false, browsers: ['ChromeHeadlessNoSandbox'], - singleRun: false, + singleRun: true, customLaunchers: { ChromeHeadlessNoSandbox: { base: 'ChromeHeadless', From 967b034f3e48394b1abc36532400bfc43df239ce Mon Sep 17 00:00:00 2001 From: Darrel O'Pry Date: Fri, 9 Mar 2018 18:12:21 -0500 Subject: [PATCH 5/8] chore: fast fail builds, allow 9.x to fails without failing whole matrix --- .travis.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.travis.yml b/.travis.yml index fe7c637..d01638f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,12 @@ node_js: - "8" - "6" + # fail buils early. +matrix: + fast_finish: true + allow_failures: + - node_js: "9" + before_install: - "npm install coveralls" From 84695d390c87b64efcfc7e93620a97990ba68635 Mon Sep 17 00:00:00 2001 From: Darrel O'Pry Date: Fri, 9 Mar 2018 18:45:27 -0500 Subject: [PATCH 6/8] chore: update karma to use electron instead of chrome --- .travis.yml | 7 +++++++ karma.conf.js | 13 ++++--------- package.json | 1 + travis.karma.conf.js | 9 +-------- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index d01638f..ed642f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,13 @@ matrix: before_install: - "npm install coveralls" +before_script: + # Generate a virtual framebuffer X server to collect Electron windows + - export DISPLAY=:99.0 + - sh -e /etc/init.d/xvfb start + # Wait for Xvfb to start + - sleep 3 + script: - "commitlint-travis" - "npm run lint" diff --git a/karma.conf.js b/karma.conf.js index 2c4abcc..d9283f5 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -7,13 +7,14 @@ module.exports = function (config) { frameworks: ['jasmine', '@angular/cli'], plugins: [ require('karma-jasmine'), - require('karma-chrome-launcher'), + require('karma-electron'), require('karma-jasmine-html-reporter'), require('karma-coverage-istanbul-reporter'), require('@angular/cli/plugins/karma') ], client:{ - clearContext: false // leave Jasmine Spec Runner output visible in browser + clearContext: false, // leave Jasmine Spec Runner output visible in browser + useIframe: false // launch in a new windows instead of iframe so nodeIntegration will work. }, coverageIstanbulReporter: { reports: [ 'html', 'lcovonly' ], @@ -27,13 +28,7 @@ module.exports = function (config) { colors: true, logLevel: config.LOG_INFO, autoWatch: true, - browsers: ['Chrome', 'ChromeHeadlessNoSandbox'], + browsers: ['Electron'], singleRun: false, - customLaunchers: { - ChromeHeadlessNoSandbox: { - base: 'ChromeHeadless', - flags: ['--no-sandbox'] - } - } }); }; diff --git a/package.json b/package.json index ffec21f..52b419d 100644 --- a/package.json +++ b/package.json @@ -84,6 +84,7 @@ "karma-chrome-launcher": "~2.1.1", "karma-cli": "~1.0.1", "karma-coverage-istanbul-reporter": "^1.2.1", + "karma-electron": "^5.2.2", "karma-jasmine": "~1.1.0", "karma-jasmine-html-reporter": "^0.2.2", "protractor": "~5.1.2", diff --git a/travis.karma.conf.js b/travis.karma.conf.js index ecd8b0a..ed736e3 100644 --- a/travis.karma.conf.js +++ b/travis.karma.conf.js @@ -17,13 +17,6 @@ module.exports = function (config) { port: 9876, logLevel: config.LOG_INFO, autoWatch: false, - browsers: ['ChromeHeadlessNoSandbox'], - singleRun: true, - customLaunchers: { - ChromeHeadlessNoSandbox: { - base: 'ChromeHeadless', - flags: ['--no-sandbox'] - } - } + singleRun: true }); }; From c5a2bd428624fe8095288619fd53c8fd262948d9 Mon Sep 17 00:00:00 2001 From: Darrel O'Pry Date: Fri, 9 Mar 2018 18:46:14 -0500 Subject: [PATCH 7/8] fix(tests): inject dependencies in tests --- src/app/app.component.spec.ts | 4 +++- src/app/pages/browse/browse.component.spec.ts | 8 ++++++- .../pages/objects/objects.component.spec.ts | 7 +++++- .../properties/properties.component.spec.ts | 7 +++++- .../pages/settings/settings.component.spec.ts | 7 +++++- src/app/services/api.service.spec.ts | 22 ++++++++++++++----- 6 files changed, 45 insertions(+), 10 deletions(-) diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index bcbdf36..fa76c13 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -1,4 +1,5 @@ import { TestBed, async } from '@angular/core/testing'; +import { RouterTestingModule } from '@angular/router/testing'; import { AppComponent } from './app.component'; describe('AppComponent', () => { beforeEach(async(() => { @@ -6,6 +7,7 @@ describe('AppComponent', () => { declarations: [ AppComponent ], + imports: [ RouterTestingModule ] }).compileComponents(); })); it('should create the app', async(() => { @@ -22,6 +24,6 @@ describe('AppComponent', () => { const fixture = TestBed.createComponent(AppComponent); fixture.detectChanges(); const compiled = fixture.debugElement.nativeElement; - expect(compiled.querySelector('h1').textContent).toContain('Welcome to app!'); + expect(compiled.querySelector('.navbar-brand-icon').textContent).toContain('Node BACStack Browser'); })); }); diff --git a/src/app/pages/browse/browse.component.spec.ts b/src/app/pages/browse/browse.component.spec.ts index 6a60dfb..de0fc39 100644 --- a/src/app/pages/browse/browse.component.spec.ts +++ b/src/app/pages/browse/browse.component.spec.ts @@ -1,6 +1,9 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; +import { RouterTestingModule } from '@angular/router/testing'; import { BrowseComponent } from './browse.component'; +import { ApiService } from '../../services/api.service'; describe('BrowseComponent', () => { let component: BrowseComponent; @@ -8,7 +11,10 @@ describe('BrowseComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ BrowseComponent ] + imports: [ RouterTestingModule, HttpClientTestingModule ], + declarations: [ BrowseComponent ], + providers: [ ApiService ] + }) .compileComponents(); })); diff --git a/src/app/pages/objects/objects.component.spec.ts b/src/app/pages/objects/objects.component.spec.ts index 4221735..cb546fa 100644 --- a/src/app/pages/objects/objects.component.spec.ts +++ b/src/app/pages/objects/objects.component.spec.ts @@ -1,6 +1,9 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; +import { RouterTestingModule } from '@angular/router/testing'; import { ObjectsComponent } from './objects.component'; +import { ApiService } from '../../services/api.service'; describe('ObjectsComponent', () => { let component: ObjectsComponent; @@ -8,7 +11,9 @@ describe('ObjectsComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ ObjectsComponent ] + imports: [ RouterTestingModule, HttpClientTestingModule ], + declarations: [ ObjectsComponent ], + providers: [ ApiService ] }) .compileComponents(); })); diff --git a/src/app/pages/properties/properties.component.spec.ts b/src/app/pages/properties/properties.component.spec.ts index e82e976..a3aa540 100644 --- a/src/app/pages/properties/properties.component.spec.ts +++ b/src/app/pages/properties/properties.component.spec.ts @@ -1,6 +1,9 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; +import { RouterTestingModule } from '@angular/router/testing'; import { PropertiesComponent } from './properties.component'; +import { ApiService } from '../../services/api.service'; describe('PropertiesComponent', () => { let component: PropertiesComponent; @@ -8,7 +11,9 @@ describe('PropertiesComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ PropertiesComponent ] + imports: [ RouterTestingModule, HttpClientTestingModule ], + declarations: [ PropertiesComponent ], + providers: [ ApiService ] }) .compileComponents(); })); diff --git a/src/app/pages/settings/settings.component.spec.ts b/src/app/pages/settings/settings.component.spec.ts index 91588f3..db229ea 100644 --- a/src/app/pages/settings/settings.component.spec.ts +++ b/src/app/pages/settings/settings.component.spec.ts @@ -1,6 +1,9 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { FormsModule } from '@angular/forms'; +import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; import { SettingsComponent } from './settings.component'; +import { ApiService } from '../../services/api.service'; describe('SettingsComponent', () => { let component: SettingsComponent; @@ -8,7 +11,9 @@ describe('SettingsComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ SettingsComponent ] + imports: [ FormsModule, HttpClientTestingModule ], + declarations: [ SettingsComponent ], + providers: [ ApiService ] }) .compileComponents(); })); diff --git a/src/app/services/api.service.spec.ts b/src/app/services/api.service.spec.ts index 65b6c71..bb96869 100644 --- a/src/app/services/api.service.spec.ts +++ b/src/app/services/api.service.spec.ts @@ -1,15 +1,27 @@ -import { TestBed, inject } from '@angular/core/testing'; - +import { TestBed, getTestBed, inject } from '@angular/core/testing'; +import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; import { ApiService } from './api.service'; +// @see: https://medium.com/netscape/testing-with-the-angular-httpclient-api-648203820712 for +// an example of testing http service. + describe('ApiService', () => { + let injector: TestBed; + let service: ApiService; + let httpMock: HttpTestingController; + beforeEach(() => { TestBed.configureTestingModule({ - providers: [ApiService] + imports: [ HttpClientTestingModule ], + providers: [ ApiService ] }); + injector = getTestBed(); + service = injector.get(ApiService); + httpMock = injector.get(HttpTestingController); + }); - it('should be created', inject([ApiService], (service: ApiService) => { + it('should be created', () => { expect(service).toBeTruthy(); - })); + }); }); From ab0232f96e9e8af89f14c4b941d58e9e70c6da42 Mon Sep 17 00:00:00 2001 From: Darrel O'Pry Date: Fri, 9 Mar 2018 18:56:34 -0500 Subject: [PATCH 8/8] fix(ci): add lcov reporting for coveralls --- .travis.yml | 2 +- karma.conf.js | 4 ++-- package.json | 4 ++-- travis.karma.conf.js | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index ed642f4..98c24e5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,6 +24,6 @@ script: - "commitlint-travis" - "npm run lint" - "npm run test-travis" - - "cat ./reports/coverage/lcov.info | ./node_modules/.bin/coveralls" + - "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls" sudo: false diff --git a/karma.conf.js b/karma.conf.js index d9283f5..11dd668 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -17,13 +17,13 @@ module.exports = function (config) { useIframe: false // launch in a new windows instead of iframe so nodeIntegration will work. }, coverageIstanbulReporter: { - reports: [ 'html', 'lcovonly' ], + reports: [ 'text-summary' ], fixWebpackSourcePaths: true }, angularCli: { environment: 'dev' }, - reporters: ['progress', 'kjhtml'], + reporters: ['progress', 'kjhtml', 'coverage-istanbul'], port: 9876, colors: true, logLevel: config.LOG_INFO, diff --git a/package.json b/package.json index 52b419d..75d29b9 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,8 @@ "ng": "ng", "start": "electron . | ng serve", "build": "ng build --prod", - "test": "ng test", - "test-travis": "ng test -c travis.karma.conf.js", + "test": "ng test --cc", + "test-travis": "ng test -c travis.karma.conf.js --cc", "lint": "ng lint", "e2e": "ng e2e", "pack": "npm run build && electron-packager . --platform=darwin,win32,linux --arch=x64 --overwrite --out=bin" diff --git a/travis.karma.conf.js b/travis.karma.conf.js index ed736e3..737c384 100644 --- a/travis.karma.conf.js +++ b/travis.karma.conf.js @@ -7,13 +7,13 @@ module.exports = function (config) { // travis-ci specific overrides. config.set({ coverageIstanbulReporter: { - reports: ['lcovonly'], + reports: ['lcovonly', 'text-summary'], fixWebpackSourcePaths: true }, angularCli: { environment: 'dev' }, - reporters: ['progress'], + reporters: ['progress', 'coverage-istanbul'], port: 9876, logLevel: config.LOG_INFO, autoWatch: false,