From 532a8004241e1cf7a197246995873b65bdcc3843 Mon Sep 17 00:00:00 2001 From: Danie Cook Date: Sat, 1 Jun 2019 08:28:06 +0100 Subject: [PATCH 1/4] #27 - Provide cleanup-after-each --- .gitignore | 2 +- README.md | 4 ++-- jest.config.js | 5 ++++- package.json | 7 ++++--- tests/__tests__/debug.js | 2 +- tests/__tests__/end-to-end.js | 2 +- tests/__tests__/fetch.js | 2 +- tests/__tests__/form.js | 2 +- tests/__tests__/integration-with-stubs.js | 2 +- tests/__tests__/number-display.js | 2 +- tests/__tests__/router/programmatic-routing/index.js | 2 +- tests/__tests__/simple-button.js | 2 +- tests/__tests__/stopwatch.js | 2 +- tests/__tests__/validate-plugin.js | 2 +- tests/__tests__/vue-router.js | 2 +- tests/__tests__/vuex.js | 2 +- 16 files changed, 23 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 2299f989..3c2fed5c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ node_modules coverage -npm +dist .opt-in .opt-out .DS_Store diff --git a/README.md b/README.md index 1240296c..4af670af 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ npm install --save-dev vue-testing-library ## Usage ``` -npm install --save-dev vue-testing-library +npm install --save-dev @testing-library/vue jest vue-jest babel-jest @@ -99,7 +99,7 @@ npm install --save-dev vue-testing-library // src/TestComponent.spec.js import 'jest-dom/extend-expect' -import { render } from 'vue-testing-library' +import { render } from '@testing-library/vue' import TestComponent from './TestComponent' test('should render HelloWorld', () => { diff --git a/jest.config.js b/jest.config.js index 8b775bea..a1337955 100644 --- a/jest.config.js +++ b/jest.config.js @@ -7,6 +7,9 @@ module.exports = { 'js', 'vue' ], + moduleNameMapper: { + '@testing-library/vue': '/src/vue-testing-library.js' + }, coverageDirectory: './coverage', collectCoverageFrom: [ '**/src/**/*.js', @@ -15,7 +18,7 @@ module.exports = { ], testPathIgnorePatterns: [ '/node_modules/', - '/npm/', + '/dist/', '/tests/__tests__/components/' ], transform: { diff --git a/package.json b/package.json index ea327de8..6e6574d8 100644 --- a/package.json +++ b/package.json @@ -2,16 +2,17 @@ "name": "@testing-library/vue", "version": "1.0.0", "description": "Simple and complete Vue DOM testing utilities that encourage good testing practices.", - "main": "npm/vue-testing-library.js", + "main": "dist/vue-testing-library.js", "scripts": { "lint": "eslint --ext .js,.vue .", "lint:fix": "eslint --ext .js,.vue . --fix", "test": "jest --coverage", "coveralls": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls", - "version": "babel src --out-dir npm" + "prepublishOnly": "babel src --out-dir dist" }, "files": [ - "npm" + "dist", + "cleanup-after-each.js" ], "repository": { "type": "git", diff --git a/tests/__tests__/debug.js b/tests/__tests__/debug.js index 1f506d8e..2e9a8762 100644 --- a/tests/__tests__/debug.js +++ b/tests/__tests__/debug.js @@ -1,5 +1,5 @@ import HelloWorld from './components/HelloWorld' -import { cleanup, render } from 'vue-testing-library' +import { cleanup, render } from '@testing-library/vue' beforeEach(() => { jest.spyOn(console, 'log').mockImplementation(() => {}) diff --git a/tests/__tests__/end-to-end.js b/tests/__tests__/end-to-end.js index 029e5470..16a8f158 100644 --- a/tests/__tests__/end-to-end.js +++ b/tests/__tests__/end-to-end.js @@ -1,4 +1,4 @@ -import { render, wait } from 'vue-testing-library' +import { render, wait } from '@testing-library/vue' import EndToEnd from './components/EndToEnd' test('it waits for the data to be loaded', async () => { diff --git a/tests/__tests__/fetch.js b/tests/__tests__/fetch.js index 7592b1ac..0da14cae 100644 --- a/tests/__tests__/fetch.js +++ b/tests/__tests__/fetch.js @@ -1,5 +1,5 @@ import axiosMock from 'axios' -import { render, fireEvent } from 'vue-testing-library' +import { render, fireEvent } from '@testing-library/vue' import Fetch from './components/Fetch.vue' import 'jest-dom/extend-expect' diff --git a/tests/__tests__/form.js b/tests/__tests__/form.js index 4b56cbb4..ac28c579 100644 --- a/tests/__tests__/form.js +++ b/tests/__tests__/form.js @@ -1,4 +1,4 @@ -import { render, fireEvent } from 'vue-testing-library' +import { render, fireEvent } from '@testing-library/vue' import Login from './components/Login' test('login form submits', async () => { diff --git a/tests/__tests__/integration-with-stubs.js b/tests/__tests__/integration-with-stubs.js index 21b538e7..b78077d6 100644 --- a/tests/__tests__/integration-with-stubs.js +++ b/tests/__tests__/integration-with-stubs.js @@ -1,4 +1,4 @@ -import { render, cleanup } from 'vue-testing-library' +import { render, cleanup } from '@testing-library/vue' import Form from './components/Form' afterEach(cleanup) diff --git a/tests/__tests__/number-display.js b/tests/__tests__/number-display.js index 16b04982..43a52179 100644 --- a/tests/__tests__/number-display.js +++ b/tests/__tests__/number-display.js @@ -1,5 +1,5 @@ import NumberDisplay from './components/NumberDisplay.vue' -import { render } from 'vue-testing-library' +import { render } from '@testing-library/vue' import 'jest-dom/extend-expect' test('calling render with the same component but different props does not remount', async () => { diff --git a/tests/__tests__/router/programmatic-routing/index.js b/tests/__tests__/router/programmatic-routing/index.js index 2e401f4f..7396f3ff 100644 --- a/tests/__tests__/router/programmatic-routing/index.js +++ b/tests/__tests__/router/programmatic-routing/index.js @@ -4,7 +4,7 @@ import App from './components/App.vue' import Home from './components/Home.vue' import About from './components/About.vue' -import { render, fireEvent } from 'vue-testing-library' +import { render, fireEvent } from '@testing-library/vue' const routes = [ { path: '/', component: Home }, diff --git a/tests/__tests__/simple-button.js b/tests/__tests__/simple-button.js index bb3fcfbe..7112dbaf 100644 --- a/tests/__tests__/simple-button.js +++ b/tests/__tests__/simple-button.js @@ -1,4 +1,4 @@ -import { render, cleanup, fireEvent } from 'vue-testing-library' +import { render, cleanup, fireEvent } from '@testing-library/vue' import SimpleButton from './components/Button' afterEach(cleanup) diff --git a/tests/__tests__/stopwatch.js b/tests/__tests__/stopwatch.js index 3bf89981..5b3d8786 100644 --- a/tests/__tests__/stopwatch.js +++ b/tests/__tests__/stopwatch.js @@ -1,5 +1,5 @@ import StopWatch from './components/StopWatch.vue' -import { render, wait, fireEvent } from 'vue-testing-library' +import { render, wait, fireEvent } from '@testing-library/vue' import 'jest-dom/extend-expect' test('unmounts a component', async () => { diff --git a/tests/__tests__/validate-plugin.js b/tests/__tests__/validate-plugin.js index a3f0a94a..644c4250 100644 --- a/tests/__tests__/validate-plugin.js +++ b/tests/__tests__/validate-plugin.js @@ -1,7 +1,7 @@ import VeeValidate from 'vee-validate' import 'jest-dom/extend-expect' -import { render, fireEvent } from 'vue-testing-library' +import { render, fireEvent } from '@testing-library/vue' import Validate from './components/Validate' test('can validate using plugin', async () => { diff --git a/tests/__tests__/vue-router.js b/tests/__tests__/vue-router.js index 9f0e9a60..8d64bd44 100644 --- a/tests/__tests__/vue-router.js +++ b/tests/__tests__/vue-router.js @@ -4,7 +4,7 @@ import App from './components/Router/App.vue' import Home from './components/Router/Home.vue' import About from './components/Router/About.vue' -import { render, fireEvent } from 'vue-testing-library' +import { render, fireEvent } from '@testing-library/vue' const routes = [ { path: '/', component: Home }, diff --git a/tests/__tests__/vuex.js b/tests/__tests__/vuex.js index 22a452db..14011aee 100644 --- a/tests/__tests__/vuex.js +++ b/tests/__tests__/vuex.js @@ -1,7 +1,7 @@ import 'jest-dom/extend-expect' import VuexTest from './components/VuexTest' -import { render, fireEvent } from 'vue-testing-library' +import { render, fireEvent } from '@testing-library/vue' const store = { state: { From 89b9b265ed1aa6cf4deedbddc95b5e0bbe49308e Mon Sep 17 00:00:00 2001 From: Danie Cook Date: Sat, 1 Jun 2019 12:25:43 +0100 Subject: [PATCH 2/4] Add missing file --- cleanup-after-each.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 cleanup-after-each.js diff --git a/cleanup-after-each.js b/cleanup-after-each.js new file mode 100644 index 00000000..f0a17c95 --- /dev/null +++ b/cleanup-after-each.js @@ -0,0 +1 @@ +afterEach(require('./dist').cleanup) From 6ff1d0479782b679c02ed58dd6c5a5c9740480f7 Mon Sep 17 00:00:00 2001 From: Danie Cook Date: Sat, 1 Jun 2019 12:30:40 +0100 Subject: [PATCH 3/4] Add cleanup to multi-test files --- tests/__tests__/stopwatch.js | 4 +++- tests/__tests__/vue-router.js | 4 +++- tests/__tests__/vuex.js | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/__tests__/stopwatch.js b/tests/__tests__/stopwatch.js index 5b3d8786..363f860d 100644 --- a/tests/__tests__/stopwatch.js +++ b/tests/__tests__/stopwatch.js @@ -1,7 +1,9 @@ import StopWatch from './components/StopWatch.vue' -import { render, wait, fireEvent } from '@testing-library/vue' +import { cleanup, render, wait, fireEvent } from '@testing-library/vue' import 'jest-dom/extend-expect' +afterEach(cleanup) + test('unmounts a component', async () => { jest.spyOn(console, 'error').mockImplementation(() => {}) diff --git a/tests/__tests__/vue-router.js b/tests/__tests__/vue-router.js index 8d64bd44..76fd0dee 100644 --- a/tests/__tests__/vue-router.js +++ b/tests/__tests__/vue-router.js @@ -4,7 +4,7 @@ import App from './components/Router/App.vue' import Home from './components/Router/Home.vue' import About from './components/Router/About.vue' -import { render, fireEvent } from '@testing-library/vue' +import { cleanup, render, fireEvent } from '@testing-library/vue' const routes = [ { path: '/', component: Home }, @@ -12,6 +12,8 @@ const routes = [ { path: '*', redirect: '/about' } ] +afterEach(cleanup) + test('full app rendering/navigating', async () => { const { queryByTestId } = render(App, { routes }) diff --git a/tests/__tests__/vuex.js b/tests/__tests__/vuex.js index 14011aee..5b799bd2 100644 --- a/tests/__tests__/vuex.js +++ b/tests/__tests__/vuex.js @@ -1,7 +1,9 @@ import 'jest-dom/extend-expect' import VuexTest from './components/VuexTest' -import { render, fireEvent } from '@testing-library/vue' +import { cleanup, render, fireEvent } from '@testing-library/vue' + +afterEach(cleanup) const store = { state: { From 2909bcc3e1f94ad816ab0f0f9460f2efa012ced6 Mon Sep 17 00:00:00 2001 From: Danie Cook Date: Sat, 1 Jun 2019 13:04:25 +0100 Subject: [PATCH 4/4] 1.0.1 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 162e44e2..d0e63770 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "vue-testing-library", - "version": "1.0.0", + "version": "1.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 6e6574d8..e216d890 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@testing-library/vue", - "version": "1.0.0", + "version": "1.0.1", "description": "Simple and complete Vue DOM testing utilities that encourage good testing practices.", "main": "dist/vue-testing-library.js", "scripts": {