diff --git a/.eslintignore b/.eslintignore index c2658d7d1..393d5170e 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ node_modules/ +**/*.spec.* diff --git a/components/button/__test__/Button.spec.js b/components/button/__test__/Button.spec.js new file mode 100644 index 000000000..11a4da016 --- /dev/null +++ b/components/button/__test__/Button.spec.js @@ -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) + }) +}) diff --git a/package-lock.json b/package-lock.json index e42d65267..0b26ccf47 100644 --- a/package-lock.json +++ b/package-lock.json @@ -229,7 +229,7 @@ }, "abbrev": { "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=", "dev": true }, @@ -753,7 +753,7 @@ }, "babel-core": { "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=", "dev": true, "requires": { @@ -780,8 +780,9 @@ "dependencies": { "debug": { "version": "2.6.9", - "resolved": "http://registry.npm.taobao.org/debug/download/debug-2.6.9.tgz", - "integrity": "sha1-XRKFFd8TT/Mn6QpMk/Tgd6U2NB8=", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, "requires": { "ms": "2.0.0" } @@ -1464,8 +1465,8 @@ }, "babel-preset-env": { "version": "1.6.1", - "resolved": "http://registry.npm.taobao.org/babel-preset-env/download/babel-preset-env-1.6.1.tgz", - "integrity": "sha1-oYtWTMm5r99KrleuPBsNmRiOb0g=", + "resolved": "https://registry.npmjs.org/babel-preset-env/-/babel-preset-env-1.6.1.tgz", + "integrity": "sha512-W6VIyA6Ch9ePMI7VptNn2wBM6dbG0eSz25HEiL40nQXCsXGTGZSTZu1Iap+cj3Q0S5a7T9+529l/5Bkvd+afNA==", "dev": true, "requires": { "babel-plugin-check-es2015-constants": "6.22.0", @@ -2970,6 +2971,16 @@ "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": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", @@ -8277,7 +8288,7 @@ }, "istanbul": { "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=", "dev": true, "requires": { @@ -8318,7 +8329,7 @@ }, "supports-color": { "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=", "dev": true, "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": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/karma-coverage/-/karma-coverage-1.1.1.tgz", diff --git a/package.json b/package.json index 0c636fd5d..bf25d6c9f 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ ], "scripts": { "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", "copy": "node scripts/run.js copy-html", "compile": "node antd-tools/cli/run.js compile", @@ -77,6 +77,7 @@ "cheerio": "^1.0.0-rc.2", "colorful": "^2.1.0", "commander": "^2.15.0", + "cross-env": "^5.1.4", "css-loader": "^0.28.7", "deep-assign": "^2.0.0", "eslint": "^4.7.2", @@ -93,6 +94,7 @@ "istanbul-instrumenter-loader": "^3.0.0", "jsonp": "^0.2.1", "karma": "^1.4.1", + "karma-babel-preprocessor": "^7.0.0", "karma-coverage": "^1.1.1", "karma-coverage-istanbul-reporter": "^1.3.0", "karma-mocha": "^1.3.0", @@ -161,4 +163,4 @@ "vue-types": "^1.0.2", "warning": "^3.0.0" } -} +} \ No newline at end of file diff --git a/test/.eslintrc b/test/.eslintrc index 009f94936..07c38eaad 100644 --- a/test/.eslintrc +++ b/test/.eslintrc @@ -1,12 +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 - } -} + "extends": ["plugin:vue-libs/recommended"], + "rules": { + "comma-dangle": [2, "always-multiline"], + "no-var": "error" + }, + "globals": { + "it": true, + "describe": true, + "expect": true + } +} \ No newline at end of file diff --git a/test/index.js b/test/index.js index 72af3af11..a803d9e1e 100644 --- a/test/index.js +++ b/test/index.js @@ -1,14 +1,14 @@ -import 'babel-polyfill' + 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$/) +const testsContext = require.context(`../components/${process.env.SCOPE}`, 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)?$/) +const srcContext = require.context(`../components`, true, /^\.(\.js|\.jsx)?$/) srcContext.keys().forEach(srcContext) diff --git a/test/karma.conf.js b/test/karma.conf.js index 14eae52a2..871b70534 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -5,7 +5,10 @@ const webpack = require('webpack') 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) { config.set({ // to run in additional browsers: @@ -14,61 +17,34 @@ module.exports = function (config) { // 2. add it to the `browsers` array below. browsers: ['PhantomJS'], frameworks: ['mocha', 'sinon-chai'], - reporters: ['spec', 'coverage-istanbul'], + reporters: ['spec', 'coverage'], 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', - }, + webpack: merge( + { + plugins: [ + new webpack.DefinePlugin({ + 'process.env': { + NODE_ENV: '"testing"', + SCOPE: `"${scope}"`, }, - }, - { - 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: { noInfo: true, }, coverageReporter: { dir: './coverage', reporters: [ + { type: 'lcov', subdir: '.' }, { type: 'text-summary' }, ], + includeAllSources: false, }, }) }