Skip to content

Commit 60c1bce

Browse files
Migrate to jest 2 (#1629)
* refactor: use jest * refactor: strip flow types when running tests with jest * refactor: update attachTo and destroy specs * refactor: continue moving to jest * refactor: update tests * refactor: update tests * refactor: update tests * refactor: continue jest migration * refactor: continue jest migration * refactor: remove sinon * refactor: update tests to use jest * refactor: update tests to use jest * refactor: add jsx plugin and update scopedSlots spec * chore: add missing deps * test: add class component and update stubs tests * test: update tests * test: migrate more tests * test: continue migration * test: refactor set methods * test: finish refactor set methods * test: refactor trigger * test: refactor wrapper-array specs * test: update config.spec.js * test: update mount specs * test: use spyOn * test: migrate tests * test: placeholder to prevent false failure * test: remove karma, sinon, chai and see what happens * test: do not use compiled dist files for tests * test: make scripts minimal * test: update import paths * chore: update circleci * chore(yarn.lock): dedupe the yarn lock file to run jest tests * chore(test/setup): remove the test setup directory The test setup directory is no longer being used * chore: remove @babel/polyfill @babel/polyfill is no longer needed as tests in browser are no longer applicable * chore(babel.config.js): set preset-env target to node current Since browser tests are no longer applicable, jest is the only tool that is actively using babel. The target can now be set to the current node environment, which in turn does not require additional polyfills (core-js, regenerator-runtime, etc) * test(setprops.spec.js): update newly added tests to Jest Update recently added watcher immediate tests to use jest assertions and mock functions over mocha chai * fix(docs/): re include vuepress build scripts to deploy docs * chore(package.json): remove webpack and mocha related dependencies These dependencies are no longer used and can be removed from the package.json * ci(unit tests): run Jest tests in single thread to prevent OOM exception Since the circle container is only 4GB, running jest tests in parallel is problematic as the container frequently runs out of memory. The memoryt can either be increased, or the tests can run in a single thread * chore(package.json): move babel dependencies to dev dependencies Babel is now only currently used by jest or systems under test. These should now be considered development dependencies * improvement(test/setup): reimplement Browser Unit Tests After converting to Jest, browser tests were removed due to capatability issues. This reimplements the browser tests with similar techniques. All related webpack/loaders have been updated to use the latest stable releases Chrome/HeadlessChrome is now being used to run these tests over the deprecated PhantomJS Karma and Jasmine are being used as a test runner while leveraging Jest's expect/assertion and mock/stubbing libraries Highly inspired by https://github.com/tom-sherman/blog/blob/master/posts/02-running-jest-tests-in-a-browser.md. 1629 * chore(scripts): re add missing build scripts Add back build scripts that were initially removed from jest migration * chore(jsdom): remove JSDOM and JSDOM-Global JSDOM and JSDOM-Global are no longer used with the removal of the mocha tests. JSDOM is still used implicitly by jest. * chore: update eslintrc * chore(karma.config.js): set singleRun to true for all runtimes Set singleRun option in karma to true locally and in CI so the test process always terminates when finished Co-authored-by: Lachlan Miller <[email protected]>
1 parent ea2a571 commit 60c1bce

File tree

101 files changed

+4263
-3659
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+4263
-3659
lines changed

Diff for: .eslintrc

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"globals": {
33
"wrapper": true,
44
"expect": true,
5-
"Element": true
5+
"Element": true,
6+
"jest": true
67
},
78
"root": true,
89
"plugins": [
@@ -13,6 +14,7 @@
1314
"plugin:flowtype/recommended"
1415
],
1516
"rules": {
17+
"template-curly-spacing" : "off",
1618
"no-debugger": 2,
1719
"no-proto": 0,
1820
"space-before-function-paren": 0,

Diff for: babel.config.js

+34-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
module.exports = {
2-
presets: ['@babel/preset-env', '@vue/babel-preset-jsx'],
1+
const defaultOptions = {
2+
presets: [
3+
[
4+
'@babel/preset-env',
5+
{
6+
targets: {
7+
node: 'current'
8+
}
9+
}
10+
],
11+
'@vue/babel-preset-jsx'
12+
],
313
plugins: [
414
'@babel/plugin-syntax-jsx',
515
'@babel/plugin-transform-flow-strip-types',
@@ -9,3 +19,25 @@ module.exports = {
919
],
1020
comments: false
1121
}
22+
23+
module.exports = api => {
24+
if (api.env('browser')) {
25+
// If running in the browser, use core-js to polyfill potentially missing functionality
26+
return {
27+
...defaultOptions,
28+
presets: [
29+
[
30+
'@babel/preset-env',
31+
{
32+
// currently, there are dependency resolution issues with older versions of vuepress. Once vuepress is upgraded, core-js can be moved to version 3
33+
corejs: 2,
34+
useBuiltIns: 'entry'
35+
}
36+
],
37+
'@vue/babel-preset-jsx'
38+
]
39+
}
40+
} else {
41+
return defaultOptions
42+
}
43+
}

Diff for: docs/api/wrapper-array/setChecked.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ const wrapper = mount({
3131
})
3232

3333
const wrapperArray = wrapper.findAll('.foo')
34-
expect(wrapper.vm.t1).to.equal(false)
35-
expect(wrapper.vm.t2).to.equal('')
34+
expect(wrapper.vm.t1).toEqual(false)
35+
expect(wrapper.vm.t2).toEqual('')
3636
wrapperArray.setChecked()
37-
expect(wrapper.vm.t1).to.equal(true)
38-
expect(wrapper.vm.t2).to.equal('foo')
37+
expect(wrapper.vm.t1).toEqual(true)
38+
expect(wrapper.vm.t2).toEqual('foo')
3939
```

Diff for: docs/api/wrapper-array/setValue.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ const wrapper = mount({
3030
})
3131

3232
const wrapperArray = wrapper.findAll('.foo')
33-
expect(wrapper.vm.t1).to.equal('')
34-
expect(wrapper.vm.t2).to.equal('')
33+
expect(wrapper.vm.t1).toEqual('')
34+
expect(wrapper.vm.t2).toEqual('')
3535
wrapperArray.setValue('foo')
36-
expect(wrapper.vm.t1).to.equal('foo')
37-
expect(wrapper.vm.t2).to.equal('foo')
36+
expect(wrapper.vm.t1).toEqual('foo')
37+
expect(wrapper.vm.t2).toEqual('foo')
3838
```

Diff for: docs/ja/api/wrapper-array/setChecked.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ const wrapper = mount({
3131
})
3232

3333
const wrapperArray = wrapper.findAll('.foo')
34-
expect(wrapper.vm.t1).to.equal(false)
35-
expect(wrapper.vm.t2).to.equal('')
34+
expect(wrapper.vm.t1).toEqual(false)
35+
expect(wrapper.vm.t2).toEqual('')
3636
wrapperArray.setChecked()
37-
expect(wrapper.vm.t1).to.equal(true)
38-
expect(wrapper.vm.t2).to.equal('foo')
37+
expect(wrapper.vm.t1).toEqual(true)
38+
expect(wrapper.vm.t2).toEqual('foo')
3939
```

Diff for: docs/ja/api/wrapper-array/setValue.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ const wrapper = mount({
3030
})
3131

3232
const wrapperArray = wrapper.findAll('.foo')
33-
expect(wrapper.vm.t1).to.equal('')
34-
expect(wrapper.vm.t2).to.equal('')
33+
expect(wrapper.vm.t1).toEqual('')
34+
expect(wrapper.vm.t2).toEqual('')
3535
wrapperArray.setValue('foo')
36-
expect(wrapper.vm.t1).to.equal('foo')
37-
expect(wrapper.vm.t2).to.equal('foo')
36+
expect(wrapper.vm.t1).toEqual('foo')
37+
expect(wrapper.vm.t2).toEqual('foo')
3838
```

Diff for: docs/ru/api/wrapper-array/setChecked.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ const wrapper = mount({
3131
})
3232

3333
const wrapperArray = wrapper.findAll('.foo')
34-
expect(wrapper.vm.t1).to.equal(false)
35-
expect(wrapper.vm.t2).to.equal('')
34+
expect(wrapper.vm.t1).toEqual(false)
35+
expect(wrapper.vm.t2).toEqual('')
3636
wrapperArray.setChecked()
37-
expect(wrapper.vm.t1).to.equal(true)
38-
expect(wrapper.vm.t2).to.equal('foo')
37+
expect(wrapper.vm.t1).toEqual(true)
38+
expect(wrapper.vm.t2).toEqual('foo')
3939
```

Diff for: docs/ru/api/wrapper-array/setValue.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ const wrapper = mount({
3030
})
3131

3232
const wrapperArray = wrapper.findAll('.foo')
33-
expect(wrapper.vm.t1).to.equal('')
34-
expect(wrapper.vm.t2).to.equal('')
33+
expect(wrapper.vm.t1).toEqual('')
34+
expect(wrapper.vm.t2).toEqual('')
3535
wrapperArray.setValue('foo')
36-
expect(wrapper.vm.t1).to.equal('foo')
37-
expect(wrapper.vm.t2).to.equal('foo')
36+
expect(wrapper.vm.t1).toEqual('foo')
37+
expect(wrapper.vm.t2).toEqual('foo')
3838
```

Diff for: docs/zh/api/wrapper-array/setChecked.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ const wrapper = mount({
3131
})
3232

3333
const wrapperArray = wrapper.findAll('.foo')
34-
expect(wrapper.vm.t1).to.equal(false)
35-
expect(wrapper.vm.t2).to.equal('')
34+
expect(wrapper.vm.t1).toEqual(false)
35+
expect(wrapper.vm.t2).toEqual('')
3636
wrapperArray.setChecked()
37-
expect(wrapper.vm.t1).to.equal(true)
38-
expect(wrapper.vm.t2).to.equal('foo')
37+
expect(wrapper.vm.t1).toEqual(true)
38+
expect(wrapper.vm.t2).toEqual('foo')
3939
```

Diff for: docs/zh/api/wrapper-array/setValue.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ const wrapper = mount({
3030
})
3131

3232
const wrapperArray = wrapper.findAll('.foo')
33-
expect(wrapper.vm.t1).to.equal('')
34-
expect(wrapper.vm.t2).to.equal('')
33+
expect(wrapper.vm.t1).toEqual('')
34+
expect(wrapper.vm.t2).toEqual('')
3535
wrapperArray.setValue('foo')
36-
expect(wrapper.vm.t1).to.equal('foo')
37-
expect(wrapper.vm.t2).to.equal('foo')
36+
expect(wrapper.vm.t1).toEqual('foo')
37+
expect(wrapper.vm.t2).toEqual('foo')
3838
```

Diff for: jest.config.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
moduleNameMapper: {
3+
'^~(.*)$': '<rootDir>/test/$1',
4+
'^packages/(.*)$': '<rootDir>/packages/$1',
5+
'\\.(css|less|scss|sass)$': 'identity-obj-proxy'
6+
},
7+
transform: {
8+
'.*\\.(vue)$': 'vue-jest',
9+
'^.+\\.js$': '<rootDir>/node_modules/babel-jest'
10+
}
11+
}

Diff for: package.json

+35-42
Original file line numberDiff line numberDiff line change
@@ -19,89 +19,82 @@
1919
"format": "prettier --write \"**/*.{js,json,vue,md}\"",
2020
"format:check": "prettier --check \"**/*.{js,json,vue,md}\"",
2121
"release": "yarn build && yarn test:unit:only && lerna publish --conventional-commits -m \"chore(release): publish %s\"",
22-
"test": "yarn format:check && yarn lint && yarn lint:docs && yarn flow && yarn test:types && yarn test:unit && yarn test:unit:karma && yarn test:unit:node",
22+
"test": "yarn format:check && yarn lint && yarn lint:docs && yarn flow && yarn test:types && yarn test:unit -w 1 && yarn test:unit:browser",
2323
"test:compat": "scripts/test-compat.sh",
24-
"test:unit": "yarn build:test && yarn test:unit:only",
25-
"test:unit:only": "mocha-webpack --webpack-config test/setup/webpack.test.config.js test/specs --recursive --require test/setup/mocha.setup.js",
26-
"test:unit:only:dev": "cross-env TARGET=dev yarn test:unit:only",
27-
"test:unit:debug": "yarn build:test && node --inspect-brk node_modules/.bin/mocha-webpack --webpack-config test/setup/webpack.test.config.js test/specs --recursive --require test/setup/mocha.setup.js",
28-
"test:unit:karma": "yarn build:test && yarn test:unit:karma:only",
29-
"test:unit:karma:only": "cross-env TARGET=browser karma start test/setup/karma.conf.js --single-run",
30-
"test:unit:node": "yarn build:test && yarn test:unit:node:only",
31-
"test:unit:node:only": "cross-env TEST_ENV=node mocha-webpack --webpack-config test/setup/webpack.test.config.js test/specs/render.spec.js test/specs/renderToString.spec.js --require test/setup/mocha.setup.js",
24+
"test:unit": "cross-env TARGET=dev yarn jest",
25+
"test:unit:browser": "cross-env TEST_ENV=browser TARGET=browser NODE_ENV=browser karma start ./test/setup/karma.config.js",
3226
"test:types": "tsc -p packages/test-utils/types && tsc -p packages/server-test-utils/types"
3327
},
3428
"dependencies": {
35-
"@babel/core": "^7.0.0",
36-
"babel-eslint": "^9.0.0",
37-
"@vue/babel-helper-vue-jsx-merge-props": "^1.0.0",
38-
"@vue/babel-preset-jsx": "^1.1.2",
39-
"babel-loader": "^8.0.0",
40-
"@babel/plugin-syntax-jsx": "^7.0.0",
41-
"@babel/plugin-proposal-decorators": "^7.0.0",
42-
"@babel/plugin-transform-flow-strip-types": "^7.0.0",
43-
"@babel/plugin-proposal-class-properties": "^7.0.0",
44-
"@babel/plugin-syntax-flow": "^7.0.0",
45-
"@babel/polyfill": "^7.0.0",
46-
"@babel/preset-env": "^7.0.0",
47-
"chai": "^4.0.0",
4829
"chalk": "^2.4.2",
4930
"conditional-specs": "^1.0.1",
5031
"conventional-changelog": "^3.1.12",
5132
"cross-env": "^5.0.0",
52-
"css-loader": "^0.28.4",
5333
"eslint": "^4.18.1",
5434
"eslint-plugin-flowtype": "^2.46.1",
5535
"eslint-plugin-markdown": "^1.0.0-beta.6",
5636
"eslint-plugin-vue-libs": "^2.1.0",
5737
"flow-bin": "^0.66.0",
58-
"jsdom": "^12.0.0",
59-
"jsdom-global": "^3.0.2",
60-
"karma": "^3.1.4",
61-
"karma-mocha": "^1.3.0",
62-
"karma-phantomjs-launcher": "^1.0.4",
63-
"karma-sinon-chai": "^2.0.2",
64-
"karma-sourcemap-loader": "^0.3.7",
65-
"karma-spec-reporter": "^0.0.31",
66-
"karma-webpack": "^2.0.3",
6738
"lerna": "^3.20.2",
6839
"markdown-it-include": "^1.0.0",
69-
"mocha": "^5.2.0",
70-
"mocha-webpack": "^1.0.1",
7140
"rollup": "1",
7241
"rollup-plugin-buble": "^0.19",
7342
"rollup-plugin-commonjs": "10",
7443
"rollup-plugin-flow-no-whitespace": "1",
7544
"rollup-plugin-json": "4",
7645
"rollup-plugin-node-resolve": "5",
7746
"semver": "^6.3.0",
78-
"sinon": "^7.2.3",
79-
"sinon-chai": "^3.3.0",
8047
"typescript": "3",
8148
"vee-validate": "^2.1.3",
8249
"vue": "^2.6.11",
83-
"vue-class-component": "^6.1.2",
84-
"vue-loader": "^13.6.2",
50+
"vue-class-component": "^7.2.3",
8551
"vue-router": "^3.0.1",
8652
"vue-server-renderer": "^2.6.11",
8753
"vue-template-compiler": "^2.6.11",
8854
"vuepress": "^0.14.8",
8955
"vuepress-theme-vue": "^1.0.3",
90-
"vuex": "^3.0.1",
91-
"webpack": "^3.0.1",
92-
"webpack-node-externals": "^2.5.0"
56+
"vuex": "^3.0.1"
9357
},
9458
"devDependencies": {
59+
"@babel/core": "^7.0.0",
60+
"@babel/plugin-proposal-class-properties": "^7.0.0",
61+
"@babel/plugin-proposal-decorators": "^7.0.0",
62+
"@babel/plugin-syntax-flow": "^7.0.0",
63+
"@babel/plugin-syntax-jsx": "^7.0.0",
64+
"@babel/plugin-transform-flow-strip-types": "^7.0.0",
65+
"@babel/preset-env": "^7.0.0",
9566
"@commitlint/cli": "^8.2.0",
9667
"@commitlint/config-conventional": "^8.2.0",
68+
"@vue/babel-helper-vue-jsx-merge-props": "^1.0.0",
69+
"@vue/babel-preset-jsx": "^1.1.2",
9770
"@vue/composition-api": "^0.6.4",
71+
"babel-eslint": "^9.0.0",
72+
"babel-jest": "^26.0.1",
73+
"babel-loader": "^8.1.0",
9874
"commitizen": "^4.0.3",
75+
"core-js": "2",
76+
"css-loader": "^4.2.0",
9977
"cz-conventional-changelog": "^3.0.2",
78+
"expect": "^26.2.0",
10079
"husky": "^3.1.0",
80+
"identity-obj-proxy": "^3.0.0",
81+
"jest": "^26.0.1",
82+
"jest-mock": "^26.2.0",
83+
"karma": "^5.1.1",
84+
"karma-chrome-launcher": "^3.1.0",
85+
"karma-jasmine": "^3.3.1",
86+
"karma-spec-reporter": "^0.0.32",
87+
"karma-webpack": "^4.0.2",
10188
"lint-staged": "^9.5.0",
10289
"prettier": "^1.16.0",
90+
"puppeteer": "^5.2.1",
10391
"rollup-plugin-delete": "^1.2.0",
104-
"rollup-plugin-replace": "^2.2.0"
92+
"rollup-plugin-replace": "^2.2.0",
93+
"vue-jest": "^4.0.0-beta.3",
94+
"vue-loader": "^15.9.3",
95+
"vue-style-loader": "^4.1.2",
96+
"webpack": "^4.44.1",
97+
"webpack-node-externals": "^2.5.0"
10598
},
10699
"config": {
107100
"commitizen": {

Diff for: packages/test-utils/src/wrapper.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,9 @@ export default class Wrapper implements BaseWrapper {
716716
const isUpdated = Object.keys(data).some(key => {
717717
return (
718718
// $FlowIgnore : Problem with possibly null this.vm
719-
this.vm[key] === data[key] || this.vm.$attrs[key] === data[key]
719+
this.vm[key] === data[key] ||
720+
// $FlowIgnore : Problem with possibly null this.vm
721+
(this.vm.$attrs && this.vm.$attrs[key] === data[key])
720722
)
721723
})
722724
return !isUpdated ? this.setProps(data).then(resolve()) : resolve()

Diff for: scripts/test-compat.sh

+13-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,20 @@
22

33
set -e
44

5+
apt-get install bc
6+
57
run() {
6-
echo "running unit tests with Vue $1"
7-
yarn add --pure-lockfile --non-interactive -W -D "vue@$1" "vue-template-compiler@$1" "vue-server-renderer@$1"
8-
yarn test:unit:only
9-
yarn test:unit:karma:only
8+
# Only run tests for vue versions above 2.1.
9+
# There are quite a few errors present with running the tests in Vue 2.1 and Vue 2.0, including in Node and in browser
10+
browserTestCutoff="2.1"
11+
12+
if [ 1 -eq "$(echo "${browserTestCutoff} < ${1}" | bc)" ]
13+
then
14+
echo "running unit tests with Vue $1"
15+
yarn add --pure-lockfile --non-interactive -W -D "vue@$1" "vue-template-compiler@$1" "vue-server-renderer@$1"
16+
yarn test:unit -w 1
17+
yarn test:unit:browser
18+
fi
1019
}
1120

1221
yarn build:test

Diff for: test/resources/utils.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* global describe */
22

33
import Vue from 'vue'
4-
import { shallowMount, mount } from '@vue/test-utils'
5-
import { renderToString } from '@vue/server-test-utils'
4+
import { shallowMount, mount } from 'packages/test-utils/src'
5+
import { renderToString } from 'packages/server-test-utils/src'
66

77
export const vueVersion = Number(
88
`${Vue.version.split('.')[0]}.${Vue.version.split('.')[1]}`
@@ -13,10 +13,10 @@ export const isRunningJSDOM =
1313
navigator.userAgent.includes &&
1414
navigator.userAgent.includes('jsdom')
1515

16-
export const isRunningPhantomJS =
16+
export const isRunningChrome =
1717
typeof navigator !== 'undefined' &&
1818
navigator.userAgent.includes &&
19-
navigator.userAgent.match(/PhantomJS/i)
19+
navigator.userAgent.match(/Chrome/i)
2020

2121
export const injectSupported = vueVersion > 2.2
2222

Diff for: test/setup/karma.conf.js

-22
This file was deleted.

0 commit comments

Comments
 (0)