11import * as test from 'tape'
2- import { spawnTsNodeDev , scriptsDir , tmpDir } from './spawn'
2+ import { spawnTsNodeDev , scriptsDir , tmpDir , turnOnOutput } from './spawn'
33import * as fs from 'fs-extra'
44import { join } from 'path'
55import touch = require( 'touch' )
66
7+ if ( process . argv . slice ( 2 ) [ 0 ] === '--output' ) {
8+ turnOnOutput ( )
9+ }
10+
711export const replaceText = async (
812 script : string ,
913 pattern : string | RegExp ,
@@ -44,7 +48,7 @@ test('It should restart on file change', async (t) => {
4448} )
4549
4650test ( 'It allow watch arbitrary folder/file' , async ( t ) => {
47- const ps = spawnTsNodeDev ( '--respawn --watch folder,folder2 simple.ts' ) //.turnOnOutput()
51+ const ps = spawnTsNodeDev ( '--respawn --watch folder,folder2 simple.ts' )
4852 await ps . waitForLine ( / U s i n g / )
4953 setTimeout ( ( ) => touch ( join ( scriptsDir , 'folder/some-file' ) ) , 250 )
5054 await ps . waitForLine ( / R e s t a r t i n g .* s o m e - f i l e / )
@@ -53,7 +57,7 @@ test('It allow watch arbitrary folder/file', async (t) => {
5357} )
5458
5559test ( 'It should report an error on start' , async ( t ) => {
56- const ps = spawnTsNodeDev ( '--respawn with-error.ts' ) //.turnOnOutput()
60+ const ps = spawnTsNodeDev ( '--respawn with-error.ts' )
5761 await ps . waitForLine ( / [ E R R O R ] / )
5862 const out = ps . getStdout ( )
5963 t . ok ( / C o m p i l a t i o n e r r o r i n / . test ( out ) , 'Reports error file' )
@@ -72,7 +76,7 @@ test('It should report an error on start', async (t) => {
7276} )
7377
7478test ( 'It should report an error with --log-error and continue to work' , async ( t ) => {
75- const ps = spawnTsNodeDev ( '--respawn --log-error with-error.ts' ) //.turnOnOutput()
79+ const ps = spawnTsNodeDev ( '--respawn --log-error with-error.ts' )
7680 await ps . waitForErrorLine ( / e r r o r / )
7781
7882 const out = ps . getStderr ( )
@@ -134,7 +138,7 @@ test('It handles allowJs option and loads JS modules', async (t) => {
134138 `--compiler-options=${ JSON . stringify ( cOptions ) } ` ,
135139 `js-module.js` ,
136140 ] . join ( ' ' )
137- ) //.turnOnOutput()
141+ )
138142 await ps . waitForLine ( / J S M O D U L E / )
139143 t . pass ( 'ok' )
140144 await ps . exit ( )
@@ -149,7 +153,7 @@ test('It handles resolveJsonModule option and loads JSON modules', async (t) =>
149153 `--compiler-options=${ JSON . stringify ( cOptions ) } ` ,
150154 `import-json` ,
151155 ] . join ( ' ' )
152- ) //.turnOnOutput()
156+ )
153157 await ps . waitForLine ( / J S O N D A T A : { f i l e : ' j s o n ' } / )
154158 t . pass ( 'ok' )
155159 await ps . exit ( )
@@ -158,21 +162,21 @@ test('It handles resolveJsonModule option and loads JSON modules', async (t) =>
158162test ( 'It should not allow --script-mode and --dir together' , async ( t ) => {
159163 const ps = spawnTsNodeDev (
160164 [ `--script-mode` , `--dir folder` , `simple.ts` ] . join ( ' ' )
161- ) //.turnOnOutput()
165+ )
162166 await ps . waitForLine ( / T y p e E r r o r : S c r i p t m o d e c a n n o t b e c o m b i n e d w i t h ` - - d i r ` / )
163167 t . pass ( 'ok' )
164168 await ps . exit ( )
165169} )
166170
167171test ( 'It should use the tsconfig at --dir when defined' , async ( t ) => {
168- const ps = spawnTsNodeDev ( [ `--dir dir-test` , `dir-test/index.ts` ] . join ( ' ' ) ) //.turnOnOutput()
172+ const ps = spawnTsNodeDev ( [ `--dir dir-test` , `dir-test/index.ts` ] . join ( ' ' ) )
169173 await ps . waitForLine ( / \{ h e l l o : ' w o r l d ' \} / )
170174 t . pass ( 'ok' )
171175 await ps . exit ( )
172176} )
173177
174178test ( 'It should use the tsconfig at --script-mode when defined' , async ( t ) => {
175- const ps = spawnTsNodeDev ( [ `-s` , `dir-test/index.ts` ] . join ( ' ' ) ) //.turnOnOutput()
179+ const ps = spawnTsNodeDev ( [ `-s` , `dir-test/index.ts` ] . join ( ' ' ) )
176180 await ps . waitForLine ( / \{ h e l l o : ' w o r l d ' \} / )
177181 t . pass ( 'ok' )
178182 await ps . exit ( )
@@ -185,7 +189,7 @@ test('It should fail if not using --dir or --script-mode on dir-test/index.ts',
185189 `--compiler-options=${ JSON . stringify ( cOptions ) } ` ,
186190 `dir-test/index.ts` ,
187191 ] . join ( ' ' )
188- ) //.turnOnOutput()
192+ )
189193 await ps . waitForLine ( / h a s n o d e f a u l t e x p o r t ./ )
190194 t . pass ( 'ok' )
191195 await ps . exit ( )
@@ -200,7 +204,7 @@ test('It allows to use TS Transformers', async (t) => {
200204 `--compiler-options=${ JSON . stringify ( cOptions ) } ` ,
201205 `nameof.ts` ,
202206 ] . join ( ' ' )
203- ) //.turnOnOutput()
207+ )
204208 await ps . waitForLine ( / c o n s o l e / )
205209
206210 await ps . exit ( )
@@ -215,7 +219,7 @@ test('It allows to use custom TS Transformers', async (t) => {
215219 `--compiler-options=${ JSON . stringify ( cOptions ) } ` ,
216220 `to-transform.ts` ,
217221 ] . join ( ' ' )
218- ) //.turnOnOutput()
222+ )
219223 await ps . waitForLine ( / t r a n s f o r m e d / )
220224 t . pass ( 'ok' )
221225 await ps . exit ( )
@@ -229,13 +233,13 @@ test('It should --prefer-ts', async (t) => {
229233 //`--prefer-ts-exts`,
230234 `prefer/prefer.js` ,
231235 ] . join ( ' ' )
232- ) //.turnOnOutput()
236+ )
233237 await ps . waitForLine ( / P R E F E R D E P J S / )
234238 await ps . waitForLine ( / P R E F E R J S / )
235239 await ps . exit ( )
236240 t . pass ( )
237241 } )
238- t . test ( 'SHould require JS deps by default' , async ( t ) => {
242+ t . test ( 'Should require JS deps by default' , async ( t ) => {
239243 const ps = spawnTsNodeDev (
240244 [
241245 `--respawn` ,
@@ -273,7 +277,7 @@ test.skip('It should add require with -r flag', async (t) => {
273277 //`--debug`,
274278 `simple` ,
275279 ] . join ( ' ' )
276- ) //.turnOnOutput()
280+ )
277281 await ps . waitForLine ( / a d d e d - - r e q u i r e / )
278282 await ps . waitForLine ( / v 1 / )
279283
@@ -286,7 +290,7 @@ test.skip('It should add require with -r flag', async (t) => {
286290} )
287291
288292test ( 'It should handle --deps flag' , async ( t ) => {
289- const ps = spawnTsNodeDev ( [ `--deps` , `--respawn` , `req-package` ] . join ( ' ' ) ) //.turnOnOutput()
293+ const ps = spawnTsNodeDev ( [ `--deps` , `--respawn` , `req-package` ] . join ( ' ' ) )
290294
291295 await ps . waitForLine ( / P A C K A G E / )
292296
@@ -305,3 +309,25 @@ test('It should handle --deps flag', async (t) => {
305309 t . pass ( )
306310 t . end ( )
307311} )
312+
313+
314+ test ( 'It should handle deep deps with --deps flag' , async ( t ) => {
315+ const ps = spawnTsNodeDev ( [ `--all-deps` , `--respawn` , `req-package` ] . join ( ' ' ) )
316+
317+ await ps . waitForLine ( / P A C K A G E / )
318+
319+ setTimeout (
320+ ( ) =>
321+ replaceText (
322+ 'node_modules/package/node_modules/level2-package/index.js' ,
323+ 'PACKAGE' ,
324+ 'CHANGED PACKAGE'
325+ ) ,
326+ 100
327+ )
328+
329+ await ps . waitForLine ( / C H A N G E D P A C K A G E / )
330+ await ps . exit ( )
331+ t . pass ( )
332+ t . end ( )
333+ } )
0 commit comments