@@ -9,8 +9,56 @@ import {
9
9
withTempDir , fixturesUseAsLibrary ,
10
10
} from './common' ;
11
11
12
- const npm = shell . which ( 'npm' ) . toString ( ) ;
13
- const node = shell . which ( 'node' ) . toString ( ) ;
12
+ const npm = shell . which ( 'npm' ) ?. toString ( ) ;
13
+ const node = shell . which ( 'node' ) ?. toString ( ) ;
14
+ const nvm = shell . which ( 'nvm' ) ?. toString ( ) ;
15
+ const isWindows = process . platform === 'win32' ;
16
+
17
+ function npmGlobalDir ( ) {
18
+ if ( ! process . env . HOME ) {
19
+ throw new Error ( 'HOME environment variable is undefined' ) ;
20
+ }
21
+ const npmDir = path . join (
22
+ process . env . HOME , '.npm-global'
23
+ ) ;
24
+ if ( ! shell . test ( '-d' , npmDir ) ) {
25
+ shell . echo ( `Creating test npm directory at ${ npmDir } ` ) ;
26
+ shell . mkdir ( npmDir ) ;
27
+ }
28
+ return npmDir ;
29
+ }
30
+
31
+ function npmLink ( ) {
32
+ if ( nvm || isWindows ) {
33
+ execFileSync ( npm , [ 'link' , '.' ] , {
34
+ cwd : path . resolve ( path . join ( __dirname , '..' , '..' ) ) ,
35
+ } ) ;
36
+ } else {
37
+ execFileSync ( npm , [ 'link' , '.' ] , {
38
+ cwd : path . resolve ( path . join ( __dirname , '..' , '..' ) ) ,
39
+ env : {
40
+ ...process . env ,
41
+ NPM_CONFIG_PREFIX : npmGlobalDir ( ) ,
42
+ } ,
43
+ } ) ;
44
+ }
45
+ }
46
+
47
+ function npmUnlink ( ) {
48
+ if ( nvm || isWindows ) {
49
+ execFileSync ( npm , [ 'unlink' , '.' ] , {
50
+ cwd : path . resolve ( path . join ( __dirname , '..' , '..' ) ) ,
51
+ } ) ;
52
+ } else {
53
+ execFileSync ( npm , [ 'unlink' , '.' ] , {
54
+ cwd : path . resolve ( path . join ( __dirname , '..' , '..' ) ) ,
55
+ env : {
56
+ ...process . env ,
57
+ NPM_CONFIG_PREFIX : npmGlobalDir ( ) ,
58
+ } ,
59
+ } ) ;
60
+ }
61
+ }
14
62
15
63
describe ( 'web-ext imported as a library' , ( ) => {
16
64
before ( function ( ) {
@@ -21,20 +69,16 @@ describe('web-ext imported as a library', () => {
21
69
this . skip ( ) ;
22
70
}
23
71
24
- execFileSync ( npm , [ 'link' , '.' ] , {
25
- cwd : path . resolve ( path . join ( __dirname , '..' , '..' ) ) ,
26
- } ) ;
72
+ npmLink ( ) ;
27
73
} ) ;
28
74
29
75
after ( ( ) => {
30
- execFileSync ( npm , [ 'unlink' , '.' ] , {
31
- cwd : path . resolve ( path . join ( __dirname , '..' , '..' ) ) ,
32
- } ) ;
76
+ npmUnlink ( ) ;
33
77
} ) ;
34
78
35
79
it ( 'can be imported as an ESM module' , async ( ) => {
36
80
await withTempDir ( async ( tmpDir ) => {
37
- execFileSync ( npm , [ 'link ' , 'web-ext' ] , { cwd : tmpDir . path ( ) } ) ;
81
+ execFileSync ( npm , [ 'install ' , 'web-ext' ] , { cwd : tmpDir . path ( ) } ) ;
38
82
shell . cp ( '-rf' , `${ fixturesUseAsLibrary } /*` , tmpDir . path ( ) ) ;
39
83
execFileSync ( node , [ '--experimental-modules' , 'test-import.mjs' ] , {
40
84
cwd : tmpDir . path ( ) ,
@@ -44,7 +88,7 @@ describe('web-ext imported as a library', () => {
44
88
45
89
it ( 'can be imported as a CommonJS module' , async ( ) => {
46
90
await withTempDir ( async ( tmpDir ) => {
47
- execFileSync ( npm , [ 'link ' , 'web-ext' ] , { cwd : tmpDir . path ( ) } ) ;
91
+ execFileSync ( npm , [ 'install ' , 'web-ext' ] , { cwd : tmpDir . path ( ) } ) ;
48
92
shell . cp ( '-rf' , `${ fixturesUseAsLibrary } /*` , tmpDir . path ( ) ) ;
49
93
execFileSync ( node , [ '--experimental-modules' , 'test-require.js' ] , {
50
94
cwd : tmpDir . path ( ) ,
0 commit comments