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

Migrate to jest 2 #1629

Merged
merged 46 commits into from
Aug 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
9c2e68f
refactor: use jest
lmiller1990 Jun 20, 2020
42b50c9
refactor: strip flow types when running tests with jest
lmiller1990 Jun 20, 2020
58973bf
refactor: update attachTo and destroy specs
lmiller1990 Jun 20, 2020
c7b2d1e
refactor: continue moving to jest
lmiller1990 Jun 20, 2020
de51777
refactor: update tests
lmiller1990 Jun 20, 2020
e09a8ad
refactor: update tests
lmiller1990 Jun 20, 2020
bd83440
refactor: update tests
lmiller1990 Jun 20, 2020
90d7118
refactor: continue jest migration
lmiller1990 Jun 20, 2020
9afa062
refactor: continue jest migration
lmiller1990 Jun 20, 2020
523e8bc
refactor: remove sinon
lmiller1990 Jun 20, 2020
0fe0eb0
refactor: update tests to use jest
lmiller1990 Jun 20, 2020
a992654
refactor: update tests to use jest
lmiller1990 Jun 20, 2020
b0aba13
refactor: add jsx plugin and update scopedSlots spec
lmiller1990 Jun 20, 2020
e179b92
chore: add missing deps
lmiller1990 Jun 30, 2020
623adc2
test: add class component and update stubs tests
lmiller1990 Jul 5, 2020
bf67d57
test: update tests
lmiller1990 Jul 5, 2020
97207fa
test: migrate more tests
lmiller1990 Jul 5, 2020
e92f965
test: continue migration
lmiller1990 Jul 5, 2020
97e6270
test: refactor set methods
lmiller1990 Jul 5, 2020
6c7c1e4
test: finish refactor set methods
lmiller1990 Jul 5, 2020
d8517d0
test: refactor trigger
lmiller1990 Jul 5, 2020
08d4848
test: refactor wrapper-array specs
lmiller1990 Jul 5, 2020
495e127
test: update config.spec.js
lmiller1990 Jul 6, 2020
f29fbe5
test: update mount specs
lmiller1990 Jul 6, 2020
cdce1e4
test: use spyOn
lmiller1990 Jul 6, 2020
a268053
test: migrate tests
lmiller1990 Jul 6, 2020
711017b
test: placeholder to prevent false failure
lmiller1990 Jul 6, 2020
85c626f
test: remove karma, sinon, chai and see what happens
lmiller1990 Jul 6, 2020
002f686
test: do not use compiled dist files for tests
lmiller1990 Jul 7, 2020
28fffd8
test: make scripts minimal
lmiller1990 Jul 7, 2020
b51ec44
test: update import paths
lmiller1990 Jul 9, 2020
014f9e6
chore: update circleci
lmiller1990 Jul 9, 2020
4d52803
chore(yarn.lock): dedupe the yarn lock file to run jest tests
AtofStryker Aug 1, 2020
1cd024c
chore(test/setup): remove the test setup directory
AtofStryker Aug 1, 2020
e9ab677
chore: remove @babel/polyfill
AtofStryker Aug 1, 2020
29b327d
chore(babel.config.js): set preset-env target to node current
AtofStryker Aug 1, 2020
16c1244
test(setprops.spec.js): update newly added tests to Jest
AtofStryker Aug 1, 2020
96d990a
fix(docs/): re include vuepress build scripts to deploy docs
AtofStryker Aug 1, 2020
178bd05
chore(package.json): remove webpack and mocha related dependencies
AtofStryker Aug 1, 2020
dcbbb1b
ci(unit tests): run Jest tests in single thread to prevent OOM exception
AtofStryker Aug 1, 2020
cfd494f
chore(package.json): move babel dependencies to dev dependencies
AtofStryker Aug 1, 2020
4517528
improvement(test/setup): reimplement Browser Unit Tests
AtofStryker Aug 2, 2020
3681110
chore(scripts): re add missing build scripts
AtofStryker Aug 4, 2020
0eb83a1
chore(jsdom): remove JSDOM and JSDOM-Global
AtofStryker Aug 9, 2020
6cbfadf
chore: update eslintrc
lmiller1990 Aug 15, 2020
afad86e
chore(karma.config.js): set singleRun to true for all runtimes
AtofStryker Aug 16, 2020
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
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"globals": {
"wrapper": true,
"expect": true,
"Element": true
"Element": true,
"jest": true
},
"root": true,
"plugins": [
Expand All @@ -13,6 +14,7 @@
"plugin:flowtype/recommended"
],
"rules": {
"template-curly-spacing" : "off",
"no-debugger": 2,
"no-proto": 0,
"space-before-function-paren": 0,
Expand Down
36 changes: 34 additions & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
module.exports = {
presets: ['@babel/preset-env', '@vue/babel-preset-jsx'],
const defaultOptions = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current'
}
}
],
'@vue/babel-preset-jsx'
],
plugins: [
'@babel/plugin-syntax-jsx',
'@babel/plugin-transform-flow-strip-types',
Expand All @@ -9,3 +19,25 @@ module.exports = {
],
comments: false
}

module.exports = api => {
if (api.env('browser')) {
// If running in the browser, use core-js to polyfill potentially missing functionality
return {
...defaultOptions,
presets: [
[
'@babel/preset-env',
{
// currently, there are dependency resolution issues with older versions of vuepress. Once vuepress is upgraded, core-js can be moved to version 3
corejs: 2,
useBuiltIns: 'entry'
}
],
'@vue/babel-preset-jsx'
]
}
} else {
return defaultOptions
}
}
8 changes: 4 additions & 4 deletions docs/api/wrapper-array/setChecked.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ const wrapper = mount({
})

const wrapperArray = wrapper.findAll('.foo')
expect(wrapper.vm.t1).to.equal(false)
expect(wrapper.vm.t2).to.equal('')
expect(wrapper.vm.t1).toEqual(false)
expect(wrapper.vm.t2).toEqual('')
wrapperArray.setChecked()
expect(wrapper.vm.t1).to.equal(true)
expect(wrapper.vm.t2).to.equal('foo')
expect(wrapper.vm.t1).toEqual(true)
expect(wrapper.vm.t2).toEqual('foo')
```
8 changes: 4 additions & 4 deletions docs/api/wrapper-array/setValue.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ const wrapper = mount({
})

const wrapperArray = wrapper.findAll('.foo')
expect(wrapper.vm.t1).to.equal('')
expect(wrapper.vm.t2).to.equal('')
expect(wrapper.vm.t1).toEqual('')
expect(wrapper.vm.t2).toEqual('')
wrapperArray.setValue('foo')
expect(wrapper.vm.t1).to.equal('foo')
expect(wrapper.vm.t2).to.equal('foo')
expect(wrapper.vm.t1).toEqual('foo')
expect(wrapper.vm.t2).toEqual('foo')
```
8 changes: 4 additions & 4 deletions docs/ja/api/wrapper-array/setChecked.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ const wrapper = mount({
})

const wrapperArray = wrapper.findAll('.foo')
expect(wrapper.vm.t1).to.equal(false)
expect(wrapper.vm.t2).to.equal('')
expect(wrapper.vm.t1).toEqual(false)
expect(wrapper.vm.t2).toEqual('')
wrapperArray.setChecked()
expect(wrapper.vm.t1).to.equal(true)
expect(wrapper.vm.t2).to.equal('foo')
expect(wrapper.vm.t1).toEqual(true)
expect(wrapper.vm.t2).toEqual('foo')
```
8 changes: 4 additions & 4 deletions docs/ja/api/wrapper-array/setValue.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ const wrapper = mount({
})

const wrapperArray = wrapper.findAll('.foo')
expect(wrapper.vm.t1).to.equal('')
expect(wrapper.vm.t2).to.equal('')
expect(wrapper.vm.t1).toEqual('')
expect(wrapper.vm.t2).toEqual('')
wrapperArray.setValue('foo')
expect(wrapper.vm.t1).to.equal('foo')
expect(wrapper.vm.t2).to.equal('foo')
expect(wrapper.vm.t1).toEqual('foo')
expect(wrapper.vm.t2).toEqual('foo')
```
8 changes: 4 additions & 4 deletions docs/ru/api/wrapper-array/setChecked.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ const wrapper = mount({
})

const wrapperArray = wrapper.findAll('.foo')
expect(wrapper.vm.t1).to.equal(false)
expect(wrapper.vm.t2).to.equal('')
expect(wrapper.vm.t1).toEqual(false)
expect(wrapper.vm.t2).toEqual('')
wrapperArray.setChecked()
expect(wrapper.vm.t1).to.equal(true)
expect(wrapper.vm.t2).to.equal('foo')
expect(wrapper.vm.t1).toEqual(true)
expect(wrapper.vm.t2).toEqual('foo')
```
8 changes: 4 additions & 4 deletions docs/ru/api/wrapper-array/setValue.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ const wrapper = mount({
})

const wrapperArray = wrapper.findAll('.foo')
expect(wrapper.vm.t1).to.equal('')
expect(wrapper.vm.t2).to.equal('')
expect(wrapper.vm.t1).toEqual('')
expect(wrapper.vm.t2).toEqual('')
wrapperArray.setValue('foo')
expect(wrapper.vm.t1).to.equal('foo')
expect(wrapper.vm.t2).to.equal('foo')
expect(wrapper.vm.t1).toEqual('foo')
expect(wrapper.vm.t2).toEqual('foo')
```
8 changes: 4 additions & 4 deletions docs/zh/api/wrapper-array/setChecked.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ const wrapper = mount({
})

const wrapperArray = wrapper.findAll('.foo')
expect(wrapper.vm.t1).to.equal(false)
expect(wrapper.vm.t2).to.equal('')
expect(wrapper.vm.t1).toEqual(false)
expect(wrapper.vm.t2).toEqual('')
wrapperArray.setChecked()
expect(wrapper.vm.t1).to.equal(true)
expect(wrapper.vm.t2).to.equal('foo')
expect(wrapper.vm.t1).toEqual(true)
expect(wrapper.vm.t2).toEqual('foo')
```
8 changes: 4 additions & 4 deletions docs/zh/api/wrapper-array/setValue.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ const wrapper = mount({
})

const wrapperArray = wrapper.findAll('.foo')
expect(wrapper.vm.t1).to.equal('')
expect(wrapper.vm.t2).to.equal('')
expect(wrapper.vm.t1).toEqual('')
expect(wrapper.vm.t2).toEqual('')
wrapperArray.setValue('foo')
expect(wrapper.vm.t1).to.equal('foo')
expect(wrapper.vm.t2).to.equal('foo')
expect(wrapper.vm.t1).toEqual('foo')
expect(wrapper.vm.t2).toEqual('foo')
```
11 changes: 11 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
moduleNameMapper: {
'^~(.*)$': '<rootDir>/test/$1',
'^packages/(.*)$': '<rootDir>/packages/$1',
'\\.(css|less|scss|sass)$': 'identity-obj-proxy'
},
transform: {
'.*\\.(vue)$': 'vue-jest',
'^.+\\.js$': '<rootDir>/node_modules/babel-jest'
}
}
77 changes: 35 additions & 42 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,89 +19,82 @@
"format": "prettier --write \"**/*.{js,json,vue,md}\"",
"format:check": "prettier --check \"**/*.{js,json,vue,md}\"",
"release": "yarn build && yarn test:unit:only && lerna publish --conventional-commits -m \"chore(release): publish %s\"",
"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",
"test": "yarn format:check && yarn lint && yarn lint:docs && yarn flow && yarn test:types && yarn test:unit -w 1 && yarn test:unit:browser",
"test:compat": "scripts/test-compat.sh",
"test:unit": "yarn build:test && yarn test:unit:only",
"test:unit:only": "mocha-webpack --webpack-config test/setup/webpack.test.config.js test/specs --recursive --require test/setup/mocha.setup.js",
"test:unit:only:dev": "cross-env TARGET=dev yarn test:unit:only",
"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",
"test:unit:karma": "yarn build:test && yarn test:unit:karma:only",
"test:unit:karma:only": "cross-env TARGET=browser karma start test/setup/karma.conf.js --single-run",
"test:unit:node": "yarn build:test && yarn test:unit:node:only",
"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",
"test:unit": "cross-env TARGET=dev yarn jest",
"test:unit:browser": "cross-env TEST_ENV=browser TARGET=browser NODE_ENV=browser karma start ./test/setup/karma.config.js",
"test:types": "tsc -p packages/test-utils/types && tsc -p packages/server-test-utils/types"
},
"dependencies": {
"@babel/core": "^7.0.0",
"babel-eslint": "^9.0.0",
"@vue/babel-helper-vue-jsx-merge-props": "^1.0.0",
"@vue/babel-preset-jsx": "^1.1.2",
"babel-loader": "^8.0.0",
"@babel/plugin-syntax-jsx": "^7.0.0",
"@babel/plugin-proposal-decorators": "^7.0.0",
"@babel/plugin-transform-flow-strip-types": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-syntax-flow": "^7.0.0",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"chai": "^4.0.0",
"chalk": "^2.4.2",
"conditional-specs": "^1.0.1",
"conventional-changelog": "^3.1.12",
"cross-env": "^5.0.0",
"css-loader": "^0.28.4",
"eslint": "^4.18.1",
"eslint-plugin-flowtype": "^2.46.1",
"eslint-plugin-markdown": "^1.0.0-beta.6",
"eslint-plugin-vue-libs": "^2.1.0",
"flow-bin": "^0.66.0",
"jsdom": "^12.0.0",
"jsdom-global": "^3.0.2",
"karma": "^3.1.4",
"karma-mocha": "^1.3.0",
"karma-phantomjs-launcher": "^1.0.4",
"karma-sinon-chai": "^2.0.2",
"karma-sourcemap-loader": "^0.3.7",
"karma-spec-reporter": "^0.0.31",
"karma-webpack": "^2.0.3",
"lerna": "^3.20.2",
"markdown-it-include": "^1.0.0",
"mocha": "^5.2.0",
"mocha-webpack": "^1.0.1",
"rollup": "1",
"rollup-plugin-buble": "^0.19",
"rollup-plugin-commonjs": "10",
"rollup-plugin-flow-no-whitespace": "1",
"rollup-plugin-json": "4",
"rollup-plugin-node-resolve": "5",
"semver": "^6.3.0",
"sinon": "^7.2.3",
"sinon-chai": "^3.3.0",
"typescript": "3",
"vee-validate": "^2.1.3",
"vue": "^2.6.11",
"vue-class-component": "^6.1.2",
"vue-loader": "^13.6.2",
"vue-class-component": "^7.2.3",
"vue-router": "^3.0.1",
"vue-server-renderer": "^2.6.11",
"vue-template-compiler": "^2.6.11",
"vuepress": "^0.14.8",
"vuepress-theme-vue": "^1.0.3",
"vuex": "^3.0.1",
"webpack": "^3.0.1",
"webpack-node-externals": "^2.5.0"
"vuex": "^3.0.1"
},
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-decorators": "^7.0.0",
"@babel/plugin-syntax-flow": "^7.0.0",
"@babel/plugin-syntax-jsx": "^7.0.0",
"@babel/plugin-transform-flow-strip-types": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@commitlint/cli": "^8.2.0",
"@commitlint/config-conventional": "^8.2.0",
"@vue/babel-helper-vue-jsx-merge-props": "^1.0.0",
"@vue/babel-preset-jsx": "^1.1.2",
"@vue/composition-api": "^0.6.4",
"babel-eslint": "^9.0.0",
"babel-jest": "^26.0.1",
"babel-loader": "^8.1.0",
"commitizen": "^4.0.3",
"core-js": "2",
"css-loader": "^4.2.0",
"cz-conventional-changelog": "^3.0.2",
"expect": "^26.2.0",
"husky": "^3.1.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^26.0.1",
"jest-mock": "^26.2.0",
"karma": "^5.1.1",
"karma-chrome-launcher": "^3.1.0",
"karma-jasmine": "^3.3.1",
"karma-spec-reporter": "^0.0.32",
"karma-webpack": "^4.0.2",
"lint-staged": "^9.5.0",
"prettier": "^1.16.0",
"puppeteer": "^5.2.1",
"rollup-plugin-delete": "^1.2.0",
"rollup-plugin-replace": "^2.2.0"
"rollup-plugin-replace": "^2.2.0",
"vue-jest": "^4.0.0-beta.3",
"vue-loader": "^15.9.3",
"vue-style-loader": "^4.1.2",
"webpack": "^4.44.1",
"webpack-node-externals": "^2.5.0"
},
"config": {
"commitizen": {
Expand Down
4 changes: 3 additions & 1 deletion packages/test-utils/src/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,9 @@ export default class Wrapper implements BaseWrapper {
const isUpdated = Object.keys(data).some(key => {
return (
// $FlowIgnore : Problem with possibly null this.vm
this.vm[key] === data[key] || this.vm.$attrs[key] === data[key]
this.vm[key] === data[key] ||
// $FlowIgnore : Problem with possibly null this.vm
(this.vm.$attrs && this.vm.$attrs[key] === data[key])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a few issues in CI recently in regards to this guy in vue 2.3. Looks like I introduced a small regression in VTU for setProps for vue version 2.3 in #1618. The stack trace was a bit difficult to track down, but this should fix the issues seen

)
})
return !isUpdated ? this.setProps(data).then(resolve()) : resolve()
Expand Down
17 changes: 13 additions & 4 deletions scripts/test-compat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@

set -e

apt-get install bc

run() {
echo "running unit tests with Vue $1"
yarn add --pure-lockfile --non-interactive -W -D "vue@$1" "vue-template-compiler@$1" "vue-server-renderer@$1"
yarn test:unit:only
yarn test:unit:karma:only
# Only run tests for vue versions above 2.1.
# 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
browserTestCutoff="2.1"

if [ 1 -eq "$(echo "${browserTestCutoff} < ${1}" | bc)" ]
then
echo "running unit tests with Vue $1"
yarn add --pure-lockfile --non-interactive -W -D "vue@$1" "vue-template-compiler@$1" "vue-server-renderer@$1"
yarn test:unit -w 1
yarn test:unit:browser
fi
}

yarn build:test
Expand Down
8 changes: 4 additions & 4 deletions test/resources/utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* global describe */

import Vue from 'vue'
import { shallowMount, mount } from '@vue/test-utils'
import { renderToString } from '@vue/server-test-utils'
import { shallowMount, mount } from 'packages/test-utils/src'
import { renderToString } from 'packages/server-test-utils/src'

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

export const isRunningPhantomJS =
export const isRunningChrome =
typeof navigator !== 'undefined' &&
navigator.userAgent.includes &&
navigator.userAgent.match(/PhantomJS/i)
navigator.userAgent.match(/Chrome/i)

export const injectSupported = vueVersion > 2.2

Expand Down
22 changes: 0 additions & 22 deletions test/setup/karma.conf.js

This file was deleted.

Loading