Skip to content

Commit

Permalink
chore: run e2e tests on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
pmrotule committed Oct 11, 2021
1 parent d34db83 commit aeacd25
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 23 deletions.
4 changes: 2 additions & 2 deletions e2e/2.x/babel-in-package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -29,7 +29,7 @@
],
"transform": {
"^.+\\.js$": "babel-jest",
"^.+\\.vue$": "vue2-jest"
"^.+\\.vue$": "@vue/vue2-jest"
}
},
"babel": {
Expand Down
4 changes: 2 additions & 2 deletions e2e/2.x/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -34,7 +34,7 @@
],
"transform": {
"^.+\\.js$": "babel-jest",
"^.+\\.vue$": "vue2-jest"
"^.+\\.vue$": "@vue/vue2-jest"
},
"moduleNameMapper": {
"^~?__styles/(.*)$": "<rootDir>/components/styles/$1"
Expand Down
4 changes: 2 additions & 2 deletions e2e/2.x/custom-transformers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -28,7 +28,7 @@
],
"transform": {
"^.+\\.js$": "./babel-transformer.js",
"^.+\\.vue$": "vue2-jest"
"^.+\\.vue$": "@vue/vue2-jest"
},
"moduleNameMapper": {
"^~?__styles/(.*)$": "<rootDir>/components/styles/$1"
Expand Down
4 changes: 2 additions & 2 deletions e2e/2.x/style/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -29,7 +29,7 @@
],
"transform": {
"^.+\\.js$": "babel-jest",
"^.+\\.vue$": "vue2-jest"
"^.+\\.vue$": "@vue/vue2-jest"
},
"moduleNameMapper": {
"^~tmp/(.*)": "/tmp/$1",
Expand Down
4 changes: 2 additions & 2 deletions e2e/3.x/babel-in-package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -27,7 +27,7 @@
],
"transform": {
"^.+\\.js$": "babel-jest",
"^.+\\.vue$": "vue3-jest"
"^.+\\.vue$": "@vue/vue3-jest"
}
},
"babel": {
Expand Down
4 changes: 2 additions & 2 deletions e2e/3.x/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -36,7 +36,7 @@
"transform": {
"^.+\\.ts$": "ts-jest",
"^.+\\.js$": "babel-jest",
"^.+\\.vue$": "vue3-jest"
"^.+\\.vue$": "@vue/vue3-jest"
},
"moduleNameMapper": {
"^~?__styles/(.*)$": "<rootDir>/components/styles/$1"
Expand Down
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 @@ -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": [
Expand All @@ -29,7 +29,7 @@
],
"transform": {
"^.+\\.js$": "./babel-transformer.js",
"^.+\\.vue$": "vue3-jest"
"^.+\\.vue$": "@vue/vue3-jest"
},
"moduleNameMapper": {
"^~?__styles/(.*)$": "<rootDir>/components/styles/$1"
Expand Down
4 changes: 2 additions & 2 deletions e2e/3.x/javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -24,7 +24,7 @@
],
"transform": {
"^.+\\.js$": "babel-jest",
"^.+\\.vue$": "vue3-jest"
"^.+\\.vue$": "@vue/vue3-jest"
}
},
"babel": {
Expand Down
6 changes: 3 additions & 3 deletions e2e/3.x/style/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -29,7 +29,7 @@
],
"transform": {
"^.+\\.js$": "babel-jest",
"^.+\\.vue$": "vue3-jest"
"^.+\\.vue$": "@vue/vue3-jest"
},
"moduleNameMapper": {
"^~?__styles/(.*)$": "<rootDir>/components/styles/$1"
Expand Down
4 changes: 2 additions & 2 deletions e2e/3.x/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -31,7 +31,7 @@
],
"transform": {
"^.+\\.js$": "babel-jest",
"^.+\\.vue$": "vue3-jest"
"^.+\\.vue$": "@vue/vue3-jest"
}
},
"babel": {
Expand Down
91 changes: 91 additions & 0 deletions e2e/test-runner.js
Original file line number Diff line number Diff line change
@@ -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/<projects dir>`, or
// `yarn test:e2e --cache 3.x/<projects dir>`.
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()
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
38 changes: 38 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit aeacd25

Please sign in to comment.