@@ -41,10 +41,36 @@ export class TestRunner {
4141 private readonly smStore : SourceMapStore ,
4242 private readonly launchConfig : ConfigValue < Record < string , any > > ,
4343 private readonly env : ConfigValue < Record < string , string > > ,
44- ) { }
44+ ) { }
4545
4646 private currentRunningTest ?: vscode . TestItem ;
4747
48+ private static filterArgsForCopy ( args : string [ ] ) : string [ ] {
49+ const forCopy : string [ ] = [ ] ;
50+
51+ // powershell prefix
52+ if ( process . platform === 'win32' ) {
53+ forCopy . push ( '&' ) ;
54+ }
55+
56+ let i = 0 ;
57+ while ( i < args . length ) {
58+
59+ if ( args [ i ] === '--reporter' ) {
60+ i ++ ; // --reporter
61+ i ++ ; // value
62+ } else {
63+ const sanitized = args [ i ] . includes ( ' ' ) || args [ i ] . includes ( '\\' )
64+ ? JSON . stringify ( args [ i ] )
65+ : args [ i ]
66+ forCopy . push ( sanitized ) ;
67+ i ++ ;
68+ }
69+ }
70+
71+ return forCopy ;
72+ }
73+
4874 public makeHandler (
4975 ctrl : vscode . TestController ,
5076 config : ConfigurationFile ,
@@ -113,8 +139,7 @@ export class TestRunner {
113139 const { path } = parsed [ 1 ] ;
114140 if ( path . length > 0 ) {
115141 enqueueLine (
116- `${ ' ' . repeat ( path . length - 1 ) } ${ styles . green . open } ✓ ${ styles . green . close } ${
117- path [ path . length - 1 ]
142+ `${ ' ' . repeat ( path . length - 1 ) } ${ styles . green . open } ✓ ${ styles . green . close } ${ path [ path . length - 1 ]
118143 } `,
119144 ) ;
120145 }
@@ -125,8 +150,7 @@ export class TestRunner {
125150 const { file, path, duration } = parsed [ 1 ] ;
126151 const test = compiledFileTests . lookup ( file , path ) ;
127152 enqueueLine (
128- `${ ' ' . repeat ( path . length - 1 ) } ${ styles . green . open } ✓ ${ styles . green . close } ${
129- path [ path . length - 1 ]
153+ `${ ' ' . repeat ( path . length - 1 ) } ${ styles . green . open } ✓ ${ styles . green . close } ${ path [ path . length - 1 ]
130154 } `,
131155 test ,
132156 ) ;
@@ -143,8 +167,7 @@ export class TestRunner {
143167 const tcase = compiledFileTests . lookup ( file , path ) ;
144168
145169 enqueueLine (
146- `${ ' ' . repeat ( path . length - 1 ) } ${ styles . red . open } x ${ path . join ( ' ' ) } ${
147- styles . red . close
170+ `${ ' ' . repeat ( path . length - 1 ) } ${ styles . red . open } x ${ path . join ( ' ' ) } ${ styles . red . close
148171 } `,
149172 tcase ,
150173 ) ;
@@ -214,11 +237,18 @@ export class TestRunner {
214237 } ;
215238
216239 run . appendOutput (
217- `${ styles . inverse . open } > ${ styles . inverse . close } ${ (
240+ `${ styles . inverse . open } VSCode Command (for troubleshooting) > ${ styles . inverse . close } ${ (
218241 await config . getMochaSpawnArgs ( spawnOpts . args )
219- ) . join ( ' ' ) } } \r\n`,
242+ ) . join ( ' ' ) } \r\n`,
220243 ) ;
221244
245+ run . appendOutput (
246+ `${ styles . inverse . open } Terminal Command (for copying)> ${ styles . inverse . close } ${ TestRunner . filterArgsForCopy (
247+ await config . getMochaSpawnArgs ( spawnOpts . args )
248+ ) . join ( ' ' ) } \r\n`,
249+ ) ;
250+
251+
222252 try {
223253 const start = performance . now ( ) ;
224254 if ( debug ) {
@@ -548,8 +578,12 @@ class CompiledFileTests {
548578
549579 // on windows paths are case insensitive and we sometimes get inconsistent
550580 // casings (e.g. C:\ vs c:\) - happens especially on debugging
581+ // we still need to keep the main parts of the paths consistent
582+ // (e.g. jest snapshot uses the file name for writing new files -> can lead to cross platform problems)
551583 if ( process . platform === 'win32' ) {
552- return file . toLowerCase ( ) ;
584+ if ( file . charAt ( 1 ) === ':' ) {
585+ return file . substring ( 0 , 1 ) . toLowerCase ( ) + file . substring ( 1 ) ;
586+ }
553587 }
554588
555589 return file ;
0 commit comments