@@ -18,6 +18,7 @@ package main
1818
1919import (
2020 "bytes"
21+ "fmt"
2122 "io/ioutil"
2223 "os"
2324 "path/filepath"
@@ -28,6 +29,54 @@ import (
2829 "testing"
2930)
3031
32+ func TestIsEnabled (t * testing.T ) {
33+ tests := []struct {
34+ env map [string ]string
35+ expected bool
36+ }{
37+ {
38+ env : nil ,
39+ expected : true ,
40+ },
41+ {
42+ env : map [string ]string {"WRAPPER_ENABLED" : "1" },
43+ expected : true ,
44+ },
45+ {
46+ env : map [string ]string {"WRAPPER_ENABLED" : "true" },
47+ expected : true ,
48+ },
49+ {
50+ env : map [string ]string {"WRAPPER_ENABLED" : "yes" },
51+ expected : true ,
52+ },
53+ {
54+ env : map [string ]string {"WRAPPER_ENABLED" : "" },
55+ expected : true ,
56+ },
57+ {
58+ env : map [string ]string {"WRAPPER_ENABLED" : "0" },
59+ expected : false ,
60+ },
61+ {
62+ env : map [string ]string {"WRAPPER_ENABLED" : "no" },
63+ expected : false ,
64+ },
65+ {
66+ env : map [string ]string {"WRAPPER_ENABLED" : "false" },
67+ expected : false ,
68+ },
69+ }
70+ for _ , test := range tests {
71+ t .Run (fmt .Sprintf ("env: %v" , test .env ), func (t * testing.T ) {
72+ result := isEnabled (test .env )
73+ if test .expected != result {
74+ t .Errorf ("expected %v but got %v" , test .expected , result )
75+ }
76+ })
77+ }
78+ }
79+
3180func TestFindScript (t * testing.T ) {
3281 tests := []struct {
3382 description string
@@ -240,37 +289,37 @@ func TestNodeContext_unwrap(t *testing.T) {
240289 tests := []struct {
241290 description string
242291 input nodeContext
243- noErr bool
292+ noErr bool
244293 expected string
245294 }{
246295 {
247296 description : "no PATH leaves unchanged" ,
248297 input : nodeContext {program : originalNode },
249- noErr : false ,
298+ noErr : false ,
250299 expected : originalNode ,
251300 },
252301 {
253302 description : "empty PATH leaves unchanged" ,
254303 input : nodeContext {program : originalNode , env : map [string ]string {"PATH" : "" }},
255- noErr : false ,
304+ noErr : false ,
256305 expected : originalNode ,
257306 },
258307 {
259308 description : "no other node leaves unchanged" ,
260309 input : nodeContext {program : originalNode , env : map [string ]string {"PATH" : root }},
261- noErr : false ,
310+ noErr : false ,
262311 expected : originalNode ,
263312 },
264313 {
265314 description : "first other node wins" ,
266315 input : nodeContext {program : originalNode , env : map [string ]string {"PATH" : root + string (os .PathListSeparator ) + binPath + string (os .PathListSeparator ) + sbinPath }},
267- noErr : true ,
316+ noErr : true ,
268317 expected : binNode ,
269318 },
270319 {
271320 description : "first node wins when original not found" ,
272321 input : nodeContext {program : name , env : map [string ]string {"PATH" : root + string (os .PathListSeparator ) + binPath + string (os .PathListSeparator ) + sbinPath }},
273- noErr : true ,
322+ noErr : true ,
274323 expected : binNode ,
275324 },
276325 }
@@ -497,6 +546,12 @@ done
497546 args : []string {"node_modules/script.js" , "--inspect" },
498547 expected : "node_modules/script.js\n --inspect\n " ,
499548 },
549+ {
550+ description : "node_modules script: inspect left alone with WRAPPER_ENABLED=0" ,
551+ args : []string {"--inspect=9229" , "./node_nodules/script.js" },
552+ env : map [string ]string {"WRAPPER_ENABLED" : "0" },
553+ expected : "--inspect=9229\n ./node_nodules/script.js\n " ,
554+ },
500555 {
501556 description : "node_modules script with inspect: seeds NODE_DEBUG" ,
502557 args : []string {"--inspect" , "node_modules/script.js" },
0 commit comments