@@ -4,6 +4,11 @@ const fs = require('fs-extra')
44const chalk = require ( 'chalk' )
55
66const 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
813function 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 package-lock.json ' )
44+ fs . removeSync ( `${ resolvedPath } /package-lock.json ` )
3845
39- log ( 'Removing package-lock.json' )
40- fs . removeSync ( `${ resolvedPath } /package-lock.json` )
46+ log ( 'Installing node_modules' )
47+ run ( 'npm install --silent' )
48+ }
4149
42- log ( 'Installing node_modules' )
43- run ( 'npm 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 ( 'npm run 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
5984testRunner ( )
0 commit comments