Skip to content

Commit 8eb2cee

Browse files
committed
chore: run e2e tests on CI
1 parent d34db83 commit 8eb2cee

File tree

5 files changed

+112
-3
lines changed

5 files changed

+112
-3
lines changed

e2e/3.x/custom-transformers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"babel-jest": "^26.0.0",
1717
"extract-from-css": "^0.4.4",
1818
"jest": "^26.0.0",
19-
"postcss": "^7.0.13",
19+
"postcss": "^8.3.5",
2020
"postcss-color-function": "^4.0.1",
2121
"sass": "^1.23.7",
2222
"vue3-jest": "^26.0.0-alpha.10"

e2e/3.x/style/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"@vue/test-utils": "^1.1.0",
1717
"jest": "^26.0.0",
1818
"less": "^3.9.0",
19-
"postcss": "^7.0.13",
19+
"postcss": "^8.3.5",
2020
"sass": "^1.23.7",
2121
"stylus": "^0.54.5",
2222
"vue3-jest": "^26.0.0-alpha.10"

e2e/test-runner.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
const { spawn } = require('child_process')
4+
const chalk = require('chalk')
5+
const rimraf = require('rimraf')
6+
7+
// Can be run as `yarn test:e2e --cache` to forego reinstalling node_modules, or
8+
// `yarn test:e2e 3.x`, or `yarn test:e2e 3.x/<projects dir>`, or
9+
// `yarn test:e2e --cache 3.x/<projects dir>`.
10+
const args = process.argv.slice(2)
11+
12+
async function runTests() {
13+
const versionDirectories = ['2.x', '3.x']
14+
const filteredVersionDirectories = filterDirectories(versionDirectories)
15+
const absVersionDirectories = filteredVersionDirectories.map(dir =>
16+
path.join(__dirname, dir)
17+
)
18+
19+
for (const versionDirectory of absVersionDirectories) {
20+
const fixtureDirectories = fs
21+
.readdirSync(versionDirectory, { withFileTypes: true })
22+
.filter(dirent => dirent.isDirectory())
23+
.map(dirent => dirent.name)
24+
25+
const filteredDirectories = filterDirectories(fixtureDirectories)
26+
const absFixtureDirectories = filteredDirectories.map(
27+
dir => `${versionDirectory}/${dir}`
28+
)
29+
30+
for (const directory of absFixtureDirectories) await runTest(directory)
31+
}
32+
}
33+
34+
async function runTest(dir) {
35+
if (!args.includes('--cache')) {
36+
await remove(dir, 'node_modules')
37+
await remove(dir, 'yarn.lock')
38+
await installDependencies(dir)
39+
}
40+
logStep(dir, 'Running tests')
41+
await execute(dir, 'yarn test')
42+
43+
success(`(${dir}) Complete`)
44+
}
45+
46+
async function remove(dir, target) {
47+
logStep(dir, `Removing ${target}`)
48+
await new Promise(resolve => rimraf(`${dir}/${target}`, resolve))
49+
}
50+
51+
async function installDependencies(dir) {
52+
logStep(dir, 'Installing node_modules')
53+
await execute(dir, 'yarn install --silent')
54+
}
55+
56+
async function execute(dir, command) {
57+
const exitCode = await new Promise((resolve, reject) => {
58+
const [cmd, ...args] = command.split(' ')
59+
const child = spawn(cmd, args, { cwd: dir, stdio: 'inherit' })
60+
child.on('close', resolve)
61+
child.on('error', reject)
62+
})
63+
if (exitCode !== 0) process.exit(exitCode)
64+
}
65+
66+
function filterDirectories(directories) {
67+
const filtered = directories.filter(dir =>
68+
args.some(arg => arg.includes(dir))
69+
)
70+
return filtered.length ? filtered : directories
71+
}
72+
73+
function logStep(dir, msg) {
74+
return info(`(${dir}) ${msg}`)
75+
}
76+
77+
function success(msg) {
78+
console.info(chalk.green(formatLog(msg)))
79+
}
80+
81+
function info(msg) {
82+
console.info(chalk.blueBright(formatLog(msg)))
83+
}
84+
85+
function formatLog(msg) {
86+
return `\n[vue-jest]: ${msg}\n`
87+
}
88+
89+
runTests()

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"format:check": "prettier --no-semi --single-quote --check \"**/*.{js,json,md}\"",
2020
"lint": "eslint --ignore-path .gitignore \"{,!(node_modules)/**/}*.js\"",
2121
"lint:fix": "yarn lint --fix",
22-
"test": "yarn lint && yarn format:check && yarn workspaces run test"
22+
"test": "yarn lint && yarn format:check && yarn test:e2e && yarn workspaces run test",
23+
"test:e2e": "node e2e/test-runner"
2324
},
2425
"devDependencies": {
2526
"eslint": "^5.12.0",

yarn.lock

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7114,6 +7114,11 @@ nanoid@^3.1.23:
71147114
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.23.tgz#f744086ce7c2bc47ee0a8472574d5c78e4183a81"
71157115
integrity sha512-FiB0kzdP0FFVGDKlRLEQ1BgDzU87dy5NnzjeW9YZNt+/c3+q82EQDUwniSAUxp/F0gFNI1ZhKU1FqYsMuqZVnw==
71167116

7117+
nanoid@^3.1.28:
7118+
version "3.1.29"
7119+
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.29.tgz#214fb2d7a33e1a5bef4757b779dfaeb6a4e5aeb4"
7120+
integrity sha512-dW2pUSGZ8ZnCFIlBIA31SV8huOGCHb6OwzVCc7A69rb/a+SgPBwfmLvK5TKQ3INPbRkcI8a/Owo0XbiTNH19wg==
7121+
71177122
nanomatch@^1.2.9:
71187123
version "1.2.13"
71197124
resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119"
@@ -7958,6 +7963,11 @@ performance-now@^2.1.0:
79587963
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
79597964
integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=
79607965

7966+
picocolors@^0.2.1:
7967+
version "0.2.1"
7968+
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-0.2.1.tgz#570670f793646851d1ba135996962abad587859f"
7969+
integrity sha512-cMlDqaLEqfSaW8Z7N5Jw+lyIW869EzT73/F5lhtY9cLGoVxSXznfgfXMO0Z5K0o0Q2TkTXq+0KFsdnSe3jDViA==
7970+
79617971
picomatch@^2.0.4, picomatch@^2.0.5, picomatch@^2.0.7, picomatch@^2.2.1:
79627972
version "2.2.1"
79637973
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.2.1.tgz#21bac888b6ed8601f831ce7816e335bc779f0a4a"
@@ -8135,6 +8145,15 @@ postcss@^8.1.10:
81358145
nanoid "^3.1.23"
81368146
source-map-js "^0.6.2"
81378147

8148+
postcss@^8.3.5:
8149+
version "8.3.9"
8150+
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.3.9.tgz#98754caa06c4ee9eb59cc48bd073bb6bd3437c31"
8151+
integrity sha512-f/ZFyAKh9Dnqytx5X62jgjhhzttjZS7hMsohcI7HEI5tjELX/HxCy3EFhsRxyzGvrzFF+82XPvCS8T9TFleVJw==
8152+
dependencies:
8153+
nanoid "^3.1.28"
8154+
picocolors "^0.2.1"
8155+
source-map-js "^0.6.2"
8156+
81388157
prelude-ls@~1.1.2:
81398158
version "1.1.2"
81408159
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"

0 commit comments

Comments
 (0)