From aeacd25ecbddf3d58fd35ec00d49c2dfcdf16a9a Mon Sep 17 00:00:00 2001 From: Pierre-Michel Brown Date: Mon, 11 Oct 2021 17:21:12 +0200 Subject: [PATCH] chore: run e2e tests on CI --- e2e/2.x/babel-in-package/package.json | 4 +- e2e/2.x/basic/package.json | 4 +- e2e/2.x/custom-transformers/package.json | 4 +- e2e/2.x/style/package.json | 4 +- e2e/3.x/babel-in-package/package.json | 4 +- e2e/3.x/basic/package.json | 4 +- e2e/3.x/custom-transformers/package.json | 6 +- e2e/3.x/javascript/package.json | 4 +- e2e/3.x/style/package.json | 6 +- e2e/3.x/typescript/package.json | 4 +- e2e/test-runner.js | 91 ++++++++++++++++++++++++ package.json | 3 +- yarn.lock | 38 ++++++++++ 13 files changed, 153 insertions(+), 23 deletions(-) create mode 100644 e2e/test-runner.js diff --git a/e2e/2.x/babel-in-package/package.json b/e2e/2.x/babel-in-package/package.json index 984b4c98..5a342b5b 100644 --- a/e2e/2.x/babel-in-package/package.json +++ b/e2e/2.x/babel-in-package/package.json @@ -19,7 +19,7 @@ "jest": "26.x", "ts-jest": "^26.3.0", "typescript": "^3.2.2", - "vue2-jest": "~26.0.0" + "@vue/vue2-jest": "file:../../../packages/vue2-jest" }, "jest": { "moduleFileExtensions": [ @@ -29,7 +29,7 @@ ], "transform": { "^.+\\.js$": "babel-jest", - "^.+\\.vue$": "vue2-jest" + "^.+\\.vue$": "@vue/vue2-jest" } }, "babel": { diff --git a/e2e/2.x/basic/package.json b/e2e/2.x/basic/package.json index e94c43e5..37f42234 100644 --- a/e2e/2.x/basic/package.json +++ b/e2e/2.x/basic/package.json @@ -24,7 +24,7 @@ "sass": "^1.23.7", "ts-jest": "^26.3.0", "typescript": "^3.2.2", - "vue2-jest": "~26.0.0" + "@vue/vue2-jest": "file:../../../packages/vue2-jest" }, "jest": { "moduleFileExtensions": [ @@ -34,7 +34,7 @@ ], "transform": { "^.+\\.js$": "babel-jest", - "^.+\\.vue$": "vue2-jest" + "^.+\\.vue$": "@vue/vue2-jest" }, "moduleNameMapper": { "^~?__styles/(.*)$": "/components/styles/$1" diff --git a/e2e/2.x/custom-transformers/package.json b/e2e/2.x/custom-transformers/package.json index ca6d8d79..2659be74 100644 --- a/e2e/2.x/custom-transformers/package.json +++ b/e2e/2.x/custom-transformers/package.json @@ -18,7 +18,7 @@ "postcss": "^7.0.13", "postcss-color-function": "^4.0.1", "sass": "^1.23.7", - "vue2-jest": "~26.0.0" + "@vue/vue2-jest": "file:../../../packages/vue2-jest" }, "jest": { "moduleFileExtensions": [ @@ -28,7 +28,7 @@ ], "transform": { "^.+\\.js$": "./babel-transformer.js", - "^.+\\.vue$": "vue2-jest" + "^.+\\.vue$": "@vue/vue2-jest" }, "moduleNameMapper": { "^~?__styles/(.*)$": "/components/styles/$1" diff --git a/e2e/2.x/style/package.json b/e2e/2.x/style/package.json index 069108b2..5cc1e47a 100644 --- a/e2e/2.x/style/package.json +++ b/e2e/2.x/style/package.json @@ -19,7 +19,7 @@ "postcss": "^7.0.13", "sass": "^1.23.7", "stylus": "^0.54.5", - "vue2-jest": "~26.0.0" + "@vue/vue2-jest": "file:../../../packages/vue2-jest" }, "jest": { "moduleFileExtensions": [ @@ -29,7 +29,7 @@ ], "transform": { "^.+\\.js$": "babel-jest", - "^.+\\.vue$": "vue2-jest" + "^.+\\.vue$": "@vue/vue2-jest" }, "moduleNameMapper": { "^~tmp/(.*)": "/tmp/$1", diff --git a/e2e/3.x/babel-in-package/package.json b/e2e/3.x/babel-in-package/package.json index 23c24c39..73557f05 100644 --- a/e2e/3.x/babel-in-package/package.json +++ b/e2e/3.x/babel-in-package/package.json @@ -17,7 +17,7 @@ "jest": "^26.0.0", "ts-jest": "^26.4.4", "typescript": "^4.1.2", - "vue3-jest": "^26.0.0-alpha.10" + "@vue/vue3-jest": "file:../../../packages/vue3-jest" }, "jest": { "moduleFileExtensions": [ @@ -27,7 +27,7 @@ ], "transform": { "^.+\\.js$": "babel-jest", - "^.+\\.vue$": "vue3-jest" + "^.+\\.vue$": "@vue/vue3-jest" } }, "babel": { diff --git a/e2e/3.x/basic/package.json b/e2e/3.x/basic/package.json index 95365075..f4c948f7 100644 --- a/e2e/3.x/basic/package.json +++ b/e2e/3.x/basic/package.json @@ -23,7 +23,7 @@ "ts-jest": "^26.4.4", "typescript": "^4.1.2", "vue-class-component": "^8.0.0-beta.4", - "vue3-jest": "^26.0.0-alpha.10", + "@vue/vue3-jest": "file:../../../packages/vue3-jest", "vue-property-decorator": "^10.0.0-rc.3" }, "jest": { @@ -36,7 +36,7 @@ "transform": { "^.+\\.ts$": "ts-jest", "^.+\\.js$": "babel-jest", - "^.+\\.vue$": "vue3-jest" + "^.+\\.vue$": "@vue/vue3-jest" }, "moduleNameMapper": { "^~?__styles/(.*)$": "/components/styles/$1" diff --git a/e2e/3.x/custom-transformers/package.json b/e2e/3.x/custom-transformers/package.json index 4ba9d191..a23f48c1 100644 --- a/e2e/3.x/custom-transformers/package.json +++ b/e2e/3.x/custom-transformers/package.json @@ -16,10 +16,10 @@ "babel-jest": "^26.0.0", "extract-from-css": "^0.4.4", "jest": "^26.0.0", - "postcss": "^7.0.13", + "postcss": "^8.3.5", "postcss-color-function": "^4.0.1", "sass": "^1.23.7", - "vue3-jest": "^26.0.0-alpha.10" + "@vue/vue3-jest": "file:../../../packages/vue3-jest" }, "jest": { "moduleFileExtensions": [ @@ -29,7 +29,7 @@ ], "transform": { "^.+\\.js$": "./babel-transformer.js", - "^.+\\.vue$": "vue3-jest" + "^.+\\.vue$": "@vue/vue3-jest" }, "moduleNameMapper": { "^~?__styles/(.*)$": "/components/styles/$1" diff --git a/e2e/3.x/javascript/package.json b/e2e/3.x/javascript/package.json index 64b0db6e..a44eb759 100644 --- a/e2e/3.x/javascript/package.json +++ b/e2e/3.x/javascript/package.json @@ -14,7 +14,7 @@ "@babel/preset-env": "^7.9.0", "coffeescript": "^2.3.2", "jest": "^26.0.0", - "vue3-jest": "^26.0.0-alpha.10" + "@vue/vue3-jest": "file:../../../packages/vue3-jest" }, "jest": { "moduleFileExtensions": [ @@ -24,7 +24,7 @@ ], "transform": { "^.+\\.js$": "babel-jest", - "^.+\\.vue$": "vue3-jest" + "^.+\\.vue$": "@vue/vue3-jest" } }, "babel": { diff --git a/e2e/3.x/style/package.json b/e2e/3.x/style/package.json index 2e3724b2..98e05298 100644 --- a/e2e/3.x/style/package.json +++ b/e2e/3.x/style/package.json @@ -16,10 +16,10 @@ "@vue/test-utils": "^1.1.0", "jest": "^26.0.0", "less": "^3.9.0", - "postcss": "^7.0.13", + "postcss": "^8.3.5", "sass": "^1.23.7", "stylus": "^0.54.5", - "vue3-jest": "^26.0.0-alpha.10" + "@vue/vue3-jest": "file:../../../packages/vue3-jest" }, "jest": { "moduleFileExtensions": [ @@ -29,7 +29,7 @@ ], "transform": { "^.+\\.js$": "babel-jest", - "^.+\\.vue$": "vue3-jest" + "^.+\\.vue$": "@vue/vue3-jest" }, "moduleNameMapper": { "^~?__styles/(.*)$": "/components/styles/$1" diff --git a/e2e/3.x/typescript/package.json b/e2e/3.x/typescript/package.json index 293dd389..4d59e54d 100644 --- a/e2e/3.x/typescript/package.json +++ b/e2e/3.x/typescript/package.json @@ -16,7 +16,7 @@ "jest": "^26.0.0", "ts-jest": "^26.4.4", "typescript": "^4.1.2", - "vue3-jest": "^26.0.0-alpha.10" + "@vue/vue3-jest": "file:../../../packages/vue3-jest" }, "jest": { "globals": { @@ -31,7 +31,7 @@ ], "transform": { "^.+\\.js$": "babel-jest", - "^.+\\.vue$": "vue3-jest" + "^.+\\.vue$": "@vue/vue3-jest" } }, "babel": { diff --git a/e2e/test-runner.js b/e2e/test-runner.js new file mode 100644 index 00000000..8c9db912 --- /dev/null +++ b/e2e/test-runner.js @@ -0,0 +1,91 @@ +const fs = require('fs') +const path = require('path') +const { spawn } = require('child_process') +const chalk = require('chalk') +const rimraf = require('rimraf') + +// Can be run as `yarn test:e2e --cache` to forego reinstalling node_modules, or +// `yarn test:e2e 3.x`, or `yarn test:e2e 3.x/`, or +// `yarn test:e2e --cache 3.x/`. +const args = process.argv.slice(2) + +async function runTests() { + const versionDirectories = ['2.x', '3.x'] + const filteredVersionDirectories = filterDirectories(versionDirectories) + const absVersionDirectories = filteredVersionDirectories.map(dir => + path.join(__dirname, dir) + ) + + for (const versionDirectory of absVersionDirectories) { + const fixtureDirectories = fs + .readdirSync(versionDirectory, { withFileTypes: true }) + .filter(dirent => dirent.isDirectory()) + .map(dirent => dirent.name) + + const filteredDirectories = filterDirectories(fixtureDirectories) + const absFixtureDirectories = filteredDirectories.map( + dir => `${versionDirectory}/${dir}` + ) + + for (const directory of absFixtureDirectories) await runTest(directory) + } +} + +async function runTest(dir) { + if (!args.includes('--cache')) { + await Promise.all([ + remove(dir, 'node_modules'), + remove(dir, 'yarn.lock'), + installDependencies(dir) + ]) + } + logStep(dir, 'Running tests') + await execute(dir, 'yarn test') + + success(`(${dir}) Complete`) +} + +async function remove(dir, target) { + logStep(dir, `Removing ${target}`) + await new Promise(resolve => rimraf(`${dir}/${target}`, resolve)) +} + +async function installDependencies(dir) { + logStep(dir, 'Installing node_modules') + await execute(dir, 'yarn install --silent') +} + +async function execute(dir, command) { + const exitCode = await new Promise((resolve, reject) => { + const [cmd, ...args] = command.split(' ') + const child = spawn(cmd, args, { cwd: dir, stdio: 'inherit' }) + child.on('close', resolve) + child.on('error', reject) + }) + if (exitCode !== 0) process.exit(exitCode) +} + +function filterDirectories(directories) { + const filtered = directories.filter(dir => + args.some(arg => arg.includes(dir)) + ) + return filtered.length ? filtered : directories +} + +function logStep(dir, msg) { + return info(`(${dir}) ${msg}`) +} + +function success(msg) { + console.info(chalk.green(formatLog(msg))) +} + +function info(msg) { + console.info(chalk.blueBright(formatLog(msg))) +} + +function formatLog(msg) { + return `\n[vue-jest]: ${msg}\n` +} + +runTests() diff --git a/package.json b/package.json index 7fb27fef..c8a2504e 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "format:check": "prettier --no-semi --single-quote --check \"**/*.{js,json,md}\"", "lint": "eslint --ignore-path .gitignore \"{,!(node_modules)/**/}*.js\"", "lint:fix": "yarn lint --fix", - "test": "yarn lint && yarn format:check && yarn workspaces run test" + "test": "yarn lint && yarn format:check && yarn test:e2e && yarn workspaces run test", + "test:e2e": "node e2e/test-runner" }, "devDependencies": { "eslint": "^5.12.0", diff --git a/yarn.lock b/yarn.lock index ce3033d7..b4994acf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1739,6 +1739,25 @@ lodash "^4.17.15" pretty "^2.0.0" +"@vue/vue2-jest@file:packages/vue2-jest": + version "26.0.0" + dependencies: + "@babel/plugin-transform-modules-commonjs" "^7.2.0" + "@vue/component-compiler-utils" "^3.1.0" + chalk "^2.1.0" + extract-from-css "^0.4.4" + source-map "0.5.6" + +"@vue/vue3-jest@file:packages/vue3-jest": + version "26.0.0-alpha.10" + dependencies: + "@babel/plugin-transform-modules-commonjs" "^7.2.0" + chalk "^2.1.0" + convert-source-map "^1.6.0" + extract-from-css "^0.4.4" + source-map "0.5.6" + tsconfig "^7.0.0" + JSONStream@^1.0.4, JSONStream@^1.3.4, JSONStream@^1.3.5: version "1.3.5" resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.5.tgz#3208c1f08d3a4d99261ab64f92302bc15e111ca0" @@ -7114,6 +7133,11 @@ nanoid@^3.1.23: resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.23.tgz#f744086ce7c2bc47ee0a8472574d5c78e4183a81" integrity sha512-FiB0kzdP0FFVGDKlRLEQ1BgDzU87dy5NnzjeW9YZNt+/c3+q82EQDUwniSAUxp/F0gFNI1ZhKU1FqYsMuqZVnw== +nanoid@^3.1.28: + version "3.1.29" + resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.29.tgz#214fb2d7a33e1a5bef4757b779dfaeb6a4e5aeb4" + integrity sha512-dW2pUSGZ8ZnCFIlBIA31SV8huOGCHb6OwzVCc7A69rb/a+SgPBwfmLvK5TKQ3INPbRkcI8a/Owo0XbiTNH19wg== + nanomatch@^1.2.9: version "1.2.13" resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119" @@ -7958,6 +7982,11 @@ performance-now@^2.1.0: resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b" integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns= +picocolors@^0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-0.2.1.tgz#570670f793646851d1ba135996962abad587859f" + integrity sha512-cMlDqaLEqfSaW8Z7N5Jw+lyIW869EzT73/F5lhtY9cLGoVxSXznfgfXMO0Z5K0o0Q2TkTXq+0KFsdnSe3jDViA== + picomatch@^2.0.4, picomatch@^2.0.5, picomatch@^2.0.7, picomatch@^2.2.1: version "2.2.1" resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.2.1.tgz#21bac888b6ed8601f831ce7816e335bc779f0a4a" @@ -8135,6 +8164,15 @@ postcss@^8.1.10: nanoid "^3.1.23" source-map-js "^0.6.2" +postcss@^8.3.5: + version "8.3.9" + resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.3.9.tgz#98754caa06c4ee9eb59cc48bd073bb6bd3437c31" + integrity sha512-f/ZFyAKh9Dnqytx5X62jgjhhzttjZS7hMsohcI7HEI5tjELX/HxCy3EFhsRxyzGvrzFF+82XPvCS8T9TFleVJw== + dependencies: + nanoid "^3.1.28" + picocolors "^0.2.1" + source-map-js "^0.6.2" + prelude-ls@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"