Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support jest runner #176

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,29 @@ module.exports = {
},
"unit": {
"type": "confirm",
"message": "Setup unit tests with Karma + Mocha?"
"message": "Set up unit tests"
},
"runner": {
"when": "unit",
"type": "list",
"message": "Pick a test runner",
"choices": [
{
name: 'Jest',
value: 'jest',
short: 'jest',
},
{
name: 'Karma and Mocha',
value: 'karma',
short: 'karma',
},
{
name: 'none (configure it yourself)',
value: 'noTest',
short: 'noTest',
}
]
},
"e2e": {
"type": "confirm",
Expand All @@ -89,7 +111,12 @@ module.exports = {
".eslintignore": "lint",
"config/test.env.js": "unit || e2e",
"test/unit/**/*": "unit",
"build/webpack.test.conf.js": "unit",
"build/webpack.test.conf.js": "unit && runner === 'karma'",
'test/unit/index.js': "unit && runner === 'karma'",
'test/unit/jest.conf.js': "unit && runner === 'jest'",
'test/unit/karma.conf.js': "unit && runner === 'karma'",
'test/unit/specs/index.js': "unit && runner === 'karma'",
'test/unit/setup.js': "unit && runner === 'jest'",
"test/e2e/**/*": "e2e",
"src/router/**/*": "router"
},
Expand Down
9 changes: 5 additions & 4 deletions template/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
}],
"stage-2"
],
"plugins": ["transform-runtime"],
"plugins": ["transform-runtime"]{{#if_or unit e2e}},
"env": {
"test": {
"presets": ["env", "stage-2"],
"plugins": [ "istanbul" ]
"presets": ["env", "stage-2"]{{#if_eq runner "karma"}},
"plugins": ["istanbul"]{{/if_eq}}{{#if_eq runner "jest"}},
"plugins": ["transform-es2015-modules-commonjs", "dynamic-import-node"]{{/if_eq}}
}
}
}{{/if_or}}
}
34 changes: 27 additions & 7 deletions template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@
"scripts": {
"dev": "node build/dev-server.js",
"start": "node build/dev-server.js",
"build": "node build/build.js"{{#unit}},
"unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run"{{/unit}}{{#e2e}},
"e2e": "node test/e2e/runner.js"{{/e2e}}{{#if_or unit e2e}},
"test": "{{#unit}}npm run unit{{/unit}}{{#unit}}{{#e2e}} && {{/e2e}}{{/unit}}{{#e2e}}npm run e2e{{/e2e}}"{{/if_or}}{{#lint}},
"lint": "eslint --ext .js,.vue src{{#unit}} test/unit/specs{{/unit}}{{#e2e}} test/e2e/specs{{/e2e}}"{{/lint}}
{{#if_eq runner "jest"}}
"unit": "jest --config test/unit/jest.conf.js --coverage",
{{/if_eq}}
{{#if_eq runner "karma"}}
"unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run",
{{/if_eq}}
{{#e2e}}
"e2e": "node test/e2e/runner.js",
{{/e2e}}
{{#if_or unit e2e}}
"test": "{{#unit}}npm run unit{{/unit}}{{#unit}}{{#e2e}} && {{/e2e}}{{/unit}}{{#e2e}}npm run e2e{{/e2e}}",
{{/if_or}}
{{#lint}}
"lint": "eslint --ext .js,.vue src{{#unit}} test/unit{{/unit}}{{#e2e}} test/e2e/specs{{/e2e}}",
{{/lint}}
"build": "node build/build.js"
},
"dependencies": {
"vue": "^2.5.2"{{#router}},
Expand Down Expand Up @@ -59,7 +70,16 @@
"html-webpack-plugin": "^2.30.1",
"http-proxy-middleware": "^0.17.4",
"webpack-bundle-analyzer": "^2.9.0",
{{#unit}}
{{#if_eq runner "jest"}}
"babel-jest": "^21.0.2",
"babel-plugin-dynamic-import-node": "^1.2.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
"jest": "^22.0.4",
"jest-serializer-vue": "^0.3.0",
"vue-jest": "^1.0.2",
"jest-transform-stub": "^1.0.0",
{{/if_eq}}
{{#if_eq runner "karma"}}
"cross-env": "^5.0.5",
"karma": "^1.7.1",
"karma-coverage": "^1.1.1",
Expand All @@ -77,7 +97,7 @@
"inject-loader": "^3.0.1",
"babel-plugin-istanbul": "^4.1.5",
"phantomjs-prebuilt": "^2.1.15",
{{/unit}}
{{/if_eq}}
{{#e2e}}
"chromedriver": "^2.33.1",
"cross-spawn": "^5.1.0",
Expand Down
33 changes: 33 additions & 0 deletions template/test/unit/jest.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const path = require('path')

module.exports = {
rootDir: path.resolve(__dirname, '../../'),
moduleFileExtensions: [
'js',
'json',
'vue'
],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1'
},
transform: {
'^.+\\.js$': '<rootDir>/node_modules/babel-jest',
'.*\\.(vue)$': '<rootDir>/node_modules/vue-jest',
'.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub'
},{{#e2e}}
testPathIgnorePatterns: [
'<rootDir>/test/e2e'
],{{/e2e}}
snapshotSerializers: ['<rootDir>/node_modules/jest-serializer-vue'],
setupFiles: ['<rootDir>/test/unit/setup'],
mapCoverage: true,
coverageDirectory: '<rootDir>/test/unit/coverage',
collectCoverageFrom: [
'src/**/*.{js,vue}',
'!src/main.js',
{{#router}}
'!src/router/index.js',
{{/router}}
'!**/node_modules/**'
]
}
3 changes: 3 additions & 0 deletions template/test/unit/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Vue from 'vue'

Vue.config.productionTip = false
2 changes: 1 addition & 1 deletion template/test/unit/specs/Hello.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ describe('Hello.vue', () => {
const Constructor = Vue.extend(Hello){{#if_eq lintConfig "airbnb"}};{{/if_eq}}
const vm = new Constructor().$mount(){{#if_eq lintConfig "airbnb"}};{{/if_eq}}
expect(vm.$el.querySelector('.hello h1').textContent)
.to.equal('Welcome to Your Vue.js PWA'){{#if_eq lintConfig "airbnb"}};{{/if_eq}}
{{#if_eq runner "karma"}}.to.equal('Welcome to Your Vue.js PWA'){{/if_eq}}{{#if_eq runner "jest"}}.toEqual('Welcome to Your Vue.js PWA'){{/if_eq}}{{#if_eq lintConfig "airbnb"}};{{/if_eq}}
}){{#if_eq lintConfig "airbnb"}};{{/if_eq}}
}){{#if_eq lintConfig "airbnb"}};{{/if_eq}}