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

feat: support jest v27 in vue3-jest #343

Merged
merged 3 commits into from
Jul 19, 2021
Merged
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- image: circleci/node:10.16.3
- image: circleci/node:10.24.1

working_directory: ~/repo

Expand Down
1 change: 1 addition & 0 deletions e2e/2.x/custom-transformers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"@vue/test-utils": "^1.1.0",
"babel-jest": "^26.6.3",
"jest": "26.x",
"postcss": "^7.0.13",
"postcss-color-function": "^4.0.1",
Expand Down
7 changes: 4 additions & 3 deletions e2e/3.x/babel-in-package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
"@babel/preset-env": "^7.9.0",
"@vue/compiler-sfc": "^3.0.3",
"coffeescript": "^2.3.2",
"jest": "^26.0.0",
"ts-jest": "^26.4.4",
"jest": "^27.0.0",
"ts-jest": "^27.0.1",
"typescript": "^4.1.2",
"vue3-jest": "^26.0.0-alpha.10"
"vue3-jest": "^27.0.0-alpha.1"
},
"jest": {
"testEnvironment": "jsdom",
"moduleFileExtensions": [
"js",
"json",
Expand Down
7 changes: 4 additions & 3 deletions e2e/3.x/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@
"babel-plugin-transform-vue-jsx": "^3.7.0",
"coffeescript": "^2.3.2",
"jade": "^1.11.0",
"jest": "^26.0.0",
"jest": "^27.0.0",
"pug": "^2.0.3",
"ts-jest": "^26.4.4",
"ts-jest": "^27.0.1",
"typescript": "^4.1.2",
"vue-class-component": "^8.0.0-beta.4",
"vue3-jest": "^26.0.0-alpha.10",
"vue3-jest": "^27.0.0-alpha.1",
"vue-property-decorator": "^10.0.0-rc.3"
},
"jest": {
"testEnvironment": "jsdom",
"moduleFileExtensions": [
"js",
"json",
Expand Down
14 changes: 8 additions & 6 deletions e2e/3.x/basic/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,23 @@ test('handles named exports', () => {
test('generates source maps for .vue files', () => {
const filePath = resolve(__dirname, './components/Basic.vue')
const fileString = readFileSync(filePath, { encoding: 'utf8' })

const { code } = jestVue.process(fileString, filePath, {
const config = {
moduleFileExtensions: ['js', 'vue']
})
}

const { code } = jestVue.process(fileString, filePath, { config })

expect(code).toMatchSnapshot()
})

test('generates source maps using src attributes', () => {
const filePath = resolve(__dirname, './components/SourceMapsSrc.vue')
const fileString = readFileSync(filePath, { encoding: 'utf8' })

const { code } = jestVue.process(fileString, filePath, {
const config = {
moduleFileExtensions: ['js', 'vue']
})
}

const { code } = jestVue.process(fileString, filePath, { config })

expect(code).toMatchSnapshot()
})
Expand Down
2 changes: 1 addition & 1 deletion e2e/3.x/custom-transformers/babel-transformer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { createTransformer } = require('babel-jest')
const { createTransformer } = require('babel-jest').default
module.exports = createTransformer({
presets: ['@babel/preset-env']
})
6 changes: 3 additions & 3 deletions e2e/3.x/custom-transformers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"babel-jest": "^26.0.0",
"babel-jest": "^27.0.0",
"extract-from-css": "^0.4.4",
"jest": "^26.0.0",
"jest": "^27.0.0",
"postcss": "^7.0.13",
"postcss-color-function": "^4.0.1",
"sass": "^1.23.7",
"vue3-jest": "^26.0.0-alpha.10"
"vue3-jest": "^27.0.0-alpha.1"
},
"jest": {
"moduleFileExtensions": [
Expand Down
5 changes: 3 additions & 2 deletions e2e/3.x/javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"coffeescript": "^2.3.2",
"jest": "^26.0.0",
"vue3-jest": "^26.0.0-alpha.10"
"jest": "^27.0.0",
"vue3-jest": "^27.0.0-alpha.1"
},
"jest": {
"testEnvironment": "jsdom",
"moduleFileExtensions": [
"js",
"json",
Expand Down
5 changes: 3 additions & 2 deletions e2e/3.x/style/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"@vue/test-utils": "^1.1.0",
"jest": "^26.0.0",
"jest": "^27.0.0",
"less": "^3.9.0",
"postcss": "^7.0.13",
"sass": "^1.23.7",
"stylus": "^0.54.5",
"vue3-jest": "^26.0.0-alpha.10"
"vue3-jest": "^27.0.0-alpha.1"
},
"jest": {
"testEnvironment": "jsdom",
"moduleFileExtensions": [
"js",
"json",
Expand Down
43 changes: 43 additions & 0 deletions e2e/3.x/typescript-with-babel/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "vue3-typescript-with-babel",
"version": "1.0.0",
"license": "MIT",
"private": true,
"scripts": {
"test": "jest --no-cache ./sub-project/test.js"
},
"dependencies": {
"@vue/compiler-sfc": "^3.0.3",
"vue": "^3.0.3"
},
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"jest": "^27.0.0",
"ts-jest": "^27.0.1",
"typescript": "^4.1.2",
"vue3-jest": "^27.0.0-alpha.1"
},
"jest": {
"testEnvironment": "jsdom",
"globals": {
"vue-jest": {
"tsConfig": "./sub-project/tsconfig.json"
}
},
"moduleFileExtensions": [
"js",
"json",
"vue"
],
"transform": {
"^.+\\.js$": "babel-jest",
"^.+\\.vue$": "vue3-jest"
}
},
"babel": {
"presets": [
"@babel/env"
]
}
}
28 changes: 11 additions & 17 deletions e2e/3.x/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,33 @@
"license": "MIT",
"private": true,
"scripts": {
"test": "jest --no-cache ./sub-project/test.js"
"test": "jest --no-cache ./src/test.ts"
},
"dependencies": {
"@vue/compiler-sfc": "^3.0.3",
"vue": "^3.0.3"
},
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"jest": "^26.0.0",
"ts-jest": "^26.4.4",
"@types/jest": "16.0.10",
"jest": "^27.0.0",
"ts-jest": "^27.0.1",
"typescript": "^4.1.2",
"vue3-jest": "^26.0.0-alpha.10"
"vue3-jest": "^27.0.0-alpha.1"
},
"jest": {
"globals": {
"vue-jest": {
"tsConfig": "./sub-project/tsconfig.json"
}
},
"testEnvironment": "jsdom",
"moduleFileExtensions": [
"js",
"ts",
"json",
"vue"
],
"moduleNameMapper": {
"^@/(.*)$": "<rootDir>/src/$1"
},
"transform": {
"^.+\\.js$": "babel-jest",
"^.+\\.ts$": "ts-jest",
"^.+\\.vue$": "vue3-jest"
}
},
"babel": {
"presets": [
"@babel/env"
]
}
}
45 changes: 45 additions & 0 deletions e2e/3.x/typescript/src/components/Basic.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<template>
<div class="hello">
<h1 :class="headingClasses">{{ msg }}</h1>
</div>
</template>

<style module="css">
.testA {
background-color: red;
}
</style>
<style module>
.testB {
background-color: blue;
}
</style>
<style>
.testC {
background-color: blue;
}
</style>

<script lang="ts">
import { computed, defineComponent, ref } from 'vue'

export default defineComponent({
name: 'basic',
setup() {
const msg = 'Welcome to Your Vue.js App'
const isCrazy = ref(false)
const headingClasses = computed(() => ({
red: isCrazy,
blue: !isCrazy,
shadow: isCrazy
}))
const toggleClass = () => (isCrazy.value = !isCrazy.value)
return {
msg,
isCrazy,
headingClasses,
toggleClass
}
}
})
</script>
5 changes: 5 additions & 0 deletions e2e/3.x/typescript/src/shims-vue.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module '*.vue' {
import type { DefineComponent } from 'vue';
const component: DefineComponent<{}, {}, any>;
export default component;
}
23 changes: 23 additions & 0 deletions e2e/3.x/typescript/src/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { createApp, h } from 'vue'

import Basic from '@/components/Basic.vue'

function mount(Component: any) {
document.getElementsByTagName('html')[0].innerHTML = ''
const el = document.createElement('div')
el.id = 'app'
document.body.appendChild(el)
const Parent = {
render() {
return h(Component)
}
}
createApp(Parent).mount(el)
}

test('processes .vue files', () => {
mount(Basic)
expect(document.querySelector('h1')!.textContent).toBe(
'Welcome to Your Vue.js App'
)
})
24 changes: 24 additions & 0 deletions e2e/3.x/typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"useDefineForClassFields": true,
"sourceMap": true,
"baseUrl": ".",
"types": ["webpack-env", "jest"],
"paths": {
"@/*": ["src/*"]
},
"lib": ["esnext", "dom", "dom.iterable", "scripthost"]
},
"include": ["src/**/*.ts", "src/**/*.vue"],
"exclude": ["node_modules"]
}
9 changes: 4 additions & 5 deletions packages/vue3-jest/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
const crypto = require('crypto')
const babelJest = require('babel-jest')

const babelJest = require('babel-jest').default
module.exports = {
process: require('./process'),
getCacheKey: function getCacheKey(
fileData,
filename,
configString,
{ config, instrument, rootDir }
{ config, configString, instrument, rootDir }
) {
return crypto
.createHash('md5')
.update(
babelJest.getCacheKey(fileData, filename, configString, {
babelJest.getCacheKey(fileData, filename, {
config,
configString,
instrument,
rootDir
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/vue3-jest/lib/process-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ module.exports = function processStyle(stylePart, filePath, config = {}) {
const preprocessOptions = getPreprocessOptions(
stylePart.lang,
filePath,
config
config.config
)
const result = compileStyle({
id: `vue-jest-${filePath}`,
Expand Down
2 changes: 1 addition & 1 deletion packages/vue3-jest/lib/process.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { parse, compileTemplate, compileScript } = require('@vue/compiler-sfc')
const { transform } = require('@babel/core')
const babelTransformer = require('babel-jest')
const babelTransformer = require('babel-jest').default

const typescriptTransformer = require('./transformers/typescript')
const coffeescriptTransformer = require('./transformers/coffee')
Expand Down
2 changes: 1 addition & 1 deletion packages/vue3-jest/lib/transformers/coffee.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const throwError = require('../utils').throwError
const getBabelOptions = require('../utils').getBabelOptions

module.exports = {
process(src, filename, config) {
process(src, filename) {
ensureRequire('coffee', ['coffeescript'])
const coffee = require('coffeescript')
const babelOptions = getBabelOptions(filename)
Expand Down
Loading