@@ -4,6 +4,11 @@ const fs = require('fs-extra')
4
4
const chalk = require ( 'chalk' )
5
5
6
6
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 )
7
12
8
13
function success ( msg ) {
9
14
console . info ( chalk . green ( '\n[vue-jest]: ' + msg + '\n' ) )
@@ -31,29 +36,49 @@ function runTest(dir) {
31
36
32
37
const log = msg => info ( `(${ dir } ) ${ msg } ` )
33
38
34
- log ( 'Running tests' )
39
+ if ( ! args . filter ( arg => arg === '--cache' ) . length ) {
40
+ log ( 'Removing node_modules' )
41
+ fs . removeSync ( `${ resolvedPath } /node_modules` )
35
42
36
- log ( 'Removing node_modules ' )
37
- fs . removeSync ( `${ resolvedPath } /node_modules ` )
43
+ log ( 'Removing package-lock.json ' )
44
+ fs . removeSync ( `${ resolvedPath } /package-lock.json ` )
38
45
39
- log ( 'Removing package-lock.json' )
40
- fs . removeSync ( `${ resolvedPath } /package-lock.json` )
46
+ log ( 'Installing node_modules' )
47
+ run ( 'npm install --silent' )
48
+ }
41
49
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
+ }
44
63
45
64
log ( 'Running tests' )
46
65
run ( 'npm run test' )
47
66
48
67
success ( `(${ dir } ) Complete` )
49
68
}
50
69
51
- async function testRunner ( dir ) {
70
+ async function testRunner ( ) {
52
71
const directories = fs
53
72
. readdirSync ( path . resolve ( __dirname , '__projects__' ) )
54
73
. filter ( d => ! IGNORE_FILES . includes ( d ) )
55
74
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
+ }
57
82
}
58
83
59
84
testRunner ( )
0 commit comments