Skip to content

Commit

Permalink
feat: support jest v27
Browse files Browse the repository at this point in the history
And also babel-jest and ts-jest v27.
  • Loading branch information
cexbrayat committed May 27, 2021
1 parent d086ee5 commit fdf77e2
Show file tree
Hide file tree
Showing 16 changed files with 815 additions and 631 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
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
5 changes: 3 additions & 2 deletions e2e/__projects__/babel-in-package/package.json
Expand Up @@ -10,12 +10,13 @@
"dependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"jest": "^26.0.0",
"ts-jest": "^26.4.4",
"jest": "^27.0.0",
"ts-jest": "^27.0.0",
"typescript": "^4.1.2",
"vue": "^3.0.3"
},
"jest": {
"testEnvironment": "jsdom",
"moduleFileExtensions": [
"js",
"json",
Expand Down
5 changes: 3 additions & 2 deletions e2e/__projects__/basic/package.json
Expand Up @@ -17,13 +17,14 @@
"babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-plugin-transform-vue-jsx": "^3.7.0",
"jest": "^26.0.0",
"ts-jest": "^26.4.4",
"jest": "^27.0.0",
"ts-jest": "^27.0.1",
"typescript": "^4.1.2",
"vue-class-component": "^8.0.0-beta.4",
"vue-property-decorator": "^10.0.0-rc.3"
},
"jest": {
"testEnvironment": "jsdom",
"moduleFileExtensions": [
"js",
"json",
Expand Down
14 changes: 8 additions & 6 deletions e2e/__projects__/basic/test.js
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/__projects__/custom-transformers/babel-transformer.js
@@ -1,4 +1,4 @@
const { createTransformer } = require('babel-jest')
const { createTransformer } = require('babel-jest').default
module.exports = createTransformer({
presets: ['@babel/preset-env']
})
2 changes: 1 addition & 1 deletion e2e/__projects__/custom-transformers/package.json
Expand Up @@ -14,7 +14,7 @@
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"jest": "^26.0.0",
"jest": "^27.0.0",
"postcss": "^7.0.13",
"postcss-color-function": "^4.0.1",
"sass": "^1.23.7"
Expand Down
3 changes: 2 additions & 1 deletion e2e/__projects__/javascript/package.json
Expand Up @@ -13,9 +13,10 @@
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"jest": "^26.0.0"
"jest": "^27.0.0"
},
"jest": {
"testEnvironment": "jsdom",
"moduleFileExtensions": [
"js",
"json",
Expand Down
2 changes: 1 addition & 1 deletion e2e/__projects__/style/package.json
Expand Up @@ -15,7 +15,7 @@
"@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",
"postcss": "^7.0.13",
"sass": "^1.23.7"
},
Expand Down
3 changes: 2 additions & 1 deletion e2e/__projects__/typescript/package.json
Expand Up @@ -13,14 +13,15 @@
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"jest": "^26.0.0"
"jest": "^27.0.0"
},
"jest": {
"globals": {
"vue-jest": {
"tsConfig": "./sub-project/tsconfig.json"
}
},
"testEnvironment": "jsdom",
"moduleFileExtensions": [
"js",
"json",
Expand Down
9 changes: 4 additions & 5 deletions lib/index.js
@@ -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 lib/process.js
@@ -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 lib/transformers/coffee.js
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
2 changes: 1 addition & 1 deletion lib/transformers/typescript.js
@@ -1,5 +1,5 @@
const ensureRequire = require('../ensure-require')
const babelJest = require('babel-jest')
const babelJest = require('babel-jest').default
const {
getBabelOptions,
getTsJestConfig,
Expand Down
11 changes: 7 additions & 4 deletions lib/utils.js
Expand Up @@ -49,7 +49,11 @@ const transformContent = function transformContent(

const getVueJestConfig = function getVueJestConfig(jestConfig) {
return (
(jestConfig && jestConfig.globals && jestConfig.globals['vue-jest']) || {}
(jestConfig &&
jestConfig.config &&
jestConfig.config.globals &&
jestConfig.config.globals['vue-jest']) ||
{}
)
}
const getBabelOptions = function loadBabelOptions(filename, options = {}) {
Expand All @@ -74,9 +78,8 @@ const getTsJestConfig = function getTsJestConfig(config) {
return null
}

const createTransformer = require('ts-jest').createTransformer
const tr = createTransformer()
const configSet = tr.configsFor(config)
const { ConfigSet } = require('ts-jest/dist/config/config-set')
const configSet = new ConfigSet(config)
const tsConfig = configSet.typescript || configSet.parsedTsConfig
// Force es5 to prevent const vue_1 = require('vue') from conflicting
return { compilerOptions: { ...tsConfig.options, target: 'es5' } }
Expand Down
12 changes: 6 additions & 6 deletions package.json
Expand Up @@ -33,7 +33,7 @@
"@babel/preset-env": "^7.9.0",
"@vue/compiler-sfc": "^3.0.3",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^26.0.0",
"babel-jest": "^27.0.0",
"coffeescript": "^2.3.2",
"conventional-changelog": "^1.1.5",
"eslint": "^5.12.0",
Expand All @@ -48,23 +48,23 @@
"hamljs": "^0.6.2",
"husky": "^1.1.4",
"jade": "^1.11.0",
"jest": "^26.0.0",
"jest": "^27.0.0",
"less": "^3.9.0",
"lint-staged": "^8.0.5",
"prettier": "^1.16.1",
"pug": "^2.0.3",
"sass": "^1.23.7",
"semantic-release": "^15.13.2",
"stylus": "^0.54.5",
"ts-jest": "^26.4.4",
"ts-jest": "^27.0.1",
"typescript": "^4.1.2",
"vue": "^3.0.3"
},
"peerDependencies": {
"@babel/core": "7.x",
"babel-jest": ">= 24 < 27",
"jest": ">= 24 < 27 ",
"ts-jest": ">= 24 < 27 ",
"babel-jest": ">= 24 < 28",
"jest": ">= 24 < 28 ",
"ts-jest": ">= 24 < 28 ",
"typescript": ">= 3.x",
"vue": "^3.0.0-0"
},
Expand Down

0 comments on commit fdf77e2

Please sign in to comment.