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 12, 2021
1 parent d34db83 commit 8eb2cee
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 3 deletions.
2 changes: 1 addition & 1 deletion e2e/3.x/custom-transformers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"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"
Expand Down
2 changes: 1 addition & 1 deletion e2e/3.x/style/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@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"
Expand Down
89 changes: 89 additions & 0 deletions e2e/test-runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
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 remove(dir, 'node_modules')
await remove(dir, 'yarn.lock')
await 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
19 changes: 19 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7114,6 +7114,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 +7963,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 +8145,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 8eb2cee

Please sign in to comment.