1
1
import { assert } from "chai" ;
2
- import os from "os" ;
3
- import path from "path" ;
4
2
5
3
import {
4
+ resolveBuidlerRegisterPath ,
6
5
runScript ,
7
6
runScriptWithBuidler
8
7
} from "../../../src/internal/util/scripts-runner" ;
@@ -13,12 +12,18 @@ describe("Scripts runner", function() {
13
12
useFixtureProject ( "project-with-scripts" ) ;
14
13
15
14
it ( "Should pass params to the script" , async function ( ) {
16
- const statusCode = await runScript ( "./params-script.js" , [ "a" , "b" , "c" ] ) ;
17
- assert . equal ( statusCode , 0 ) ;
15
+ const [
16
+ statusCodeWithScriptParams ,
17
+ statusCodeWithNoParams
18
+ ] = await Promise . all ( [
19
+ runScript ( "./params-script.js" , [ "a" , "b" , "c" ] ) ,
20
+ runScript ( "./params-script.js" )
21
+ ] ) ;
22
+
23
+ assert . equal ( statusCodeWithScriptParams , 0 ) ;
18
24
19
25
// We check here that the script is correctly testing this:
20
- const statusCode2 = await runScript ( "./params-script.js" ) ;
21
- assert . notEqual ( statusCode2 , 0 ) ;
26
+ assert . notEqual ( statusCodeWithNoParams , 0 ) ;
22
27
} ) ;
23
28
24
29
it ( "Should run the script to completion" , async function ( ) {
@@ -30,54 +35,90 @@ describe("Scripts runner", function() {
30
35
} ) ;
31
36
32
37
it ( "Should resolve to the status code of the script run" , async function ( ) {
33
- this . timeout ( 35000 ) ;
34
-
35
- if ( os . type ( ) === "Windows_NT" ) {
36
- this . skip ( ) ;
37
- }
38
-
39
- const statusCode1 = await runScript (
40
- "./async-script.js" ,
41
- [ ] ,
42
- [ "--require" , path . join ( __dirname , ".." , ".." , ".." , "src" , "register" ) ]
38
+ const buidlerRegisterPath = resolveBuidlerRegisterPath ( ) ;
39
+
40
+ const extraNodeArgs = [ "--require" , buidlerRegisterPath ] ;
41
+ const scriptArgs : string [ ] = [ ] ;
42
+
43
+ const runScriptCases = [
44
+ {
45
+ scriptPath : "./async-script.js" ,
46
+ extraNodeArgs,
47
+ expectedStatusCode : 0
48
+ } ,
49
+ {
50
+ scriptPath : "./failing-script.js" ,
51
+ expectedStatusCode : 123
52
+ } ,
53
+ {
54
+ scriptPath : "./successful-script.js" ,
55
+ extraNodeArgs,
56
+ expectedStatusCode : 0
57
+ }
58
+ ] ;
59
+
60
+ const runScriptTestResults = await Promise . all (
61
+ runScriptCases . map (
62
+ async ( { scriptPath, extraNodeArgs : _extraNodeArgs } ) => {
63
+ const statusCode =
64
+ _extraNodeArgs === undefined
65
+ ? await runScript ( scriptPath )
66
+ : await runScript ( scriptPath , scriptArgs , _extraNodeArgs ) ;
67
+ return { scriptPath, statusCode } ;
68
+ }
69
+ )
43
70
) ;
44
- assert . equal ( statusCode1 , 0 ) ;
45
-
46
- const statusCode2 = await runScript ( "./failing-script.js" ) ;
47
- assert . equal ( statusCode2 , 123 ) ;
48
71
49
- const statusCode3 = await runScript (
50
- "./successful-script.js" ,
51
- [ ] ,
52
- [ "--require" , path . join ( __dirname , ".." , ".." , ".." , "src" , "register" ) ]
72
+ const expectedResults = runScriptCases . map (
73
+ ( { expectedStatusCode, scriptPath } ) => ( {
74
+ scriptPath,
75
+ statusCode : expectedStatusCode
76
+ } )
53
77
) ;
54
- assert . equal ( statusCode3 , 0 ) ;
78
+
79
+ assert . deepEqual ( runScriptTestResults , expectedResults ) ;
55
80
} ) ;
56
81
57
82
it ( "Should pass env variables to the script" , async function ( ) {
58
- const statusCode = await runScript ( "./env-var-script.js" , [ ] , [ ] , {
59
- TEST_ENV_VAR : "test"
60
- } ) ;
61
- assert . equal ( statusCode , 0 ) ;
83
+ const [ statusCodeWithEnvVars , statusCodeWithNoEnvArgs ] = await Promise . all ( [
84
+ runScript ( "./env-var-script.js" , [ ] , [ ] , {
85
+ TEST_ENV_VAR : "test"
86
+ } ) ,
87
+ runScript ( "./env-var-script.js" )
88
+ ] ) ;
89
+
90
+ assert . equal (
91
+ statusCodeWithEnvVars ,
92
+ 0 ,
93
+ "Status code with env vars should be 0"
94
+ ) ;
62
95
63
- // We check here that the script is correctly testing this:
64
- const statusCode2 = await runScript ( "./env-var-script.js" ) ;
65
- assert . notEqual ( statusCode2 , 0 ) ;
96
+ assert . notEqual (
97
+ statusCodeWithNoEnvArgs ,
98
+ 0 ,
99
+ "Status code with no env vars should not be 0"
100
+ ) ;
66
101
} ) ;
67
102
68
103
describe ( "runWithBuidler" , function ( ) {
69
104
useEnvironment ( ) ;
70
105
71
106
it ( "Should load buidler/register successfully" , async function ( ) {
72
- const statusCode = await runScriptWithBuidler (
73
- this . env . buidlerArguments ,
74
- "./successful-script.js"
75
- ) ;
76
- assert . equal ( statusCode , 0 ) ;
107
+ const [
108
+ statusCodeWithBuidler ,
109
+ statusCodeWithoutBuidler
110
+ ] = await Promise . all ( [
111
+ runScriptWithBuidler (
112
+ this . env . buidlerArguments ,
113
+ "./successful-script.js"
114
+ ) ,
115
+ runScript ( "./successful-script.js" )
116
+ ] ) ;
117
+
118
+ assert . equal ( statusCodeWithBuidler , 0 ) ;
77
119
78
120
// We check here that the script is correctly testing this:
79
- const statusCode2 = await runScript ( "./successful-script.js" ) ;
80
- assert . notEqual ( statusCode2 , 0 ) ;
121
+ assert . notEqual ( statusCodeWithoutBuidler , 0 ) ;
81
122
} ) ;
82
123
83
124
it ( "Should forward all the buidler arguments" , async function ( ) {
0 commit comments