Skip to content

Commit

Permalink
chore: update test run script (Port from vuejs#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
nogic1008 committed Mar 29, 2021
1 parent 27f2259 commit 4e9dc59
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions e2e/test-runner.js
Expand Up @@ -4,6 +4,11 @@ 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'))
Expand Down Expand Up @@ -31,29 +36,49 @@ function runTest(dir) {

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

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

log('Removing node_modules')
fs.removeSync(`${resolvedPath}/node_modules`)
log('Removing yarn.lock')
fs.removeSync(`${resolvedPath}/yarn.lock`)

log('Removing yarn-lock.json')
fs.removeSync(`${resolvedPath}/yarn-lock.json`)
log('Installing node_modules')
run('yarn install --silent')
}

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(dir) {
async function testRunner() {
const directories = fs
.readdirSync(path.resolve(__dirname, '__projects__'))
.filter(d => !IGNORE_FILES.includes(d))

directories.forEach(runTest)
const matches = args.filter(d => directories.includes(d))

if (matches.length) {
matches.forEach(runTest)
} else {
directories.forEach(runTest)
}
}

testRunner()

0 comments on commit 4e9dc59

Please sign in to comment.