Skip to content
This repository has been archived by the owner on Feb 8, 2019. It is now read-only.

Commit

Permalink
💥 breaking(test): switch jasmine to mocha
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Mar 27, 2017
1 parent 4c1d75a commit f2f7539
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 56 deletions.
2 changes: 1 addition & 1 deletion template/config/karma.base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
],
exclude: [
],
frameworks: ['jasmine'],
frameworks: ['mocha', 'phantomjs-shim'],
preprocessors: {
'../test/unit/index.js': ['webpack', 'sourcemap']
},
Expand Down
6 changes: 2 additions & 4 deletions template/config/webpack.dev.conf.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const path = require('path')
const webpack = require('webpack')
const JasmineWebpackPlugin = require('./webpack.dev.plugin')

module.exports = {
entry: './test/unit/index.js',
entry: 'mocha-loader!./test/unit/index.js',
output: {
path: path.resolve(__dirname, '/test/unit'),
filename: 'tests.js',
Expand All @@ -21,8 +20,7 @@ module.exports = {
'process.env': {
NODE_ENV: '"development"'
}
}),
new JasmineWebpackPlugin()
})
],
devtool: '#eval-source-map'
}
29 changes: 0 additions & 29 deletions template/config/webpack.dev.plugin.js

This file was deleted.

15 changes: 0 additions & 15 deletions template/config/webpack.runner.template.html

This file was deleted.

9 changes: 5 additions & 4 deletions template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,19 @@
"gitbook-cli": "^2.3.0",
{{/gitbook}}
"html-webpack-plugin": "^2.19.0",
"jasmine": "^2.5.3",
"jasmine-core": "^2.5.2",
"mocha": "^3.2.0",
"mocha-loader": "^1.1.1",
"karma": "^1.4.1",
"karma-chrome-launcher": "^2.0.0",
"karma-coverage": "^1.1.1",
{{#if_eq coverageConfig "coveralls"}}
"karma-coveralls": "^1.1.2",
{{/if_eq}}
"karma-firefox-launcher": "^1.0.0",
"karma-jasmine": "^1.1.0",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.2",
"karma-phantomjs-launcher": "^1.0.2",
"karma-phantomjs-shim": "^1.4.0",
"karma-safari-launcher": "^1.0.0",
{{#sauce}}
"karma-sauce-launcher": "^1.1.0",
Expand Down Expand Up @@ -113,7 +114,7 @@
{{#if_eq coverageConfig "codecov"}}
"coverage": "cat ./coverage/lcov.info",
{{/if_eq}}
"dev": "BABEL_ENV=test webpack-dev-server --inline --hot --open --config config/webpack.dev.conf.js",
"dev": "BABEL_ENV=test webpack-dev-server --inline --hot --open --content-base ./test/unit/ --config config/webpack.dev.conf.js",
{{#gitbook}}
"docs": "gitbook serve ./gitbook ./docs",
"docs:build": "node config/version.js && gitbook build ./gitbook ./docs",
Expand Down
5 changes: 4 additions & 1 deletion template/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"env": {
"jasmine": true
"browser": true,
"mocha": true
},
"globals": {
"waitForUpdate": true,
"nextTick": true,
"delay": true,
"assert": true,
"Vue": true
}
Expand Down
58 changes: 57 additions & 1 deletion template/test/helpers/wait-for-update.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Vue from 'vue'

// helper for async assertions.
// helper for jasmine async assertions.
//
// Use like this:
//
// vm.a = 123
Expand Down Expand Up @@ -66,3 +67,58 @@ window.waitForUpdate = initialCb => {
function timeout (n) {
return next => setTimeout(next, n)
}

// helper for mocha async assertions.
// nextTick().then(() => {
//
// Automatically waits for nextTick
// }).then(() => {
// return a promise or value to skip the wait
// })
function nextTick () {
const jobs = []
let done

const chainer = {
then (cb) {
jobs.push(cb)
return chainer
}
}

function shift (...args) {
const job = jobs.shift()
let result
try {
result = job(...args)
} catch (e) {
jobs.length = 0
done(e)
}

// wait for nextTick
if (result !== undefined) {
if (result.then) {
result.then(shift)
} else {
shift(result)
}
} else if (jobs.length) {
requestAnimationFrame(() => Vue.nextTick(shift))
}
}

// First time
Vue.nextTick(() => {
done = jobs[jobs.length - 1]
if (done.toString().slice(0, 14) !== 'function (err)') {
throw new Error('waitForUpdate chain is missing .then(done)')
}
shift()
})

return chainer
}

window.nextTick = nextTick
window.delay = time => new Promise(resolve => setTimeout(resolve, time))
2 changes: 1 addition & 1 deletion template/test/unit/add.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('$add', () => {

describe('1 + 1', () => {
it('should be 2', done => {
waitForUpdate(() => {
nextTick(() => {
assert(vm.$add(1, 1) === 2, 'You should be implemented!!')
}).then(done)
})
Expand Down
10 changes: 10 additions & 0 deletions template/test/unit/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>{{ name }} tests</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="tests.js"></script>
</head>
<body>
</body>
</html>

0 comments on commit f2f7539

Please sign in to comment.