@@ -15,13 +15,9 @@ const jestArgs = process.argv.slice(3)
15
15
let gitUrl = false
16
16
17
17
const randomStr = ( ) => parseInt ( Math . random ( ) * 1e17 , 10 ) . toString ( 36 )
18
-
19
- if ( / ^ ( ( h t t p s | s s h | g i t ) : \/ \/ | [ a - z 0 - 9 ] + @ [ a - z 0 - 9 . ] + : ) .+ $ / . test ( projectPath ) ) {
20
- gitUrl = projectPath
21
- projectPath = resolve ( tmpdir ( ) , 'ts-jest-git-ext' , randomStr ( ) , randomStr ( ) )
22
- } else {
18
+ const executeTest = ( path ) => {
23
19
try {
24
- projectPath = realpathSync ( resolve ( process . cwd ( ) , projectPath ) )
20
+ projectPath = realpathSync ( resolve ( process . cwd ( ) , path ) )
25
21
} catch ( err ) {
26
22
projectPath = undefined
27
23
}
@@ -33,61 +29,75 @@ if (/^((https|ssh|git):\/\/|[a-z0-9]+@[a-z0-9.]+:).+$/.test(projectPath)) {
33
29
logger . error ( 'First argument must be the path to a project or a git URL' )
34
30
process . exit ( 1 )
35
31
}
36
- }
32
+ // first we need to create a bundle
33
+ const bundle = createBundle ( )
37
34
38
- // first we need to create a bundle
39
- const bundle = createBundle ( )
35
+ // if it's a git URL we first need to clone
36
+ if ( gitUrl ) {
37
+ logger . log ( 'found what could be a git URL, trying to clone' )
38
+ spawnSync ( 'git' , [ 'clone' , gitUrl , projectPath ] )
39
+ }
40
40
41
- // if it's a git URL we first need to clone
42
- if ( gitUrl ) {
43
- logger . log ( 'found what could be a git URL, trying to clone' )
44
- spawnSync ( 'git' , [ 'clone' , gitUrl , projectPath ] )
45
- }
41
+ // we change current directory
42
+ process . chdir ( projectPath )
46
43
47
- // we change current directory
48
- process . chdir ( projectPath )
44
+ // reading package.json
45
+ const projectPkg = require ( join ( projectPath , 'package.json' ) )
46
+ if ( ! projectPkg . name ) projectPkg . name = 'unknown'
47
+ if ( ! projectPkg . version ) projectPkg . version = 'unknown'
49
48
50
- // reading package.json
51
- const projectPkg = require ( join ( projectPath , 'package.json' ) )
52
- if ( ! projectPkg . name ) projectPkg . name = 'unknown'
53
- if ( ! projectPkg . version ) projectPkg . version = 'unknown'
49
+ logger . log ( )
50
+ logger . log (
51
+ '=' . repeat ( 20 ) ,
52
+ `${ projectPkg . name } @${ projectPkg . version } ` ,
53
+ 'in' ,
54
+ projectPath ,
55
+ '=' . repeat ( 20 )
56
+ )
57
+ logger . log ( )
54
58
55
- logger . log ( )
56
- logger . log (
57
- '=' . repeat ( 20 ) ,
58
- `${ projectPkg . name } @${ projectPkg . version } ` ,
59
- 'in' ,
60
- projectPath ,
61
- '=' . repeat ( 20 )
62
- )
63
- logger . log ( )
59
+ // then we install it in the repo
60
+ logger . log ( 'ensuring all depedencies of target project are installed' )
61
+ npm . spawnSync (
62
+ [ 'install' , '--no-package-lock' , '--no-shrinkwrap' , '--no-save' ] ,
63
+ { cwd : projectPath }
64
+ )
65
+ logger . log ( 'installing bundled version of ts-jest' )
66
+ npm . spawnSync (
67
+ [ 'install' , '--no-package-lock' , '--no-shrinkwrap' , '--no-save' , bundle ] ,
68
+ { cwd : projectPath }
69
+ )
64
70
65
- // then we install it in the repo
66
- logger . log ( 'ensuring all depedencies of target project are installed' )
67
- npm . spawnSync (
68
- [ 'install' , '--no-package-lock' , '--no-shrinkwrap' , '--no-save' ] ,
69
- { cwd : projectPath }
70
- )
71
- logger . log ( 'installing bundled version of ts-jest' )
72
- npm . spawnSync (
73
- [ 'install' , '--no-package-lock' , '--no-shrinkwrap' , '--no-save' , bundle ] ,
74
- { cwd : projectPath }
75
- )
71
+ // then we can run the tests
72
+ const cmdLine =
73
+ projectPkg . scripts && projectPkg . scripts . test
74
+ ? [ 'npm' , 'test' , '--' ]
75
+ : [ 'jest' ]
76
+ cmdLine . push ( ...jestArgs )
76
77
77
- // then we can run the tests
78
- const cmdLine =
79
- projectPkg . scripts && projectPkg . scripts . test
80
- ? [ 'npm' , 'test' , '--' ]
81
- : [ 'jest' ]
82
- cmdLine . push ( ...jestArgs )
78
+ logger . log ( 'starting the tests using:' , ...cmdLine )
79
+ logger . log ( )
83
80
84
- logger . log ( 'starting the tests using:' , ...cmdLine )
85
- logger . log ( )
81
+ spawnSync ( cmdLine . shift ( ) , cmdLine , {
82
+ cwd : projectPath ,
83
+ stdio : 'inherit' ,
84
+ env : Object . assign ( { } , process . env , {
85
+ TS_JEST_IGNORE_DIAGNOSTICS : '5023,5024' ,
86
+ } ) ,
87
+ } )
88
+ }
86
89
87
- spawnSync ( cmdLine . shift ( ) , cmdLine , {
88
- cwd : projectPath ,
89
- stdio : 'inherit' ,
90
- env : Object . assign ( { } , process . env , {
91
- TS_JEST_IGNORE_DIAGNOSTICS : '5023,5024' ,
92
- } ) ,
93
- } )
90
+ if ( / ^ ( ( h t t p s | s s h | g i t ) : \/ \/ | [ a - z 0 - 9 ] + @ [ a - z 0 - 9 . ] + : ) .+ $ / . test ( projectPath ) ) {
91
+ gitUrl = projectPath
92
+ projectPath = resolve ( tmpdir ( ) , 'ts-jest-git-ext' , randomStr ( ) , randomStr ( ) )
93
+ } else {
94
+ if ( projectPath === 'monorepo' ) {
95
+ [
96
+ 'e2e/__monorepos__/simple/with-dependency' ,
97
+ ] . forEach ( monorepoPath => {
98
+ executeTest ( monorepoPath )
99
+ } )
100
+ } else {
101
+ executeTest ( projectPath )
102
+ }
103
+ }
0 commit comments