-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathtest-runner.js
84 lines (67 loc) · 2.33 KB
/
test-runner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const { spawnSync } = require('child_process')
const path = require('path')
const fs = require('fs-extra')
const chalk = require('chalk')
const IGNORE_FILES = ['.DS_Store']
const cwd = process.cwd()
// Can be run as `yarn test:e2e --cache` to forego reinstalling node_modules, or
// `yarn test:e2e <projects dir>`, or `yarn test:e2e --cache <projects dir>`.
const args = process.argv.slice(2)
function success(msg) {
console.info(chalk.green('\n[vue-jest]: ' + msg + '\n'))
}
function info(msg) {
console.info(chalk.blue('\n[vue-jest]: ' + msg + '\n'))
}
function runTest(dir) {
const resolvedPath = path.resolve(__dirname, '__projects__', dir)
const run = command => {
const [cmd, ...args] = command.split(' ')
const { status } = spawnSync(cmd, args, {
cwd: resolvedPath,
env: { PATH: process.env.PATH },
stdio: 'inherit',
shell: true
})
if (status !== 0) {
process.exit(status)
}
}
const log = msg => info(`(${dir}) ${msg}`)
if (!args.filter(arg => arg === '--cache').length) {
log('Removing node_modules')
fs.removeSync(`${resolvedPath}/node_modules`)
log('Removing yarn.lock')
fs.removeSync(`${resolvedPath}/yarn.lock`)
log('Installing node_modules')
run('yarn install --silent')
}
// For tests that need vue-jest to successfully `require.resolve()` a file in
// the project directory's node_modules, we can't symlink vue-jest from a
// parent directory (as node module resolution walks up the file tree,
// starting from the realpath of the caller), we must copy it.
if (
!fs.existsSync(`${resolvedPath}/node_modules/vue-jest`) ||
!fs.lstatSync(`${resolvedPath}/node_modules/vue-jest`).isSymbolicLink()
) {
log('Copying vue-jest into node_modules')
fs.mkdirSync(`${resolvedPath}/node_modules/vue-jest`, { recursive: true })
run(`cp ${cwd}/package.json node_modules/vue-jest/`)
run(`cp -r ${cwd}/lib node_modules/vue-jest/`)
}
log('Running tests')
run('yarn test')
success(`(${dir}) Complete`)
}
async function testRunner() {
const directories = fs
.readdirSync(path.resolve(__dirname, '__projects__'))
.filter(d => !IGNORE_FILES.includes(d))
const matches = args.filter(d => directories.includes(d))
if (matches.length) {
matches.forEach(runTest)
} else {
directories.forEach(runTest)
}
}
testRunner()