Skip to content

Commit

Permalink
Introduce travis ci support and wallabyjs runner
Browse files Browse the repository at this point in the history
- Reformat the tests so that we're DRY. Use a second beforeEach only assert in tests
- add MIT license
  • Loading branch information
arranbartish committed Apr 14, 2017
1 parent 2bf12b5 commit 0bb9688
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .angular-cli.json
Expand Up @@ -46,6 +46,9 @@
}
],
"test": {
"codeCoverage": {
"exclude": ["src/test.ts"]
},
"karma": {
"config": "./karma.conf.js"
}
Expand Down
26 changes: 26 additions & 0 deletions .travis.yml
@@ -0,0 +1,26 @@
language: node_js
dist: trusty
node_js:
- 6.1
sudo: required
addons:
apt:
sources:
- google-chrome
packages:
- google-chrome-stable
- google-chrome-beta
before_install:
- export CHROME_BIN=chromium-browser
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- google-chrome --version
install:
- npm install
- npm install codecov
script:
- npm run test -- --single-run=true --browsers Chrome --code-coverage
- ./node_modules/codecov/bin/codecov
- npm run e2e
- npm run lint
- npm run build
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Arran Bartish

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
23 changes: 21 additions & 2 deletions karma.conf.js
Expand Up @@ -10,6 +10,7 @@ module.exports = function (config) {
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('karma-istanbul-threshold'),
require('@angular/cli/plugins/karma')
],
client:{
Expand All @@ -25,14 +26,32 @@ module.exports = function (config) {
'text/x-typescript': ['ts','tsx']
},
coverageIstanbulReporter: {
reports: [ 'html', 'lcovonly' ],
reports: [ 'html', 'lcovonly', 'json' ],
fixWebpackSourcePaths: true
},
istanbulThresholdReporter: {
src: 'coverage/coverage-final.json',
reporters: ['text'],
thresholds: {
global: {
statements: 95.01,
branches: 75.59,
lines: 91.89,
functions: 89.23
},
each: {
statements: 75.76,
branches: 33.33,
lines: 75,
functions: 41.67
}
}
},
angularCli: {
environment: 'dev'
},
reporters: config.angularCli && config.angularCli.codeCoverage
? ['progress', 'coverage-istanbul']
? ['progress', 'coverage-istanbul', 'istanbul-threshold']
: ['progress', 'kjhtml'],
port: 9876,
colors: true,
Expand Down
9 changes: 7 additions & 2 deletions package.json
Expand Up @@ -8,7 +8,8 @@
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
"pree2e": "webdriver-manager update --versions.chrome=2.28",
"e2e": "ng e2e --webdriver-update false"
},
"private": true,
"dependencies": {
Expand All @@ -29,18 +30,22 @@
"@angular/compiler-cli": "^4.0.0",
"@types/jasmine": "2.5.38",
"@types/node": "~6.0.60",
"angular2-template-loader": "^0.6.2",
"codelyzer": "~2.0.0",
"electron": "^1.4.15",
"jasmine-core": "~2.5.2",
"jasmine-spec-reporter": "~3.2.0",
"karma": "~1.4.1",
"karma-chrome-launcher": "~2.0.0",
"karma-cli": "~1.0.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-coverage-istanbul-reporter": "^0.2.0",
"karma-coverage-istanbul-reporter": "^1.0.0",
"karma-istanbul-threshold": "^1.2.2",
"protractor": "~5.1.0",
"ts-node": "~2.0.0",
"tslint": "~4.5.0",
"wallaby-webpack": "0.0.33",
"typescript": "~2.2.0"
}
}
18 changes: 12 additions & 6 deletions src/app/app.component.spec.ts
@@ -1,31 +1,37 @@
import { TestBed, async } from '@angular/core/testing';

import { AppComponent } from './app.component';
import {NO_ERRORS_SCHEMA} from '@angular/core';

describe('AppComponent', () => {
let fixture;
let app;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
],
schemas: [NO_ERRORS_SCHEMA],
imports: []
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(AppComponent);
app = fixture.debugElement.componentInstance;
fixture.detectChanges();
});

it('should create the app', async(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
}));

it(`should have as title 'app works!'`, async(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app.title).toEqual('app works!');
}));

it('should render title in a h1 tag', async(() => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1').textContent).toContain('app works!');
}));
Expand Down
19 changes: 19 additions & 0 deletions src/wallabyTest.ts
@@ -0,0 +1,19 @@
import './polyfills';

import 'zone.js/dist/long-stack-trace-zone';
import 'zone.js/dist/proxy.js';
import 'zone.js/dist/sync-test';
import 'zone.js/dist/jasmine-patch';
import 'zone.js/dist/async-test';
import 'zone.js/dist/fake-async-test';

import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';

getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
71 changes: 71 additions & 0 deletions wallaby.js
@@ -0,0 +1,71 @@
var wallabyWebpack = require('wallaby-webpack');

var electronParams = {};
if(process.env.DISABLE_GPU){
/* if you are having issues with your GPU such as https://github.com/wallabyjs/public/issues/1076
* then simply defined an environment variable in the trouble environment DISABLE_GPU=true and electron will use
* chrome environment with the GPU disabled
*/
electronParams.runner = '--disable-gpu';
}

var webpackPostprocessor = wallabyWebpack({
entryPatterns: [
'src/wallabyTest.js',
'src/**/*spec.js'
],

module: {
loaders: [
{test: /\.css$/, loader: 'raw-loader'},
{test: /\.html$/, loader: 'raw-loader'},
{test: /\.js$/, loader: 'angular2-template-loader', exclude: /node_modules/},
{test: /\.json$/, loader: 'json-loader'},
{test: /\.styl$/, loaders: ['raw-loader', 'stylus-loader']},
{test: /\.less$/, loaders: ['raw-loader', 'less-loader']},
{test: /\.scss$|\.sass$/, loaders: ['raw-loader', 'sass-loader']},
{test: /\.(jpg|png)$/, loader: 'url-loader?limit=128000'}
]
}
});

var compilerOptions = require('./src/tsconfig.spec.json').compilerOptions;

module.exports = function (wallaby) {

return {
files: [
{ pattern: 'src/**/*.ts', load: false },
{ pattern: 'src/**/*.d.ts', ignore: true },
{ pattern: 'src/**/*.css', load: false },
{ pattern: 'src/**/*.less', load: false },
{ pattern: 'src/**/*.scss', load: false },
{ pattern: 'src/**/*.sass', load: false },
{ pattern: 'src/**/*.html', load: false },
{ pattern: 'src/**/*spec.ts', ignore: true }
],

tests: [
{pattern: 'src/**/*spec.ts', load: false}
],

testFramework: 'jasmine',

compilers: {
'**/*.ts': wallaby.compilers.typeScript(compilerOptions)
},

env: {
kind: 'electron',
params: electronParams
},

postprocessor: webpackPostprocessor,

setup: function () {
window.__moduleBundler.loadTests();
},

debug: true
};
};

0 comments on commit 0bb9688

Please sign in to comment.