55 * LICENSE file in the root directory of this source tree.
66 */
77
8- import { createHash } from 'crypto' ;
9- import { tmpdir } from 'os' ;
10- import * as path from 'path' ;
11- import { ExecaSyncReturnValue , sync as spawnSync } from 'execa' ;
8+ import { sync as spawnSync } from 'execa' ;
129import * as fs from 'graceful-fs' ;
10+ import tempy = require( 'tempy' ) ;
1311
1412const CIRCUS_PATH = require . resolve ( '../' ) . replace ( / \\ / g, '\\\\' ) ;
1513const CIRCUS_RUN_PATH = require . resolve ( '../run' ) . replace ( / \\ / g, '\\\\' ) ;
@@ -21,20 +19,11 @@ const BABEL_REGISTER_PATH = require
2119 . resolve ( '@babel/register' )
2220 . replace ( / \\ / g, '\\\\' ) ;
2321
24- interface Result extends ExecaSyncReturnValue {
25- status : number ;
26- error : string ;
27- }
28-
2922export const runTest = (
3023 source : string ,
3124 opts ?: { seed ?: number ; randomize ?: boolean } ,
3225) => {
33- const filename = createHash ( 'sha1' )
34- . update ( source )
35- . digest ( 'hex' )
36- . substring ( 0 , 32 ) ;
37- const tmpFilename = path . join ( tmpdir ( ) , filename ) ;
26+ const tmpFilename = tempy . file ( ) ;
3827
3928 const content = `
4029 require('${ BABEL_REGISTER_PATH } ')({extensions: [".js", ".ts"]});
@@ -62,25 +51,18 @@ export const runTest = (
6251 fs . writeFileSync ( tmpFilename , content ) ;
6352 const result = spawnSync ( 'node' , [ tmpFilename ] , {
6453 cwd : process . cwd ( ) ,
65- } ) as Result ;
66-
67- // For compat with cross-spawn
68- result . status = result . exitCode ;
54+ } ) ;
6955
70- if ( result . status !== 0 ) {
56+ if ( result . exitCode !== 0 ) {
7157 const message = `
7258 STDOUT: ${ result . stdout && result . stdout . toString ( ) }
7359 STDERR: ${ result . stderr && result . stderr . toString ( ) }
74- STATUS: ${ result . status }
75- ERROR: ${ String ( result . error ) }
60+ STATUS: ${ result . exitCode }
7661 ` ;
7762 throw new Error ( message ) ;
7863 }
7964
80- result . stdout = String ( result . stdout ) ;
81- result . stderr = String ( result . stderr ) ;
82-
83- fs . unlinkSync ( tmpFilename ) ;
65+ fs . rmSync ( tmpFilename , { force : true } ) ;
8466
8567 if ( result . stderr ) {
8668 throw new Error (
0 commit comments