From ed11471b682239c7d8ac678fd13bb90dca3fac14 Mon Sep 17 00:00:00 2001 From: neverland Date: Wed, 29 Aug 2018 15:19:32 +0800 Subject: [PATCH] [Build] add object assign transform (#1713) --- babel.config.js | 11 ++++++----- jest.config.js | 3 ++- package.json | 3 +++ test/jest.init.js | 1 + test/jest.transform.js | 3 +++ yarn.lock | 23 ++++++++++++++++++++++- 6 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 test/jest.init.js create mode 100644 test/jest.transform.js diff --git a/babel.config.js b/babel.config.js index 5cf919dfd..7bfd419ad 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,8 +1,8 @@ module.exports = function(api) { - const { BABEL_MODULE } = process.env; - const useESModules = BABEL_MODULE !== 'commonjs'; + const { BABEL_MODULE, NODE_ENV } = process.env; + const useESModules = BABEL_MODULE !== 'commonjs' && NODE_ENV !== 'test'; - api.cache(false); + api && api.cache(false); return { presets: [ @@ -10,7 +10,7 @@ module.exports = function(api) { '@babel/preset-env', { loose: true, - modules: BABEL_MODULE || false + modules: useESModules ? false : 'commonjs' } ] ], @@ -24,7 +24,8 @@ module.exports = function(api) { useESModules } ], - '@babel/plugin-syntax-dynamic-import' + '@babel/plugin-syntax-dynamic-import', + '@babel/plugin-transform-object-assign' ] }; }; diff --git a/jest.config.js b/jest.config.js index 942758cff..f926c25d5 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,7 +1,8 @@ module.exports = { + setupFiles: ['/test/jest.init.js'], moduleFileExtensions: ['js', 'vue'], transform: { - '^.+\\.js$': '/node_modules/babel-jest', + '^.+\\.js$': '/test/jest.transform.js', '.*\\.(vue)$': '/node_modules/vue-jest' }, moduleNameMapper: { diff --git a/package.json b/package.json index 47c494623..b4e00ed8e 100644 --- a/package.json +++ b/package.json @@ -61,11 +61,14 @@ "devDependencies": { "@babel/core": "^7.0.0", "@babel/plugin-syntax-dynamic-import": "^7.0.0", + "@babel/plugin-transform-object-assign": "^7.0.0", "@babel/plugin-transform-runtime": "^7.0.0", + "@babel/polyfill": "^7.0.0", "@babel/preset-env": "^7.0.0", "@vue/server-test-utils": "^1.0.0-beta.24", "@vue/test-utils": "^1.0.0-beta.24", "autoprefixer": "^9.1.3", + "babel-core": "^7.0.0-0", "babel-jest": "^23.4.2", "babel-loader": "^8.0.0", "codecov": "^3.0.4", diff --git a/test/jest.init.js b/test/jest.init.js new file mode 100644 index 000000000..c7c823054 --- /dev/null +++ b/test/jest.init.js @@ -0,0 +1 @@ +require('@babel/polyfill'); diff --git a/test/jest.transform.js b/test/jest.transform.js new file mode 100644 index 000000000..a1b580d9c --- /dev/null +++ b/test/jest.transform.js @@ -0,0 +1,3 @@ +const babelConfig = require('../babel.config'); + +module.exports = require('babel-jest').createTransformer(babelConfig()); diff --git a/yarn.lock b/yarn.lock index 81fe9d6bc..ba2758808 100644 --- a/yarn.lock +++ b/yarn.lock @@ -506,6 +506,12 @@ dependencies: "@babel/helper-plugin-utils" "^7.0.0" +"@babel/plugin-transform-object-assign@^7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-object-assign/-/plugin-transform-object-assign-7.0.0.tgz#fca6d7500d9675c42868b8f3882979201b9a5ad8" + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-transform-object-super@^7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/@babel/plugin-transform-object-super/-/plugin-transform-object-super-7.0.0.tgz#b8587d511309b3a0e96e9e38169908b3e392041e" @@ -575,6 +581,13 @@ "@babel/helper-regex" "^7.0.0" regexpu-core "^4.1.3" +"@babel/polyfill@^7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/@babel/polyfill/-/polyfill-7.0.0.tgz#c8ff65c9ec3be6a1ba10113ebd40e8750fb90bff" + dependencies: + core-js "^2.5.7" + regenerator-runtime "^0.11.1" + "@babel/preset-env@^7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/@babel/preset-env/-/preset-env-7.0.0.tgz#f450f200c14e713f98cb14d113bf0c2cfbb89ca9" @@ -1422,6 +1435,10 @@ babel-core@^6.26.0: slash "^1.0.0" source-map "^0.5.6" +babel-core@^7.0.0-0: + version "7.0.0-bridge.0" + resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-7.0.0-bridge.0.tgz#95a492ddd90f9b4e9a4a1da14eb335b87b634ece" + babel-eslint@^8.2.3: version "8.2.3" resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-8.2.3.tgz#1a2e6681cc9bc4473c32899e59915e19cd6733cf" @@ -2409,6 +2426,10 @@ core-js@^2.4.0, core-js@^2.5.0: version "2.5.5" resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.5.5.tgz#b14dde936c640c0579a6b50cabcc132dd6127e3b" +core-js@^2.5.7: + version "2.5.7" + resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.5.7.tgz#f972608ff0cead68b841a16a932d0b183791814e" + core-util-is@1.0.2, core-util-is@~1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" @@ -8043,7 +8064,7 @@ regenerate@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.0.tgz#4a856ec4b56e4077c557589cae85e7a4c8869a11" -regenerator-runtime@^0.11.0: +regenerator-runtime@^0.11.0, regenerator-runtime@^0.11.1: version "0.11.1" resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9"