Skip to content

Commit d332318

Browse files
committed
feat: use browser-do, add mocha support
1 parent 5a28223 commit d332318

14 files changed

Lines changed: 113 additions & 61 deletions

File tree

File renamed without changes.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import {expect} from 'chai';
2+
import {StageComponent} from 'aurelia-testing';
3+
import {bootstrap} from 'aurelia-bootstrapper';
4+
5+
describe('Component app', () => {
6+
let component;
7+
let model = {};
8+
9+
beforeEach(() => {
10+
component = StageComponent
11+
.withResources('app')
12+
.inView('<app></app>')
13+
.boundTo(model);
14+
});
15+
16+
afterEach(() => {
17+
if (component) {
18+
component.dispose();
19+
component = null;
20+
}
21+
});
22+
23+
it('should render message', done => {
24+
component.create(bootstrap).then(() => {
25+
const view = component.element;
26+
expect(view.textContent.trim()).to.be('Hello Aurelia!');
27+
done();
28+
}).catch(e => {
29+
done(e);
30+
});
31+
});
32+
});

common/.eslintrc.json__if_babel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
// @if jasmine
4343
"jasmine": true,
4444
// @endif
45+
// @if mocha
46+
"mocha": true,
47+
// @endif
4548
// @if jest
4649
"jest": true,
4750
// @endif

common/README.md

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,70 +3,60 @@
33
An app using dumber bundler to build. More details in `tasks/*.js` (loaded by `gulpfile.js`).
44

55
## Run in dev mode, plus watch
6-
```
7-
npm start
8-
```
6+
7+
npm start
98

109
## Run in production mode, plus watch
1110

1211
It updates index.html with hashed file name.
13-
```
14-
npm run start:prod
15-
```
12+
13+
npm run start:prod
14+
1615

1716
## Build in dev mode
1817

1918
Generates `scripts/*-bundle.js`
20-
```
21-
npm run build:dev
22-
```
19+
20+
npm run build:dev
21+
2322

2423
## Build in production mode
2524

2625
Generates `scripts/*-bundle.[hash].js`, update index.html with hashed file name.
27-
```
28-
npm run build
29-
```
26+
27+
npm run build
28+
3029

3130
## To clear cache
3231

3332
Clear tracing cache by dumber/* @if babel */, and transpiling cache by gulp-cache/* @endif */.
34-
```
35-
npm run clear-cache
36-
```
33+
34+
npm run clear-cache
35+
3736
// @if babel
3837
If you touch `.babelrc` file, you'd better do clear cache.
3938
// @endif
4039

4140
// @if jest || ava
4241
## Nodejs test
43-
```
44-
npm test
45-
```
42+
43+
npm test
4644

4745
Details in package.json -> scripts -> pretest & test.
4846
// @endif
49-
// @if jasmine || tape
47+
// @if jasmine || tape || mocha
5048
## Headless browser (electron) test
51-
```
52-
npm test
53-
```
49+
50+
npm test
5451

5552
Details in package.json -> scripts -> pretest & test.
5653

57-
1. no karma, no hacking, just browser-run (tape-run wraps browser-run).
54+
1. no karma, no hacking, just [browser-do](https://github.com/3cp/browser-do).
5855
2. note `| tap-dot` is optional, `tap-dot` is just a tap result formatter to please the eyes.
59-
// @if jasmine
60-
3. uses jasmine tap reporter so we can pipe the result to tape-run to return proper return-code to terminal.
61-
// @endif
62-
63-
Read more in `tasks/build.js`.
6456

6557
## Visible browser (chrome) test
66-
```
67-
npm run browser-test
68-
```
69-
// @if jasmine
70-
Note in visible browser test, we are feeding browser-run with SpecRunner.html instead of entry-bundle.js because we need jasmine css (in SpecRunner.html) for proper rendering.
71-
// @endif
58+
59+
npm run browser-test
60+
61+
This runs in Chrome, if you want to use other browser, update package.json "browser-test" script. Read [browser-do](https://github.com/3cp/browser-do) for available browsers.
7262
// @endif

common/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
"lesshint": "^6.3.6",
3737
// @endif
3838

39-
// @if jasmine || tape
39+
// @if jasmine || tape || mocha
4040
"tap-dot": "^2.0.0",
41-
"tape-run": "^5.0.0",
41+
"browser-do": "^0.1.0",
4242
// @endif
4343

4444
// @if !sfc
@@ -79,10 +79,9 @@
7979
// @endif
8080
"lint": "npm run js-lint/* @if sass || less */ && npm run css-lint/* @endif *//* @if aurelia */ && npm run html-lint/* @endif */",
8181

82-
// @if jasmine || tape
82+
// @if jasmine || tape || mocha
8383
"pretest": "npm run lint && npm run build:test",
8484
"build:test": "gulp clean && cross-env NODE_ENV=test gulp build",
85-
"test": "tape-run < dist/entry-bundle.js | tap-dot",
8685
// @endif
8786
"start": "gulp",
8887
"start:prod": "cross-env NODE_ENV=production gulp",

common/tasks/_dumber.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,14 @@ module.exports = dumber({
3232

3333
// prepend before amd loader.
3434
// dumber-module-loader is injected automatically by dumber bundler after prepends.
35-
// @if jasmine
36-
// Here we load all jasmine stuff in global name space in test mode.
37-
// @endif
3835
prepend: [
39-
// @if jasmine
40-
isTest && "node_modules/jasmine-core/lib/jasmine-core/jasmine.js",
41-
isTest && "node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js",
42-
isTest && "node_modules/jasmine-core/lib/jasmine-core/boot.js",
43-
isTest && "node_modules/jasmine-reporters/src/tap_reporter.js",
44-
// Turn on tap reporter (from jasmine-reporters), so results can be piped to tape-run.
45-
// Note prepend accepts direct JavaScript content.
46-
isTest && "jasmine.getEnv().addReporter(new jasmineReporters.TapReporter());",
47-
// @endif
4836
// Promise polyfill for IE
4937
"node_modules/promise-polyfill/dist/polyfill.min.js"
5038
],
5139

5240
// append after amd loader and all module definitions in entry bundle.
5341
append: [
54-
// @if jasmine || tape
42+
// @if jasmine || tape || mocha
5543
// Kick off all test files.
5644
// Note dumber-module-loader requirejs call accepts regex which loads all matched module ids!
5745
// Note all module ids are relative to dumber option "src" (default to 'src') folder.

common/tasks/build.js__if_not_sfc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,18 @@ function build() {
9999
// @endif
100100
// @if babel
101101
// @if !react
102-
buildJs(/* @if jasmine || tape */isTest ? ['src/**/*.js', 'test/**/*.js'] : /* @endif */'src/**/*.js'),
102+
buildJs(/* @if jasmine || tape || mocha */isTest ? ['src/**/*.js', 'test/**/*.js'] : /* @endif */'src/**/*.js'),
103103
// @endif
104104
// @if react
105-
buildJs(/* @if jasmine || tape */isTest ? ['src/**/*.js{,x}', 'test/**/*.js{,x}'] : /* @endif */'src/**/*.js{,x}'),
105+
buildJs(/* @if jasmine || tape || mocha */isTest ? ['src/**/*.js{,x}', 'test/**/*.js{,x}'] : /* @endif */'src/**/*.js{,x}'),
106106
// @endif
107107
// @endif
108108
// @if typescript
109109
// @if !react
110-
buildJs(/* @if jasmine || tape */isTest ? ['src/**/*.ts', 'test/**/*.ts'] : /* @endif */'src/**/*.ts'),
110+
buildJs(/* @if jasmine || tape || mocha */isTest ? ['src/**/*.ts', 'test/**/*.ts'] : /* @endif */'src/**/*.ts'),
111111
// @endif
112112
// @if react
113-
buildJs(/* @if jasmine || tape */isTest ? ['src/**/*.ts{,x}', 'test/**/*.ts{,x}'] : /* @endif */'src/**/*.ts{,x}'),
113+
buildJs(/* @if jasmine || tape || mocha */isTest ? ['src/**/*.ts{,x}', 'test/**/*.ts{,x}'] : /* @endif */'src/**/*.ts{,x}'),
114114
// @endif
115115
// @endif
116116
// @if css

common/tasks/build.js__if_sfc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function build() {
3939
// dumber knows nothing about .ts/.less/.scss/.md files,
4040
// gulp-* plugins transpiled them into js/css/html before
4141
// sending to dumber.
42-
return gulp.src(/* @if jasmine || tape */isTest ? ['test/**/*.js', 'src/**/*.{json,js,vue}'] : /* @endif */'src/**/*.{json,js,vue}', {sourcemaps: !isProduction, since: gulp.lastRun(build)})
42+
return gulp.src(/* @if jasmine || tape || mocha */isTest ? ['test/**/*.js', 'src/**/*.{json,js,vue}'] : /* @endif */'src/**/*.{json,js,vue}', {sourcemaps: !isProduction, since: gulp.lastRun(build)})
4343
// plumber does continue on failure for dev mode
4444
.pipe(gulpif(!isProduction, plumber()))
4545
.pipe(compileVue)

jasmine/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"devDependencies": {
33
"jasmine-core": "^3.4.0",
4-
"jasmine-reporters": "^2.3.2",
54
// @if typescript
65
"@types/jasmine": "^3.3.12",
76
// @endif
87
},
98
"scripts": {
10-
"browser-test": "npm run build:test && browser-run --input html --static . --browser chrome < SpecRunner.html"
9+
"test": "browser-do --jasmine < dist/entry-bundle.js | tap-dot",
10+
"browser-test": "npm run build:test && browser-do --jasmine --browser chrome < dist/entry-bundle.js"
1111
}
1212
}

mocha/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"devDependencies": {
3+
"mocha": "^6.1.4",
4+
"chai": "^4.2.0",
5+
// @if typescript
6+
"@types/mocha": "^5.2.7",
7+
// @endif
8+
},
9+
"scripts": {
10+
"test": "browser-do --mocha < dist/entry-bundle.js | tap-dot",
11+
"browser-test": "npm run build:test && browser-do --mocha --browser chrome < dist/entry-bundle.js"
12+
}
13+
}

0 commit comments

Comments
 (0)