Skip to content

Commit 11943f6

Browse files
committed
chore: add wallaby.js support, refactor example spec
1 parent b614774 commit 11943f6

File tree

3 files changed

+104
-33
lines changed

3 files changed

+104
-33
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ _temp
1212
!**/*e2e-spec.js
1313
!karma*.js
1414
!protractor*.js
15+
!wallaby.js

app/app.component.spec.ts

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,10 @@
22
import { AppComponent } from './app.component';
33

44
import {
5-
it,
6-
iit,
7-
xit,
8-
describe,
9-
ddescribe,
10-
xdescribe,
11-
expect,
12-
fakeAsync,
13-
tick,
14-
beforeEach,
15-
inject,
16-
injectAsync,
17-
withProviders,
18-
beforeEachProviders,
19-
TestComponentBuilder
5+
expect, it, iit, xit,
6+
describe, ddescribe, xdescribe,
7+
beforeEach, beforeEachProviders, withProviders,
8+
inject, injectAsync, fakeAsync, TestComponentBuilder, tick
209
} from 'angular2/testing';
2110

2211
import { provide } from 'angular2/core';
@@ -25,36 +14,36 @@ import { PromiseWrapper } from 'angular2/src/facade/promise';
2514

2615
/////////// Module Preparation ///////////////////////
2716
interface Done {
28-
(): void;
29-
fail: (err: any) => void;
17+
(): void;
18+
fail: (err: any) => void;
3019
}
3120

3221
//////// SPECS /////////////
3322

34-
/// Delete thesVerify can use Angular testing's DOM abstraction to access DOM
35-
23+
/// Delete this: verify can use Angular testing's DOM abstraction to access DOM
3624
describe('Smoke test', () => {
3725
it('should run a passing test', () => {
3826
expect(true).toEqual(true, 'should pass');
3927
});
4028
});
4129

42-
describe('AppComponent', function() {
30+
31+
describe('AppComponent', function () {
4332
it('should instantiate component',
44-
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
33+
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
4534

46-
return tcb.createAsync(AppComponent).then(fixture => {
47-
expect(fixture.componentInstance instanceof AppComponent).toBe(true, 'should create AppComponent');
48-
});
49-
}));
35+
return tcb.createAsync(AppComponent).then(fixture => {
36+
expect(fixture.componentInstance instanceof AppComponent).toBe(true, 'should create AppComponent');
37+
});
38+
}));
5039

5140
it('should have expected <h1> text',
52-
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
53-
54-
return tcb.createAsync(AppComponent).then(fixture => {
55-
// fixture.detectChanges(); // need for a binding; we don't have one
56-
let h1 = fixture.debugElement.query(el => el.name === 'h1').nativeElement;
57-
expect(h1.innerText).toMatch(/angular 2 app/i, '<h1> should say something about "Angular 2 App"');
58-
});
59-
}));
41+
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
42+
43+
return tcb.createAsync(AppComponent).then(fixture => {
44+
// fixture.detectChanges(); // need for a binding; we don't have one
45+
let h1 = fixture.debugElement.query(el => el.name === 'h1').nativeElement;
46+
expect(h1.innerText).toMatch(/angular 2 app/i, '<h1> should say something about "Angular 2 App"');
47+
});
48+
}));
6049
});

wallaby.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Configuration for the Wallaby Visual Studio Code testing extension
2+
// https://marketplace.visualstudio.com/items?itemName=WallabyJs.wallaby-vscode
3+
// Note: Wallaby is not open source and costs money
4+
module.exports = function () {
5+
6+
return {
7+
files: [
8+
{pattern: 'node_modules/es6-shim/es6-shim.js', instrument: false},
9+
{pattern: 'node_modules/systemjs/dist/system-polyfills.js', instrument: false},
10+
{pattern: 'node_modules/systemjs/dist/system.js', instrument: false},
11+
{pattern: 'node_modules/reflect-metadata/Reflect.js', instrument: false},
12+
{pattern: 'node_modules/zone.js/dist/zone.js', instrument: false},
13+
{pattern: 'node_modules/zone.js/dist/long-stack-trace-zone.js', instrument: false},
14+
{pattern: 'node_modules/zone.js/dist/jasmine-patch.js', instrument: false},
15+
16+
{pattern: 'app/**/*.ts', load: false},
17+
{pattern: 'app/**/*.html', load: false},
18+
{pattern: 'app/**/*.spec.ts', ignore: true}
19+
],
20+
21+
tests: [
22+
{pattern: 'app/*.spec.ts', load: false}
23+
],
24+
25+
middleware: function (app, express) {
26+
app.use('/node_modules', express.static(require('path').join(__dirname, 'node_modules')));
27+
},
28+
29+
testFramework: 'jasmine',
30+
31+
bootstrap: function (wallaby) {
32+
wallaby.delayStart();
33+
34+
System.config({
35+
defaultJSExtensions: true,
36+
packages: {
37+
app: {
38+
meta: {
39+
'*': {
40+
scriptLoad: true
41+
}
42+
}
43+
}
44+
},
45+
paths: {
46+
'npm:*': 'node_modules/*'
47+
},
48+
map: {
49+
'angular2': 'npm:angular2',
50+
'rxjs': 'npm:rxjs'
51+
}
52+
});
53+
54+
55+
Promise.all([
56+
System.import('angular2/testing'),
57+
System.import('angular2/platform/testing/browser')
58+
])
59+
.then(function (results) {
60+
var testing = results[0];
61+
var browser = results[1];
62+
testing.setBaseTestProviders(
63+
browser.TEST_BROWSER_PLATFORM_PROVIDERS,
64+
browser.TEST_BROWSER_APPLICATION_PROVIDERS);
65+
66+
return Promise.all(wallaby.tests.map(function (specFile) {
67+
return System.import(specFile.replace(/\.js$/, ''));
68+
}));
69+
})
70+
.then(function () {
71+
wallaby.start();
72+
})
73+
.catch(function (e) {
74+
setTimeout(function () {
75+
throw e;
76+
}, 0);
77+
});
78+
},
79+
debug: true
80+
};
81+
};

0 commit comments

Comments
 (0)