Skip to content

Commit a488810

Browse files
committed
feat(test): add support for client tests with karma
1 parent 3043ea6 commit a488810

File tree

8 files changed

+54
-18
lines changed

8 files changed

+54
-18
lines changed

template/gulp-tasks/build.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,6 @@ import source from 'vinyl-source-stream';
1010
import buffer from 'vinyl-buffer';
1111
import {dirs} from './config.js';
1212

13-
gulp.task('build:test', () => {
14-
return gulp.src([
15-
path.resolve(dirs.test, '**/*.test.js'),
16-
path.resolve(dirs.test, 'config.js'),
17-
])
18-
.pipe(sourcemaps.init())
19-
.pipe(babel())
20-
.pipe(sourcemaps.write())
21-
.pipe(gulp.dest(dirs.buildTest));
22-
});
23-
2413
gulp.task('build:client', ['copy:client'], () => {
2514
let b = browserify({
2615
entries: path.resolve(dirs.srcClient, 'main.js'),
@@ -70,7 +59,6 @@ gulp.task('build:server', () => {
7059
});
7160

7261
gulp.task('build', [
73-
'build:test',
7462
'build:client',
7563
'build:common',
7664
'build:server',

template/gulp-tasks/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ dirs.buildClient = path.resolve(dirs.root, dirs.build, 'client');
88
dirs.buildServer = path.resolve(dirs.root, dirs.build, 'server');
99
dirs.buildCommon = path.resolve(dirs.root, dirs.build, 'common');
1010
dirs.test = path.resolve(dirs.root, 'test');
11+
dirs.testClient = path.resolve(dirs.test, 'client');
12+
dirs.testServer = path.resolve(dirs.test, 'server');
1113
dirs.srcClient = path.resolve(dirs.root, 'client');
1214
dirs.srcCommon = path.resolve(dirs.root, 'common');
1315
dirs.srcServer = path.resolve(dirs.root, 'server');

template/gulp-tasks/test.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
import gulp from 'gulp';
22
import mocha from 'gulp-mocha';
3+
import {Server} from 'karma';
34
import path from 'path';
45
import {dirs} from './config.js';
56

6-
gulp.task('test', ['build'], () => {
7-
gulp.src(path.resolve(dirs.buildTest, '**/*.test.js'))
7+
gulp.task('test:server', () => {
8+
gulp.src(path.resolve(dirs.testServer, '**/*.test.js'))
89
.pipe(mocha({
910
compilers: 'js:babel-core/register',
10-
require: path.resolve(dirs.test, 'config.js'),
11+
require: path.resolve(dirs.test, 'mocha.conf.js'),
1112
}));
1213
});
14+
15+
gulp.task('test:client', (done) => {
16+
new Server({
17+
files: [path.resolve(dirs.testClient, '**/*.test.js')],
18+
configFile: path.resolve(dirs.test, 'karma.conf.js'),
19+
singleRun: true,
20+
}, done).start();
21+
});
22+
23+
gulp.task('test', ['test:server', 'test:client']);

template/package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
"babel-preset-es2015": "^6.24.1",
2828
"babelify": "^7.3.0",
2929
"browserify": "^14.4.0",
30-
"css-modulesify": "^0.28.0",
3130
"chai": "^4.1.0",
3231
"chai-http": "^3.0.0",
32+
"css-modulesify": "^0.28.0",
3333
"eslint": "^3.17.1",
3434
"eslint-config-loopback": "^8.0.0",
3535
"eslint-plugin-vue": "beta",
@@ -39,8 +39,13 @@
3939
"gulp-connect": "^5.0.0",
4040
"gulp-mocha": "^4.3.1",
4141
"gulp-sourcemaps": "^2.6.0",
42+
"karma": "^1.7.1",
43+
"karma-browserify": "^5.1.1",
44+
"karma-chai": "^0.1.0",
45+
"karma-mocha": "^1.3.0",
46+
"karma-phantomjs-launcher": "^1.0.4",
47+
"karma-phantomjs-shim": "^1.5.0",
4248
"mocha": "^3.4.2",
43-
"nsp": "^2.1.0",
4449
"sinon": "^2.3.8",
4550
"vinyl-buffer": "^1.0.0",
4651
"vinyl-source-stream": "^1.1.0",

template/test/.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"globals": {
66
"expect": true,
77
"assert": true,
8-
"request": true
8+
"request": true,
9+
"sinon": true
910
}
1011
}

template/test/client/app.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Vue from 'vue';
2+
import App from '../../client/App.vue';
3+
4+
describe('App.vue', () => {
5+
const Constructor = Vue.extend(App);
6+
7+
it('should render correct content', () => {
8+
const vm = new Constructor().$mount();
9+
return Vue.nextTick(() => {
10+
expect(vm.$el.innerHTML).to.equal('Hello World!');
11+
});
12+
});
13+
});

template/test/karma.conf.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import babelify from 'babelify';
2+
import vueify from 'vueify';
3+
4+
export default (config) => {
5+
config.set({
6+
browsers: ['PhantomJS'],
7+
frameworks: ['browserify', 'mocha', 'chai', 'phantomjs-shim'],
8+
preprocessors: {
9+
'**/*.js': ['browserify'],
10+
},
11+
browserify: {
12+
debug: true,
13+
transform: [babelify, vueify],
14+
},
15+
});
16+
};
File renamed without changes.

0 commit comments

Comments
 (0)