From 5581d6d407de379898736343948e75eda30516aa Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Thu, 7 Mar 2019 22:06:34 +0800 Subject: [PATCH] feat: add jest typeahead plugin closes #1908 --- .../cli-plugin-unit-jest/generator/index.js | 39 +++++++++++-------- .../@vue/cli-plugin-unit-jest/package.json | 1 + yarn.lock | 22 ++++++++--- 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/packages/@vue/cli-plugin-unit-jest/generator/index.js b/packages/@vue/cli-plugin-unit-jest/generator/index.js index 5b3c226335..555c9f6be8 100644 --- a/packages/@vue/cli-plugin-unit-jest/generator/index.js +++ b/packages/@vue/cli-plugin-unit-jest/generator/index.js @@ -11,31 +11,34 @@ module.exports = (api, _, __, invoking) => { '@vue/test-utils': '1.0.0-beta.29' }, jest: { - 'moduleFileExtensions': [ + moduleFileExtensions: [ 'js', 'jsx', 'json', // tell Jest to handle *.vue files 'vue' ], - 'transform': { + transform: { // process *.vue files with vue-jest '^.+\\.vue$': 'vue-jest', - '.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub' + '.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': + 'jest-transform-stub' }, // support the same @ -> src alias mapping in source code - 'moduleNameMapper': { + moduleNameMapper: { '^@/(.*)$': '/src/$1' }, // serializer for snapshots - 'snapshotSerializers': [ - 'jest-serializer-vue' - ], - 'testMatch': [ + snapshotSerializers: ['jest-serializer-vue'], + testMatch: [ '**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)' ], // https://github.com/facebook/jest/issues/6766 - 'testURL': 'http://localhost/' + testURL: 'http://localhost/', + watchPlugins: [ + require.resolve('jest-watch-typeahead/filename'), + require.resolve('jest-watch-typeahead/testname') + ] } }) @@ -59,9 +62,13 @@ module.exports = (api, _, __, invoking) => { // Jest's shipped babel-jest still uses babel 6, // so we cannot use extendPackage which renders babel.config.js. api.render(files => { - files['.babelrc'] = JSON.stringify({ - plugins: ['transform-es2015-modules-commonjs'] - }, null, 2) + files['.babelrc'] = JSON.stringify( + { + plugins: ['transform-es2015-modules-commonjs'] + }, + null, + 2 + ) }) } } else { @@ -73,7 +80,7 @@ module.exports = (api, _, __, invoking) => { } } -const applyTS = module.exports.applyTS = (api, invoking) => { +const applyTS = (module.exports.applyTS = (api, invoking) => { api.extendPackage({ jest: { moduleFileExtensions: ['ts', 'tsx'], @@ -118,12 +125,12 @@ const applyTS = module.exports.applyTS = (api, invoking) => { } }) } -} +}) -const applyESLint = module.exports.applyESLint = api => { +const applyESLint = (module.exports.applyESLint = api => { api.render(files => { files['tests/unit/.eslintrc.js'] = api.genJSConfig({ env: { jest: true } }) }) -} +}) diff --git a/packages/@vue/cli-plugin-unit-jest/package.json b/packages/@vue/cli-plugin-unit-jest/package.json index c843746dae..41cc7ee38a 100644 --- a/packages/@vue/cli-plugin-unit-jest/package.json +++ b/packages/@vue/cli-plugin-unit-jest/package.json @@ -29,6 +29,7 @@ "jest": "^23.6.0", "jest-serializer-vue": "^2.0.2", "jest-transform-stub": "^2.0.0", + "jest-watch-typeahead": "^0.2.1", "vue-jest": "^3.0.3" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index 225ecd3a26..00fbea98d1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9993,7 +9993,19 @@ jest-validate@^23.6.0: leven "^2.1.0" pretty-format "^23.6.0" -jest-watcher@^23.4.0: +jest-watch-typeahead@^0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/jest-watch-typeahead/-/jest-watch-typeahead-0.2.1.tgz#6c40f232996ca6c39977e929e9f79b189e7d87e4" + integrity sha512-xdhEtKSj0gmnkDQbPTIHvcMmXNUDzYpHLEJ5TFqlaI+schi2NI96xhWiZk9QoesAS7oBmKwWWsHazTrYl2ORgg== + dependencies: + ansi-escapes "^3.0.0" + chalk "^2.4.1" + jest-watcher "^23.1.0" + slash "^2.0.0" + string-length "^2.0.0" + strip-ansi "^5.0.0" + +jest-watcher@^23.1.0, jest-watcher@^23.4.0: version "23.4.0" resolved "https://registry.yarnpkg.com/jest-watcher/-/jest-watcher-23.4.0.tgz#d2e28ce74f8dad6c6afc922b92cabef6ed05c91c" integrity sha1-0uKM50+NrWxq/JIrksq+9u0FyRw= @@ -16735,10 +16747,10 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript@~3.2.2: - version "3.2.4" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.2.4.tgz#c585cb952912263d915b462726ce244ba510ef3d" - integrity sha512-0RNDbSdEokBeEAkgNbxJ+BLwSManFy9TeXz8uW+48j/xhEXv1ePME60olyzw2XzUqUBNAYFeJadIqAgNqIACwg== +typescript@^3.2.1: + version "3.3.3333" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.3.3333.tgz#171b2c5af66c59e9431199117a3bcadc66fdcfd6" + integrity sha512-JjSKsAfuHBE/fB2oZ8NxtRTk5iGcg6hkYXMnZ3Wc+b2RSqejEqTaem11mHASMnFilHrax3sLK0GDzcJrekZYLw== uc.micro@^1.0.1, uc.micro@^1.0.5: version "1.0.6"