Skip to content

Commit 4e9dc59

Browse files
committed
chore: update test run script (Port from vuejs#284)
1 parent 27f2259 commit 4e9dc59

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

e2e/test-runner.js

+34-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ const fs = require('fs-extra')
44
const chalk = require('chalk')
55

66
const IGNORE_FILES = ['.DS_Store']
7+
const cwd = process.cwd()
8+
9+
// Can be run as `yarn test:e2e --cache` to forego reinstalling node_modules, or
10+
// `yarn test:e2e <projects dir>`, or `yarn test:e2e --cache <projects dir>`.
11+
const args = process.argv.slice(2)
712

813
function success(msg) {
914
console.info(chalk.green('\n[vue-jest]: ' + msg + '\n'))
@@ -31,29 +36,49 @@ function runTest(dir) {
3136

3237
const log = msg => info(`(${dir}) ${msg}`)
3338

34-
log('Running tests')
39+
if (!args.filter(arg => arg === '--cache').length) {
40+
log('Removing node_modules')
41+
fs.removeSync(`${resolvedPath}/node_modules`)
3542

36-
log('Removing node_modules')
37-
fs.removeSync(`${resolvedPath}/node_modules`)
43+
log('Removing yarn.lock')
44+
fs.removeSync(`${resolvedPath}/yarn.lock`)
3845

39-
log('Removing yarn-lock.json')
40-
fs.removeSync(`${resolvedPath}/yarn-lock.json`)
46+
log('Installing node_modules')
47+
run('yarn install --silent')
48+
}
4149

42-
log('Installing node_modules')
43-
run('yarn install --silent')
50+
// For tests that need vue-jest to successfully `require.resolve()` a file in
51+
// the project directory's node_modules, we can't symlink vue-jest from a
52+
// parent directory (as node module resolution walks up the file tree,
53+
// starting from the realpath of the caller), we must copy it.
54+
if (
55+
!fs.existsSync(`${resolvedPath}/node_modules/vue-jest`) ||
56+
!fs.lstatSync(`${resolvedPath}/node_modules/vue-jest`).isSymbolicLink()
57+
) {
58+
log('Copying vue-jest into node_modules')
59+
fs.mkdirSync(`${resolvedPath}/node_modules/vue-jest`, { recursive: true })
60+
run(`cp ${cwd}/package.json node_modules/vue-jest/`)
61+
run(`cp -r ${cwd}/lib node_modules/vue-jest/`)
62+
}
4463

4564
log('Running tests')
4665
run('yarn test')
4766

4867
success(`(${dir}) Complete`)
4968
}
5069

51-
async function testRunner(dir) {
70+
async function testRunner() {
5271
const directories = fs
5372
.readdirSync(path.resolve(__dirname, '__projects__'))
5473
.filter(d => !IGNORE_FILES.includes(d))
5574

56-
directories.forEach(runTest)
75+
const matches = args.filter(d => directories.includes(d))
76+
77+
if (matches.length) {
78+
matches.forEach(runTest)
79+
} else {
80+
directories.forEach(runTest)
81+
}
5782
}
5883

5984
testRunner()

0 commit comments

Comments
 (0)