5
5
* LICENSE file in the root directory of this source tree.
6
6
*/
7
7
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' ;
12
9
import * as fs from 'graceful-fs' ;
10
+ import tempy = require( 'tempy' ) ;
13
11
14
12
const CIRCUS_PATH = require . resolve ( '../' ) . replace ( / \\ / g, '\\\\' ) ;
15
13
const CIRCUS_RUN_PATH = require . resolve ( '../run' ) . replace ( / \\ / g, '\\\\' ) ;
@@ -21,20 +19,11 @@ const BABEL_REGISTER_PATH = require
21
19
. resolve ( '@babel/register' )
22
20
. replace ( / \\ / g, '\\\\' ) ;
23
21
24
- interface Result extends ExecaSyncReturnValue {
25
- status : number ;
26
- error : string ;
27
- }
28
-
29
22
export const runTest = (
30
23
source : string ,
31
24
opts ?: { seed ?: number ; randomize ?: boolean } ,
32
25
) => {
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 ( ) ;
38
27
39
28
const content = `
40
29
require('${ BABEL_REGISTER_PATH } ')({extensions: [".js", ".ts"]});
@@ -62,25 +51,18 @@ export const runTest = (
62
51
fs . writeFileSync ( tmpFilename , content ) ;
63
52
const result = spawnSync ( 'node' , [ tmpFilename ] , {
64
53
cwd : process . cwd ( ) ,
65
- } ) as Result ;
66
-
67
- // For compat with cross-spawn
68
- result . status = result . exitCode ;
54
+ } ) ;
69
55
70
- if ( result . status !== 0 ) {
56
+ if ( result . exitCode !== 0 ) {
71
57
const message = `
72
58
STDOUT: ${ result . stdout && result . stdout . toString ( ) }
73
59
STDERR: ${ result . stderr && result . stderr . toString ( ) }
74
- STATUS: ${ result . status }
75
- ERROR: ${ String ( result . error ) }
60
+ STATUS: ${ result . exitCode }
76
61
` ;
77
62
throw new Error ( message ) ;
78
63
}
79
64
80
- result . stdout = String ( result . stdout ) ;
81
- result . stderr = String ( result . stderr ) ;
82
-
83
- fs . unlinkSync ( tmpFilename ) ;
65
+ fs . rmSync ( tmpFilename , { force : true } ) ;
84
66
85
67
if ( result . stderr ) {
86
68
throw new Error (
0 commit comments