Skip to content

Commit 25861e4

Browse files
authored
Merge pull request #10 from InCuca/jest
Add jest support
2 parents 5ba568d + ab52d32 commit 25861e4

23 files changed

+220
-234
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# vue-loopback
22
[![Travis](https://img.shields.io/travis/InCuca/vue-loopback/master.svg)](https://travis-ci.org/InCuca/vue-loopback/branches)
33

4-
A Vue project template with [Loopback](http://loopback.io/) framework featuring ES6, Gulp, and Mocha for unit tests
4+
A Vue project template with [Loopback](http://loopback.io/) framework featuring ES6, Gulp, and Jest for unit tests
55

66
> This template is for Vue 2.x **only** with [vue-cli](https://github.com/vuejs/vue-cli).
77
@@ -44,6 +44,14 @@ A Vue project template with [Loopback](http://loopback.io/) framework featuring
4444
$ npm run dev
4545
```
4646

47+
## Debug
48+
49+
```
50+
$ DEBUG=loopback npm run dev
51+
```
52+
53+
[More info...](https://loopback.io/doc/en/lb3/Setting-debug-strings.html)
54+
4755
## Build to ./build
4856

4957
```
@@ -56,10 +64,3 @@ A Vue project template with [Loopback](http://loopback.io/) framework featuring
5664
$ cd build
5765
$ npm run start
5866
```
59-
60-
You can run only the server with:
61-
62-
```bash
63-
$ cd build/server
64-
$ node .
65-
```

template/.babelrc

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
"> 1%",
77
"last 2 versions",
88
"not ie <= 8"
9-
]
9+
],
10+
"node": "8"
1011
}
1112
}],
12-
"stage-2"
13+
"stage-2"
1314
],
1415
"plugins": [
15-
["babel-plugin-root-import", [
16+
[
17+
"babel-plugin-root-import",
18+
[
1619
{
1720
"rootPathPrefix": "~",
1821
"rootPathSuffix": "."
@@ -21,6 +24,14 @@
2124
"rootPathPrefix": "@",
2225
"rootPathSuffix": "client"
2326
}
24-
]]
27+
]
28+
],
29+
[
30+
"transform-runtime",
31+
{
32+
"polyfill": false,
33+
"regenerator": true
34+
}
35+
]
2536
]
2637
}

template/.eslintrc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
"devDependencies": [
2323
"test/**/*.js",
2424
"test/**/*.js",
25-
"gulp-tasks/**/*.js"
25+
"gulp-tasks/**/*.js",
26+
"jest.config.js",
27+
"jest.plugins.js"
2628
]
2729
}
2830
],
@@ -35,6 +37,7 @@
3537
"expect": true,
3638
"assert": true,
3739
"require": true,
38-
"request": true
40+
"request": true,
41+
"jest": true
3942
}
4043
}

template/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@
3333
$ npm run dev
3434
```
3535

36+
## Debug
37+
38+
```
39+
$ DEBUG=loopback npm run dev
40+
```
41+
42+
[More info...](https://loopback.io/doc/en/lb3/Setting-debug-strings.html)
43+
3644
## Build to ./build
3745

3846
```

template/gulp-tasks/build.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@ import {argv} from 'yargs';
1515
import {dirs, extended} from './config';
1616
import {customSass} from './compilers';
1717

18-
gulp.task('build:test', () => gulp.src([
19-
path.resolve(dirs.test, '**/*.test.js'),
20-
path.resolve(dirs.test, 'config.js'),
21-
])
22-
.pipe(sourcemaps.init())
23-
.pipe(babel())
24-
.pipe(sourcemaps.write())
25-
.pipe(gulp.dest(dirs.buildTest)));
26-
2718
gulp.task('build:client', ['copy:client', 'copy:config:server'], () => {
2819
// Node modules to be included in babel transpilation
2920
// Use this with ES6 modules for example
@@ -148,7 +139,6 @@ gulp.task('build:index', () => {
148139
});
149140

150141
gulp.task('build', [
151-
'build:test',
152142
'build:client',
153143
'build:common',
154144
'build:server',

template/gulp-tasks/tasks.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
import './serve';
33
import './default';
44
import './build';
5-
import './test';
65
import './copy';

template/gulp-tasks/test.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

template/package.json

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@
1010
"dev": "gulp serve",
1111
"build": "gulp build --production && npm run afterbuild",
1212
"afterbuild": "cd build && npm install --production",
13-
"test": "gulp test",
14-
"test:server": "gulp test:server",
15-
"test:client": "gulp test:client",
16-
"start": "(type ./build/index.js && node ./build/index.js) || node ./index.js ",
17-
"vulnerabilities": "nsp check"
13+
"test": "npx jest --runInBand test/server/**.spec.js && npx jest test/client/**.spec.js",
14+
"start": "node ./index.js"
1815
},
1916
"dependencies": {
2017
"compression": "^1.0.3",
@@ -24,7 +21,7 @@
2421
"express": "^4.16.2",
2522
"express-history-api-fallback": "^2.2.1",
2623
"loopback": "^3.16.2",
27-
"loopback-boot": "^2.27.0",
24+
"loopback-boot": "github:klarkc/loopback-boot#master",
2825
"loopback-component-explorer": "^4.0.0",
2926
"serve-favicon": "^2.0.1",
3027
"strong-error-handler": "^2.0.0",
@@ -47,18 +44,18 @@
4744
},
4845
"devDependencies": {
4946
"aliasify": "^2.1.0",
50-
"babel-core": "^6.25.0",
47+
"babel-core": "^6.26.3",
5148
"babel-eslint": "^8.2.2",
49+
"babel-jest": "^23.0.1",
50+
"regenerator-runtime": "^0.11.1",
51+
"supertest": "^3.1.0",
5252
"babel-plugin-transform-runtime": "^6.23.0",
5353
"babel-preset-env": "^1.6.1",
5454
"babel-preset-stage-2": "^6.24.1",
5555
"babelify": "^7.3.0",
5656
"browserify": "^14.4.0",
5757
"browserify-global-shim": "^1.0.3",
58-
"chai": "^4.1.0",
59-
"chai-http": "^3.0.0",
6058
"css-modulesify": "^0.28.0",
61-
"babel-eslint": "^8.2.2",
6259
"eslint": "^4.15.0",
6360
"eslint-config-airbnb-base": "^11.3.0",
6461
"eslint-plugin-import": "^2.9.0",
@@ -68,34 +65,37 @@
6865
"gulp-autoprefixer": "^4.0.0",
6966
"gulp-babel": "^6.1.2",
7067
"gulp-connect": "^5.0.0",
71-
"gulp-mocha": "^4.3.1",
7268
"gulp-sourcemaps": "^2.6.0",
73-
"karma": "^1.7.1",
74-
"karma-browserify": "^5.1.1",
75-
"karma-chai": "^0.1.0",
76-
"karma-mocha": "^1.3.0",
77-
"karma-chrome-launcher": "^2.2.0",
78-
"loopback-chai": "^2.3.0",
79-
"mocha": "^3.4.2",
80-
"sinon": "^2.3.8",
69+
"jest": "^22.4.4",
70+
"jest-plugins": "^2.9.0",
71+
"jest-preset-loopback": "^1.0.0",
72+
"loopback-jest": "^1.3.0",
73+
"supertest": "^3.1.0",
8174
"tfilter": "^1.0.1",
8275
"through2": "^2.0.3",
8376
"tmp": "0.0.33",
8477
"vinyl-buffer": "^1.0.0",
8578
"vinyl-source-stream": "^1.1.0",
79+
"vue-jest": "^2.6.0",
80+
"vue-test-utils": "^1.0.0-beta.11",
8681
"vueify": "^9.4.1",
8782
"yargs": "^10.0.3",
8883
"babel-plugin-root-import": "^5.1.0",
8984
"connect-history-api-fallback": "^1.5.0",
9085
"node-sass": "^4.6.0",
91-
"nsp": "^2.1.0",
9286
"gulp-util": "^3.0.8",
9387
"babel-register": "^6.26.0"
9488
},
9589
"repository": {
9690
"type": "",
9791
"url": ""
9892
},
93+
"jest": {
94+
"projects": [
95+
"<rootDir>/test/server",
96+
"<rootDir>/test/client"
97+
]
98+
},
9999
"license": "UNLICENSED",
100100
"description": "{{ description }}"{{#extended}},
101101
"extended": true

template/server/server.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import boot from 'loopback-boot';
33

44
const app = loopback();
55

6+
const options = {
7+
appRootDir: __dirname,
8+
// File Extensions for jest (strongloop/loopback#3204)
9+
scriptExtensions: ['.js', '.json', '.node', '.ejs'],
10+
};
11+
612
let httpServer;
713

814
app.start = function() {
@@ -25,7 +31,7 @@ app.close = function() {
2531

2632
// Bootstrap the application, configure models, datasources and middleware.
2733
// Sub-apps like REST API are mounted via boot scripts.
28-
boot(app, __dirname, (err) => {
34+
boot(app, options, (err) => {
2935
if (err) throw err;
3036

3137
// start the server if `$ node server.js`

template/test/.eslintrc

Lines changed: 0 additions & 11 deletions
This file was deleted.

template/test/client/app.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ describe('App.vue', () => {
4040

4141
{{#extended}}
4242
it('should render router component', () => {
43-
expect(vm.$el.innerHTML).to.equal('mocked component');
44-
expect(vm.$el.getAttribute('id')).to.equal('app');
43+
expect(vm.$el.innerHTML).toEqual('mocked component');
44+
expect(vm.$el.getAttribute('id')).toEqual('app');
4545
});
4646
{{else}}
4747
it('should render correct content', () => {
4848
const newVm = new Constructor().$mount();
4949
return Vue.nextTick().then(() => {
50-
expect(newVm.$el.innerHTML).to.equal('Hello World!');
50+
expect(newVm.$el.innerHTML).toEqual('Hello World!');
5151
});
5252
});
5353
{{/extended}}
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
import Vue from 'vue';
1+
import {mount} from 'vue-test-utils';
22
import HelloWorld from '@/components/HelloWorld/HelloWorld.vue';
33

44
describe('HelloWorld.vue', () => {
5-
const Constructor = Vue.extend(HelloWorld);
5+
const wrapper = mount(HelloWorld);
66

77
it('should render correct content', () => {
8-
const vm = new Constructor().$mount();
9-
return Vue.nextTick().then(() => {
10-
expect(vm.$el.innerHTML).to.include(
11-
'Hello World! This content is restricted.'
12-
);
13-
});
8+
expect(wrapper.html()).toContain(
9+
'Hello World! This content is restricted.'
10+
);
1411
});
1512
});

template/test/client/jest.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
moduleFileExtensions: [
3+
'js',
4+
'json',
5+
'vue',
6+
],
7+
transform: {
8+
'^.+\\.js$': 'babel-jest',
9+
'^.+\\.vue$': 'vue-jest',
10+
},
11+
};

0 commit comments

Comments
 (0)