Skip to content

Commit

Permalink
build: migrate tests to jest (vuejs#1738)
Browse files Browse the repository at this point in the history
* build: migrate tests to jest

* build: remove babel object-rest-spread plugin

* chore: rename `.eslintrc` to `.eslintrc.json`

* chore: update `.eslintrc` in the test folder too
  • Loading branch information
kiaking authored May 8, 2020
1 parent 71372c3 commit dfacba6
Show file tree
Hide file tree
Showing 22 changed files with 2,346 additions and 743 deletions.
3 changes: 1 addition & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"presets": ["env"],
"plugins": ["transform-object-rest-spread"]
"presets": ["@babel/preset-env"]
}
File renamed without changes.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/coverage
/docs/.vuepress/dist
/examples/**/build.js
/test/e2e/reports
Expand Down
1 change: 0 additions & 1 deletion examples/chat/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'babel-polyfill'
import Vue from 'vue'
import App from './components/App.vue'
import store from './store'
Expand Down
1 change: 0 additions & 1 deletion examples/counter/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'babel-polyfill'
import Vue from 'vue'
import Counter from './Counter.vue'
import store from './store'
Expand Down
1 change: 0 additions & 1 deletion examples/shopping-cart/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'babel-polyfill'
import Vue from 'vue'
import App from './components/App.vue'
import store from './store'
Expand Down
1 change: 0 additions & 1 deletion examples/todomvc/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'babel-polyfill'
import Vue from 'vue'
import store from './store'
import App from './components/App.vue'
Expand Down
24 changes: 24 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
rootDir: __dirname,
globals: {
__DEV__: true
},
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
'^test/(.*)$': '<rootDir>/test/$1'
},
testMatch: ['<rootDir>/test/unit/**/*.spec.js'],
testPathIgnorePatterns: ['/node_modules/'],
setupFilesAfterEnv: [
'./test/setup.js'
],
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/babel-jest"
},
coverageDirectory: 'coverage',
coverageReporters: ['json', 'lcov', 'text-summary', 'clover'],
collectCoverageFrom: [
'src/**/*.js',
'!src/index.cjs.js'
]
}
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
"build:logger": "node scripts/build-logger.js",
"lint": "eslint src test",
"test": "npm run lint && npm run test:types && npm run test:unit && npm run test:ssr && npm run test:e2e",
"test:unit": "jasmine JASMINE_CONFIG_PATH=test/unit/jasmine.json",
"test:unit": "jest --testPathIgnorePatterns test/e2e",
"test:e2e": "node test/e2e/runner.js",
"test:ssr": "cross-env VUE_ENV=server jasmine JASMINE_CONFIG_PATH=test/unit/jasmine.json",
"test:ssr": "cross-env VUE_ENV=server jest --testPathIgnorePatterns test/e2e",
"test:types": "tsc -p types/test",
"coverage": "jest --testPathIgnorePatterns test/e2e --coverage",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"release": "node scripts/release.js",
"docs": "vuepress dev docs",
Expand All @@ -44,16 +45,15 @@
"vue": "^2.0.0"
},
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.5",
"@rollup/plugin-buble": "^0.21.3",
"@rollup/plugin-commonjs": "^11.1.0",
"@rollup/plugin-node-resolve": "^7.1.3",
"@rollup/plugin-replace": "^2.3.2",
"@types/node": "^13.13.2",
"babel-core": "^6.22.1",
"babel-loader": "^7.1.2",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-polyfill": "^6.22.0",
"babel-preset-env": "^1.5.1",
"babel-jest": "^25.4.0",
"babel-loader": "^8.1.0",
"brotli": "^1.3.2",
"chalk": "^4.0.0",
"chromedriver": "^80.0.1",
Expand All @@ -66,10 +66,10 @@
"eslint-plugin-vue-libs": "^4.0.0",
"execa": "^4.0.0",
"express": "^4.17.1",
"jasmine": "2.8.0",
"jasmine-core": "2.8.0",
"jest": "^25.4.0",
"nightwatch": "^1.3.1",
"nightwatch-helpers": "^1.2.0",
"regenerator-runtime": "^0.13.5",
"rollup": "^2.7.2",
"rollup-plugin-terser": "^5.3.0",
"semver": "^7.3.2",
Expand Down
5 changes: 5 additions & 0 deletions test/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"env": {
"jest": true
}
}
5 changes: 5 additions & 0 deletions test/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'regenerator-runtime/runtime'
import Vue from 'vue'
import Vuex from '@/index'

Vue.use(Vuex)
5 changes: 0 additions & 5 deletions test/unit/.eslintrc

This file was deleted.

34 changes: 17 additions & 17 deletions test/unit/helpers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('Helpers', () => {
})

it('mapState (with undefined states)', () => {
spyOn(console, 'error')
jest.spyOn(console, 'error').mockImplementation()
const store = new Vuex.Store({
modules: {
foo: {
Expand Down Expand Up @@ -225,7 +225,7 @@ describe('Helpers', () => {
})

it('mapMutations (with undefined mutations)', () => {
spyOn(console, 'error')
jest.spyOn(console, 'error').mockImplementation()
const store = new Vuex.Store({
modules: {
foo: {
Expand Down Expand Up @@ -393,7 +393,7 @@ describe('Helpers', () => {
})

it('mapGetters (with undefined getters)', () => {
spyOn(console, 'error')
jest.spyOn(console, 'error').mockImplementation()
const store = new Vuex.Store({
modules: {
foo: {
Expand All @@ -420,8 +420,8 @@ describe('Helpers', () => {
})

it('mapActions (array)', () => {
const a = jasmine.createSpy()
const b = jasmine.createSpy()
const a = jest.fn()
const b = jest.fn()
const store = new Vuex.Store({
actions: {
a,
Expand All @@ -440,8 +440,8 @@ describe('Helpers', () => {
})

it('mapActions (object)', () => {
const a = jasmine.createSpy()
const b = jasmine.createSpy()
const a = jest.fn()
const b = jest.fn()
const store = new Vuex.Store({
actions: {
a,
Expand All @@ -463,7 +463,7 @@ describe('Helpers', () => {
})

it('mapActions (function)', () => {
const a = jasmine.createSpy()
const a = jest.fn()
const store = new Vuex.Store({
actions: { a }
})
Expand All @@ -476,12 +476,12 @@ describe('Helpers', () => {
})
})
vm.foo('foo')
expect(a.calls.argsFor(0)[1]).toBe('foobar')
expect(a.mock.calls[0][1]).toBe('foobar')
})

it('mapActions (with namespace)', () => {
const a = jasmine.createSpy()
const b = jasmine.createSpy()
const a = jest.fn()
const b = jest.fn()
const store = new Vuex.Store({
modules: {
foo: {
Expand All @@ -508,7 +508,7 @@ describe('Helpers', () => {
})

it('mapActions (function with namespace)', () => {
const a = jasmine.createSpy()
const a = jest.fn()
const store = new Vuex.Store({
modules: {
foo: {
Expand All @@ -526,12 +526,12 @@ describe('Helpers', () => {
})
})
vm.foo('foo')
expect(a.calls.argsFor(0)[1]).toBe('foobar')
expect(a.mock.calls[0][1]).toBe('foobar')
})

it('mapActions (with undefined actions)', () => {
spyOn(console, 'error')
const a = jasmine.createSpy()
jest.spyOn(console, 'error').mockImplementation()
const a = jest.fn()
const store = new Vuex.Store({
modules: {
foo: {
Expand All @@ -552,8 +552,8 @@ describe('Helpers', () => {
})

it('createNamespacedHelpers', () => {
const actionA = jasmine.createSpy()
const actionB = jasmine.createSpy()
const actionA = jest.fn()
const actionB = jest.fn()
const store = new Vuex.Store({
modules: {
foo: {
Expand Down
22 changes: 11 additions & 11 deletions test/unit/hot-reload.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ describe('Hot Reload', () => {
}
})

const spy = jasmine.createSpy()
const spy = jest.fn()
const vm = new Vue({
computed: {
a: () => store.getters.count
Expand Down Expand Up @@ -292,7 +292,7 @@ describe('Hot Reload', () => {
it('provide warning if a new module is given', () => {
const store = new Vuex.Store({})

spyOn(console, 'warn')
jest.spyOn(console, 'warn').mockImplementation()

store.hotUpdate({
modules: {
Expand All @@ -312,10 +312,10 @@ describe('Hot Reload', () => {

it('update namespace', () => {
// prevent to print notification of unknown action/mutation
spyOn(console, 'error')
jest.spyOn(console, 'error').mockImplementation()

const actionSpy = jasmine.createSpy()
const mutationSpy = jasmine.createSpy()
const actionSpy = jest.fn()
const mutationSpy = jest.fn()

const store = new Vuex.Store({
modules: {
Expand All @@ -332,9 +332,9 @@ describe('Hot Reload', () => {
expect(store.state.a.value).toBe(1)
expect(store.getters['a/foo']).toBe(1)
store.dispatch('a/foo')
expect(actionSpy.calls.count()).toBe(1)
expect(actionSpy).toHaveBeenCalledTimes(1)
store.commit('a/foo')
expect(actionSpy.calls.count()).toBe(1)
expect(actionSpy).toHaveBeenCalledTimes(1)

store.hotUpdate({
modules: {
Expand All @@ -350,18 +350,18 @@ describe('Hot Reload', () => {

// should not be called
store.dispatch('a/foo')
expect(actionSpy.calls.count()).toBe(1)
expect(actionSpy).toHaveBeenCalledTimes(1)

// should be called
store.dispatch('foo')
expect(actionSpy.calls.count()).toBe(2)
expect(actionSpy).toHaveBeenCalledTimes(2)

// should not be called
store.commit('a/foo')
expect(mutationSpy.calls.count()).toBe(1)
expect(mutationSpy).toHaveBeenCalledTimes(1)

// should be called
store.commit('foo')
expect(mutationSpy.calls.count()).toBe(2)
expect(mutationSpy).toHaveBeenCalledTimes(2)
})
})
10 changes: 0 additions & 10 deletions test/unit/jasmine.json

This file was deleted.

2 changes: 1 addition & 1 deletion test/unit/module/module-collection.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ModuleCollection from '../../../src/module/module-collection'
import ModuleCollection from '@/module/module-collection'

describe('ModuleCollection', () => {
it('get', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/module/module.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Module from '../../../src/module/module'
import Module from '@/module/module'

describe('Module', () => {
it('get state', () => {
Expand Down
Loading

0 comments on commit dfacba6

Please sign in to comment.