Commit 11943f67 authored by Ward Bell's avatar Ward Bell

chore: add wallaby.js support, refactor example spec

parent b6147741
......@@ -12,3 +12,4 @@ _temp
!**/*e2e-spec.js
!karma*.js
!protractor*.js
!wallaby.js
......@@ -2,21 +2,10 @@
import { AppComponent } from './app.component';
import {
it,
iit,
xit,
describe,
ddescribe,
xdescribe,
expect,
fakeAsync,
tick,
beforeEach,
inject,
injectAsync,
withProviders,
beforeEachProviders,
TestComponentBuilder
expect, it, iit, xit,
describe, ddescribe, xdescribe,
beforeEach, beforeEachProviders, withProviders,
inject, injectAsync, fakeAsync, TestComponentBuilder, tick
} from 'angular2/testing';
import { provide } from 'angular2/core';
......@@ -25,36 +14,36 @@ import { PromiseWrapper } from 'angular2/src/facade/promise';
/////////// Module Preparation ///////////////////////
interface Done {
(): void;
fail: (err: any) => void;
(): void;
fail: (err: any) => void;
}
//////// SPECS /////////////
/// Delete thesVerify can use Angular testing's DOM abstraction to access DOM
/// Delete this: verify can use Angular testing's DOM abstraction to access DOM
describe('Smoke test', () => {
it('should run a passing test', () => {
expect(true).toEqual(true, 'should pass');
});
});
describe('AppComponent', function() {
describe('AppComponent', function () {
it('should instantiate component',
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb.createAsync(AppComponent).then(fixture => {
expect(fixture.componentInstance instanceof AppComponent).toBe(true, 'should create AppComponent');
});
}));
return tcb.createAsync(AppComponent).then(fixture => {
expect(fixture.componentInstance instanceof AppComponent).toBe(true, 'should create AppComponent');
});
}));
it('should have expected <h1> text',
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb.createAsync(AppComponent).then(fixture => {
// fixture.detectChanges(); // need for a binding; we don't have one
let h1 = fixture.debugElement.query(el => el.name === 'h1').nativeElement;
expect(h1.innerText).toMatch(/angular 2 app/i, '<h1> should say something about "Angular 2 App"');
});
}));
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb.createAsync(AppComponent).then(fixture => {
// fixture.detectChanges(); // need for a binding; we don't have one
let h1 = fixture.debugElement.query(el => el.name === 'h1').nativeElement;
expect(h1.innerText).toMatch(/angular 2 app/i, '<h1> should say something about "Angular 2 App"');
});
}));
});
// Configuration for the Wallaby Visual Studio Code testing extension
// https://marketplace.visualstudio.com/items?itemName=WallabyJs.wallaby-vscode
// Note: Wallaby is not open source and costs money
module.exports = function () {
return {
files: [
{pattern: 'node_modules/es6-shim/es6-shim.js', instrument: false},
{pattern: 'node_modules/systemjs/dist/system-polyfills.js', instrument: false},
{pattern: 'node_modules/systemjs/dist/system.js', instrument: false},
{pattern: 'node_modules/reflect-metadata/Reflect.js', instrument: false},
{pattern: 'node_modules/zone.js/dist/zone.js', instrument: false},
{pattern: 'node_modules/zone.js/dist/long-stack-trace-zone.js', instrument: false},
{pattern: 'node_modules/zone.js/dist/jasmine-patch.js', instrument: false},
{pattern: 'app/**/*.ts', load: false},
{pattern: 'app/**/*.html', load: false},
{pattern: 'app/**/*.spec.ts', ignore: true}
],
tests: [
{pattern: 'app/*.spec.ts', load: false}
],
middleware: function (app, express) {
app.use('/node_modules', express.static(require('path').join(__dirname, 'node_modules')));
},
testFramework: 'jasmine',
bootstrap: function (wallaby) {
wallaby.delayStart();
System.config({
defaultJSExtensions: true,
packages: {
app: {
meta: {
'*': {
scriptLoad: true
}
}
}
},
paths: {
'npm:*': 'node_modules/*'
},
map: {
'angular2': 'npm:angular2',
'rxjs': 'npm:rxjs'
}
});
Promise.all([
System.import('angular2/testing'),
System.import('angular2/platform/testing/browser')
])
.then(function (results) {
var testing = results[0];
var browser = results[1];
testing.setBaseTestProviders(
browser.TEST_BROWSER_PLATFORM_PROVIDERS,
browser.TEST_BROWSER_APPLICATION_PROVIDERS);
return Promise.all(wallaby.tests.map(function (specFile) {
return System.import(specFile.replace(/\.js$/, ''));
}));
})
.then(function () {
wallaby.start();
})
.catch(function (e) {
setTimeout(function () {
throw e;
}, 0);
});
},
debug: true
};
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment