test: add unit test

pull/22/head
tjz 7 years ago
parent 97b2041fa5
commit 5bc6a464d5

@ -1 +1,2 @@
node_modules/ node_modules/
**/*.spec.*

@ -0,0 +1,14 @@
import Vue from 'vue'
import Button from '../index'
describe('Button.vue', () => {
it('should render correct contents', () => {
const Constructor = Vue.extend(Button)
const ele = document.createElement('div')
document.body.appendChild(ele)
const vm = new Constructor({ propsData: { type: 'primary' }})
vm.$mount(ele)
expect(vm.$el.classList.contains('ant-btn-primary'))
.to.equal(true)
})
})

33
package-lock.json generated

@ -229,7 +229,7 @@
}, },
"abbrev": { "abbrev": {
"version": "1.0.9", "version": "1.0.9",
"resolved": "http://10.134.27.134:7001/abbrev/download/abbrev-1.0.9.tgz", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.0.9.tgz",
"integrity": "sha1-kbR5JYinc4wl813W9jdSovh3YTU=", "integrity": "sha1-kbR5JYinc4wl813W9jdSovh3YTU=",
"dev": true "dev": true
}, },
@ -753,7 +753,7 @@
}, },
"babel-core": { "babel-core": {
"version": "6.26.0", "version": "6.26.0",
"resolved": "http://registry.npm.taobao.org/babel-core/download/babel-core-6.26.0.tgz", "resolved": "https://registry.npmjs.org/babel-core/-/babel-core-6.26.0.tgz",
"integrity": "sha1-rzL3izGm/O8RnIew/Y2XU/A6C7g=", "integrity": "sha1-rzL3izGm/O8RnIew/Y2XU/A6C7g=",
"dev": true, "dev": true,
"requires": { "requires": {
@ -780,8 +780,9 @@
"dependencies": { "dependencies": {
"debug": { "debug": {
"version": "2.6.9", "version": "2.6.9",
"resolved": "http://registry.npm.taobao.org/debug/download/debug-2.6.9.tgz", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha1-XRKFFd8TT/Mn6QpMk/Tgd6U2NB8=", "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"dev": true,
"requires": { "requires": {
"ms": "2.0.0" "ms": "2.0.0"
} }
@ -1464,8 +1465,8 @@
}, },
"babel-preset-env": { "babel-preset-env": {
"version": "1.6.1", "version": "1.6.1",
"resolved": "http://registry.npm.taobao.org/babel-preset-env/download/babel-preset-env-1.6.1.tgz", "resolved": "https://registry.npmjs.org/babel-preset-env/-/babel-preset-env-1.6.1.tgz",
"integrity": "sha1-oYtWTMm5r99KrleuPBsNmRiOb0g=", "integrity": "sha512-W6VIyA6Ch9ePMI7VptNn2wBM6dbG0eSz25HEiL40nQXCsXGTGZSTZu1Iap+cj3Q0S5a7T9+529l/5Bkvd+afNA==",
"dev": true, "dev": true,
"requires": { "requires": {
"babel-plugin-check-es2015-constants": "6.22.0", "babel-plugin-check-es2015-constants": "6.22.0",
@ -2970,6 +2971,16 @@
"sha.js": "2.4.9" "sha.js": "2.4.9"
} }
}, },
"cross-env": {
"version": "5.1.4",
"resolved": "https://registry.npmjs.org/cross-env/-/cross-env-5.1.4.tgz",
"integrity": "sha512-Mx8mw6JWhfpYoEk7PGvHxJMLQwQHORAs8+2bX+C1lGQ4h3GkDb1zbzC2Nw85YH9ZQMlO0BHZxMacgrfPmMFxbg==",
"dev": true,
"requires": {
"cross-spawn": "5.1.0",
"is-windows": "1.0.2"
}
},
"cross-spawn": { "cross-spawn": {
"version": "5.1.0", "version": "5.1.0",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz",
@ -8277,7 +8288,7 @@
}, },
"istanbul": { "istanbul": {
"version": "0.4.5", "version": "0.4.5",
"resolved": "https://registry.npm.taobao.org/istanbul/download/istanbul-0.4.5.tgz", "resolved": "https://registry.npmjs.org/istanbul/-/istanbul-0.4.5.tgz",
"integrity": "sha1-ZcfXPUxNqE1POsMQuRj7C4Azczs=", "integrity": "sha1-ZcfXPUxNqE1POsMQuRj7C4Azczs=",
"dev": true, "dev": true,
"requires": { "requires": {
@ -8318,7 +8329,7 @@
}, },
"supports-color": { "supports-color": {
"version": "3.2.3", "version": "3.2.3",
"resolved": "http://registry.npm.sogou/supports-color/download/supports-color-3.2.3.tgz", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-3.2.3.tgz",
"integrity": "sha1-ZawFBLOVQXHYpklGsq48u4pfVPY=", "integrity": "sha1-ZawFBLOVQXHYpklGsq48u4pfVPY=",
"dev": true, "dev": true,
"requires": { "requires": {
@ -8687,6 +8698,12 @@
} }
} }
}, },
"karma-babel-preprocessor": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/karma-babel-preprocessor/-/karma-babel-preprocessor-7.0.0.tgz",
"integrity": "sha512-k8YUot8ZAAYhAeUxOsOGUEXW7AlB6SkoIVGfavEBCAdGHzWuraOBoR2wCxxdePUCvcItIxSUyQnOj6DuZdEJYA==",
"dev": true
},
"karma-coverage": { "karma-coverage": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/karma-coverage/-/karma-coverage-1.1.1.tgz", "resolved": "https://registry.npmjs.org/karma-coverage/-/karma-coverage-1.1.1.tgz",

@ -23,7 +23,7 @@
], ],
"scripts": { "scripts": {
"start": "NODE_ENV=development ./node_modules/.bin/webpack-dev-server --open --hot", "start": "NODE_ENV=development ./node_modules/.bin/webpack-dev-server --open --hot",
"test": "karma start test/karma.conf.js --single-run", "test": "cross-env BABEL_ENV=test karma start test/karma.conf.js --single-run",
"site": "node scripts/run.js site-dist", "site": "node scripts/run.js site-dist",
"copy": "node scripts/run.js copy-html", "copy": "node scripts/run.js copy-html",
"compile": "node antd-tools/cli/run.js compile", "compile": "node antd-tools/cli/run.js compile",
@ -77,6 +77,7 @@
"cheerio": "^1.0.0-rc.2", "cheerio": "^1.0.0-rc.2",
"colorful": "^2.1.0", "colorful": "^2.1.0",
"commander": "^2.15.0", "commander": "^2.15.0",
"cross-env": "^5.1.4",
"css-loader": "^0.28.7", "css-loader": "^0.28.7",
"deep-assign": "^2.0.0", "deep-assign": "^2.0.0",
"eslint": "^4.7.2", "eslint": "^4.7.2",
@ -93,6 +94,7 @@
"istanbul-instrumenter-loader": "^3.0.0", "istanbul-instrumenter-loader": "^3.0.0",
"jsonp": "^0.2.1", "jsonp": "^0.2.1",
"karma": "^1.4.1", "karma": "^1.4.1",
"karma-babel-preprocessor": "^7.0.0",
"karma-coverage": "^1.1.1", "karma-coverage": "^1.1.1",
"karma-coverage-istanbul-reporter": "^1.3.0", "karma-coverage-istanbul-reporter": "^1.3.0",
"karma-mocha": "^1.3.0", "karma-mocha": "^1.3.0",
@ -161,4 +163,4 @@
"vue-types": "^1.0.2", "vue-types": "^1.0.2",
"warning": "^3.0.0" "warning": "^3.0.0"
} }
} }

@ -1,12 +1,12 @@
{ {
"extends": ["plugin:vue-libs/recommended"], // ,"plugin:vue-libs/recommended" "extends": ["plugin:vue-libs/recommended"],
"rules": { "rules": {
"comma-dangle": [2, "always-multiline"], "comma-dangle": [2, "always-multiline"],
"no-var": "error" "no-var": "error"
}, },
"globals": { "globals": {
"it": true, "it": true,
"describe": true, "describe": true,
"expect": true "expect": true
} }
} }

@ -1,14 +1,14 @@
import 'babel-polyfill'
import Vue from 'vue' import Vue from 'vue'
Vue.config.productionTip = false Vue.config.productionTip = false
// require all test files (files that ends with .spec.js) // require all test files (files that ends with .spec.js)
const testsContext = require.context('./specs', true, /\.spec$/) const testsContext = require.context(`../components/${process.env.SCOPE}`, true, /\.spec$/)
testsContext.keys().forEach(testsContext) testsContext.keys().forEach(testsContext)
// require all src files except main.js for coverage. // require all src files except main.js for coverage.
// you can also change this to match only the subset of files that // you can also change this to match only the subset of files that
// you want coverage for. // you want coverage for.
const srcContext = require.context('../components', true, /^\.(\.js|\.vue)?$/) const srcContext = require.context(`../components`, true, /^\.(\.js|\.jsx)?$/)
srcContext.keys().forEach(srcContext) srcContext.keys().forEach(srcContext)

@ -5,7 +5,10 @@
const webpack = require('webpack') const webpack = require('webpack')
const webpackConfig = require('../webpack.config') const webpackConfig = require('../webpack.config')
const merge = require('webpack-merge')
delete webpackConfig.entry
const scope = process.argv[5] || ''
console.log('scope', process.argv)
module.exports = function (config) { module.exports = function (config) {
config.set({ config.set({
// to run in additional browsers: // to run in additional browsers:
@ -14,61 +17,34 @@ module.exports = function (config) {
// 2. add it to the `browsers` array below. // 2. add it to the `browsers` array below.
browsers: ['PhantomJS'], browsers: ['PhantomJS'],
frameworks: ['mocha', 'sinon-chai'], frameworks: ['mocha', 'sinon-chai'],
reporters: ['spec', 'coverage-istanbul'], reporters: ['spec', 'coverage'],
files: ['./index.js'], files: ['./index.js'],
preprocessors: { preprocessors: {
'./index.js': ['webpack', 'sourcemap', 'coverage'], './index.js': ['webpack', 'sourcemap', 'coverage'],
}, },
webpack: { webpack: merge(
module: { {
rules: [ plugins: [
{ new webpack.DefinePlugin({
test: /\.vue$/, 'process.env': {
loader: 'vue-loader', NODE_ENV: '"testing"',
options: { SCOPE: `"${scope}"`,
loaders: {
js: 'babel-loader',
},
postLoaders: {
js: 'istanbul-instrumenter-loader?esModules=true',
},
},
},
{
test: /\.js$/,
loader: 'babel-loader', exclude: /node_modules/,
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]',
}, },
}, }),
{
test: /\.less$/,
use: [
{ loader: 'style-loader' },
{
loader: 'css-loader',
options: { sourceMap: true },
},
{ loader: 'less-loader',
options: { sourceMap: true },
},
],
},
], ],
}, },
}, webpackConfig
),
webpackMiddleware: { webpackMiddleware: {
noInfo: true, noInfo: true,
}, },
coverageReporter: { coverageReporter: {
dir: './coverage', dir: './coverage',
reporters: [ reporters: [
{ type: 'lcov', subdir: '.' },
{ type: 'text-summary' }, { type: 'text-summary' },
], ],
includeAllSources: false,
}, },
}) })
} }

Loading…
Cancel
Save