From 8cfde38102918f741afc869f8018229b3180fabe Mon Sep 17 00:00:00 2001 From: Icebob Date: Fri, 6 May 2016 11:04:36 +0200 Subject: [PATCH] Create test environment --- .eslintrc.js | 3 +- .gitignore | 9 +++-- package.json | 39 +++++++++++++++++- test/unit/index.js | 11 ++++++ test/unit/karma.conf.js | 48 ++++++++++++++++++++++ test/unit/specs/test.spec.js | 18 +++++++++ test/unit/webpack.test.config.js | 68 ++++++++++++++++++++++++++++++++ 7 files changed, 190 insertions(+), 6 deletions(-) create mode 100644 test/unit/index.js create mode 100644 test/unit/karma.conf.js create mode 100644 test/unit/specs/test.spec.js create mode 100644 test/unit/webpack.test.config.js diff --git a/.eslintrc.js b/.eslintrc.js index cc08e5ad..3f9e3195 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,4 +1,5 @@ module.exports = { + root: true, "env": { "browser": true, "commonjs": true, @@ -10,7 +11,7 @@ module.exports = { "sourceType": "module" }, "plugins": [ - "vue" + "html" ], "rules": { "indent": [ diff --git a/.gitignore b/.gitignore index f8d83f47..3781f9b4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ -/node_modules -/test/specs.js -.DS_Store \ No newline at end of file +.DS_Store +node_modules/ +npm-debug.log +selenium-debug.log +test/unit/coverage +test/e2e/reports \ No newline at end of file diff --git a/package.json b/package.json index d2084969..3529505c 100644 --- a/package.json +++ b/package.json @@ -2,12 +2,17 @@ "name": "vue-form-generator", "version": "0.1.0", "description": "A schema-based form generator component for Vue.js", + "homepage": "https://github.com/icebob/vue-form-generator", "main": "dist/vue-form-generator.js", "scripts": { "build": "webpack --config webpack.build.config.js", "dev": "webpack-dev-server --config webpack.dev.config.js --inline --hot --content-base dev/", "lint": "eslint --ext=.js,.vue src", - "test": "webpack --config test/webpack.config.js" + "coverage": "set TEST_TYPE=coverage & karma start karma.config.js", + "unit": "karma start test/unit/karma.conf.js --single-run", + "e2e": "node test/e2e/runner.js", + "test": "npm run lint && npm run unit && npm run e2e", + "ci": "karma start test/unit/karma.conf.js --auto-watch --no-single-run --reporters=dots" }, "keywords": [ "vue", @@ -17,25 +22,54 @@ "schema", "json" ], + "files": [ + "dist/vue-form-generator.js", + "dist/vue-form-generator.min.js", + "src" + ], "author": "Icebob", "license": "MIT", "devDependencies": { "babel-core": "6.7.7", "babel-loader": "6.2.4", + "babel-plugin-espower": "2.1.2", "babel-plugin-transform-runtime": "6.7.5", "babel-preset-es2015": "6.6.0", "babel-preset-stage-0": "6.5.0", "babel-runtime": "5.8.38", + "chai": "3.5.0", "css-loader": "0.23.1", "eslint": "2.9.0", + "eslint-friendly-formatter": "2.0.4", + "eslint-loader": "1.3.0", + "eslint-plugin-html": "1.4.0", "eslint-plugin-vue": "0.1.1", "faker": "3.1.0", + "inject-loader": "2.0.1", + "isparta-loader": "2.0.0", "jade": "1.11.0", "jade-loader": "0.8.0", + "karma": "0.13.9", + "karma-chai": "0.1.0", + "karma-chrome-launcher": "1.0.1", + "karma-coverage": "0.5.5", + "karma-mocha": "0.2.2", + "karma-phantomjs-launcher": "1.0.0", + "karma-sinon-chai": "1.2.0", + "karma-sourcemap-loader": "0.3.7", + "karma-spec-reporter": "0.0.26", + "karma-webpack": "1.7.0", "lodash": "4.11.1", + "lolex": "1.4.0", + "mocha": "2.4.5", + "mocha-generators": "1.2.0", + "mocha-loader": "0.7.1", "moment": "2.13.0", "node-sass": "3.6.0", + "phantomjs-prebuilt": "2.1.3", "sass-loader": "3.2.0", + "sinon": "1.17.4", + "sinon-chai": "2.8.0", "style-loader": "0.13.1", "vue": "1.0.21", "vue-hot-reload-api": "1.3.2", @@ -43,7 +77,8 @@ "vue-loader": "8.2.3", "vue-style-loader": "1.0.0", "webpack": "1.13.0", - "webpack-dev-server": "1.14.1" + "webpack-dev-server": "1.14.1", + "webpack-merge": "0.12.0" }, "dependencies": { "joi": "8.0.5", diff --git a/test/unit/index.js b/test/unit/index.js new file mode 100644 index 00000000..5e7c8941 --- /dev/null +++ b/test/unit/index.js @@ -0,0 +1,11 @@ +// require all test files (files that ends with .spec.js) +var 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. +var srcContext = require.context('../../src', true, /^\.\/(?!main(\.js)?$)/) +srcContext.keys().forEach(srcContext) +*/ \ No newline at end of file diff --git a/test/unit/karma.conf.js b/test/unit/karma.conf.js new file mode 100644 index 00000000..85f9b8f3 --- /dev/null +++ b/test/unit/karma.conf.js @@ -0,0 +1,48 @@ +var wsConfig = require('./webpack.test.config'); + +module.exports = function(config) { + var settings = { + // base path that will be used to resolve all patterns (eg. files, exclude) + basePath: '', + + browsers: ['PhantomJS'], + + reporters: ['spec', 'coverage'], + + frameworks: ['mocha', 'chai'/*, 'sinon-chai'*/], + + files: ['./index.js'], + + exclude: [], + + preprocessors: { + './index.js': ['webpack', 'sourcemap'] + }, + + webpack: wsConfig, + + webpackMiddleware: { + noInfo: true + }, + + port: 9876, + + colors: true, + + logLevel: config.LOG_INFO, + + autoWatch: false, + + singleRun: true, + + coverageReporter: { + dir: './coverage', + reporters: [ + { type: 'lcov', subdir: '.' }, + { type: 'text-summary' } + ] + } + } + + config.set(settings); +} \ No newline at end of file diff --git a/test/unit/specs/test.spec.js b/test/unit/specs/test.spec.js new file mode 100644 index 00000000..c37cf7dc --- /dev/null +++ b/test/unit/specs/test.spec.js @@ -0,0 +1,18 @@ +import { expect } from "chai"; + +import VueFormGenerator from "src/index"; + +describe("VueFormGenerator", () => { + + it("class properties", () => { + + expect(true).to.be.true; + + expect(VueFormGenerator).to.be.exist; + expect(VueFormGenerator).to.have.property("component"); + expect(VueFormGenerator).to.have.property("schema"); + expect(VueFormGenerator).to.have.property("validators"); + + }); + +}) \ No newline at end of file diff --git a/test/unit/webpack.test.config.js b/test/unit/webpack.test.config.js new file mode 100644 index 00000000..c8823c14 --- /dev/null +++ b/test/unit/webpack.test.config.js @@ -0,0 +1,68 @@ +var path = require("path"); +var webpack = require('webpack'); + +module.exports = { + devtool: '#inline-source-map', + + module: { + loaders: [ + { + "test": /\.js?$/, + "exclude": /node_modules/, + "loader": "babel", + "query": { + "presets": [ + "es2015", + "stage-0" + ], + "plugins": [] + } + }, + { + "test": /\.css?$/, + "loader": "style!css" + }, + { + "test": /\.scss?$/, + "loader": "style!css!sass" + }, + { + "test": /\.jade?$/, + "loader": "jade" + }, + { + "test": /\.vue?$/, + "loader": "vue" + }, + { + test: /\.(woff2?|svg)$/, + loader: 'url' + //loader: 'url?limit=10000' + }, + { + test: /\.(ttf|eot)$/, + loader: 'url' + } + ] + }, + + resolve: { + packageAlias: 'browser', + alias: { + 'src': path.resolve(__dirname, '../../src') + } + }, + + plugins: [ + ], + + vue: { + autoprefixer: { + browsers: ['last 2 versions'] + }/*, + loaders: { + js: 'isparta' + }*/ + } + +};