From 894f6031faa36049b1f5a16016fac56c0b508614 Mon Sep 17 00:00:00 2001 From: wanlei Date: Thu, 26 Oct 2017 21:28:55 +0800 Subject: [PATCH] update: [BUG] wired bug for 'validator' --- .gitignore | 3 +- package.json | 20 ++++++++++- test/.eslintrc | 12 +++++++ test/index.js | 13 +++++++ test/karma.conf.js | 74 +++++++++++++++++++++++++++++++++++++++ test/specs/Button.spec.js | 14 ++++++++ 6 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 test/.eslintrc create mode 100644 test/index.js create mode 100644 test/karma.conf.js create mode 100644 test/specs/Button.spec.js diff --git a/.gitignore b/.gitignore index 00cbbdf53..6cbb08205 100644 --- a/.gitignore +++ b/.gitignore @@ -56,4 +56,5 @@ typings/ # dotenv environment variables file .env - +.idea +.DS_Store diff --git a/package.json b/package.json index e953784ea..52f8aef48 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "start": "NODE_ENV=development webpack-dev-server --open --hot", - "test": "echo \"Error: no test specified\" && exit 1", + "test": "karma start test/karma.conf.js --single-run", "lint": "eslint -c ./.eslintrc --fix --ext .js ./src/", "lint:style": "stylelint \"./src/**/*.less\" --syntax less" }, @@ -30,17 +30,35 @@ "babel-cli": "^6.26.0", "babel-helper-vue-jsx-merge-props": "^2.0.2", "babel-loader": "^7.1.2", + "babel-plugin-istanbul": "^4.1.1", "babel-plugin-syntax-jsx": "^6.18.0", "babel-plugin-transform-vue-jsx": "^3.5.0", "babel-preset-env": "^1.6.0", + "chai": "^4.1.2", "css-loader": "^0.28.7", "eslint": "^4.7.2", "eslint-plugin-html": "^3.2.2", "eslint-plugin-vue-libs": "^1.2.1", "html-webpack-plugin": "^2.30.1", + "istanbul-instrumenter-loader": "^3.0.0", + "karma": "^1.4.1", + "karma-coverage": "^1.1.1", + "karma-coverage-istanbul-reporter": "^1.3.0", + "karma-mocha": "^1.3.0", + "karma-phantomjs-launcher": "^1.0.2", + "karma-phantomjs-shim": "^1.4.0", + "karma-sinon-chai": "^1.3.1", + "karma-sourcemap-loader": "^0.3.7", + "karma-spec-reporter": "0.0.31", + "karma-webpack": "^2.0.2", "less": "^2.7.2", "less-loader": "^4.0.5", + "mocha": "^3.2.0", "pre-commit": "^1.2.2", + "selenium-server": "^3.0.1", + "semver": "^5.3.0", + "sinon": "^4.0.2", + "sinon-chai": "^2.8.0", "style-loader": "^0.18.2", "stylelint": "^8.1.1", "stylelint-config-standard": "^17.0.0", diff --git a/test/.eslintrc b/test/.eslintrc new file mode 100644 index 000000000..009f94936 --- /dev/null +++ b/test/.eslintrc @@ -0,0 +1,12 @@ +{ + "extends": ["plugin:vue-libs/recommended"], // ,"plugin:vue-libs/recommended" + "rules": { + "comma-dangle": [2, "always-multiline"], + "no-var": "error" + }, + "globals": { + "it": true, + "describe": true, + "expect": true + } +} diff --git a/test/index.js b/test/index.js new file mode 100644 index 000000000..26d0ce27a --- /dev/null +++ b/test/index.js @@ -0,0 +1,13 @@ +import Vue from 'vue' + +Vue.config.productionTip = false + +// require all test files (files that ends with .spec.js) +const testsContext = require.context('./specs', true, /\.spec$/) +testsContext.keys().forEach(testsContext) + +// require all src files except main.js for coverage. +// you can also change this to match only the subset of files that +// you want coverage for. +const srcContext = require.context('../components', true, /^\.(\.js|\.vue)?$/) +srcContext.keys().forEach(srcContext) diff --git a/test/karma.conf.js b/test/karma.conf.js new file mode 100644 index 000000000..14eae52a2 --- /dev/null +++ b/test/karma.conf.js @@ -0,0 +1,74 @@ +// This is a karma config file. For more details see +// http://karma-runner.github.io/0.13/config/configuration-file.html +// we are also using it with karma-webpack +// https://github.com/webpack/karma-webpack + +const webpack = require('webpack') +const webpackConfig = require('../webpack.config') + +module.exports = function (config) { + config.set({ + // to run in additional browsers: + // 1. install corresponding karma launcher + // http://karma-runner.github.io/0.13/config/browsers.html + // 2. add it to the `browsers` array below. + browsers: ['PhantomJS'], + frameworks: ['mocha', 'sinon-chai'], + reporters: ['spec', 'coverage-istanbul'], + files: ['./index.js'], + preprocessors: { + './index.js': ['webpack', 'sourcemap', 'coverage'], + }, + webpack: { + module: { + rules: [ + { + test: /\.vue$/, + loader: 'vue-loader', + options: { + 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 }, + }, + ], + }, + ], + }, + }, + webpackMiddleware: { + noInfo: true, + }, + coverageReporter: { + dir: './coverage', + reporters: [ + { type: 'text-summary' }, + ], + }, + }) +} diff --git a/test/specs/Button.spec.js b/test/specs/Button.spec.js new file mode 100644 index 000000000..33564af39 --- /dev/null +++ b/test/specs/Button.spec.js @@ -0,0 +1,14 @@ +import Vue from 'vue' +import Button from '../../components/button' + +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) + }) +})