1
1
'use strict'
2
2
3
- const { describe, it } = require ( 'mocha' )
4
- const assert = require ( 'assert' )
3
+ const { describe, it } = require ( 'node:test' )
5
4
const path = require ( 'path' )
6
5
const os = require ( 'os' )
7
6
const gyp = require ( '../lib/node-gyp' )
@@ -46,8 +45,7 @@ const SPAWN_RESULT = cb => ({ on: function () { cb() } })
46
45
47
46
const driveLetter = os . platform ( ) === 'win32' ? `${ process . cwd ( ) . split ( path . sep ) [ 0 ] } ` : ''
48
47
function checkTargetPath ( target , value ) {
49
- let targetPath = path . join ( path . sep , target , 'include' ,
50
- 'node' , 'common.gypi' )
48
+ let targetPath = path . join ( path . sep , target , 'include' , 'node' , 'common.gypi' )
51
49
if ( process . platform === 'win32' ) {
52
50
targetPath = driveLetter + targetPath
53
51
}
@@ -56,68 +54,76 @@ function checkTargetPath (target, value) {
56
54
}
57
55
58
56
describe ( 'configure-nodedir' , function ( ) {
59
- it ( 'configure nodedir with node-gyp command line' , function ( done ) {
57
+ it ( 'configure nodedir with node-gyp command line' , async function ( ) {
60
58
const prog = gyp ( )
61
59
prog . parseArgv ( [ 'dummy_prog' , 'dummy_script' , '--nodedir=' + path . sep + 'usr' ] )
62
60
63
- prog . spawn = function ( program , args ) {
64
- for ( let i = 0 ; i < args . length ; i ++ ) {
65
- if ( checkTargetPath ( 'usr' , args [ i ] ) ) {
66
- return SPAWN_RESULT ( done )
61
+ await new Promise ( ( resolve , reject ) => {
62
+ prog . spawn = function ( program , args ) {
63
+ for ( let i = 0 ; i < args . length ; i ++ ) {
64
+ if ( checkTargetPath ( 'usr' , args [ i ] ) ) {
65
+ return SPAWN_RESULT ( resolve )
66
+ }
67
67
}
68
- } ;
69
- assert . fail ( )
70
- }
71
- configure ( prog , [ ] , assert . fail )
68
+ reject ( new Error ( 'Expected nodedir path not found' ) )
69
+ }
70
+ configure ( prog , [ ] , reject )
71
+ } )
72
72
} )
73
73
74
74
if ( process . config . variables . use_prefix_to_find_headers ) {
75
- it ( 'use-prefix-to-find-headers build time option - match' , function ( done ) {
75
+ it ( 'use-prefix-to-find-headers build time option - match' , async function ( ) {
76
76
const prog = gyp ( )
77
77
prog . parseArgv ( [ 'dummy_prog' , 'dummy_script' ] )
78
78
79
- prog . spawn = function ( program , args ) {
80
- for ( let i = 0 ; i < args . length ; i ++ ) {
79
+ await new Promise ( ( resolve , reject ) => {
80
+ prog . spawn = function ( program , args ) {
81
81
const nodedir = process . config . variables . node_prefix
82
- if ( checkTargetPath ( nodedir , args [ i ] ) ) {
83
- return SPAWN_RESULT ( done )
82
+ for ( let i = 0 ; i < args . length ; i ++ ) {
83
+ if ( checkTargetPath ( nodedir , args [ i ] ) ) {
84
+ return SPAWN_RESULT ( resolve )
85
+ }
84
86
}
85
- } ;
86
- assert . fail ( )
87
- }
88
- configure ( prog , [ ] , assert . fail )
87
+ reject ( new Error ( 'Expected nodedir path not found' ) )
88
+ }
89
+ configure ( prog , [ ] , reject )
90
+ } )
89
91
} )
90
92
91
- it ( 'use-prefix-to-find-headers build time option - no match' , function ( done ) {
93
+ it ( 'use-prefix-to-find-headers build time option - no match' , async function ( ) {
92
94
const prog = gyp ( )
93
95
prog . parseArgv ( [ 'dummy_prog' , 'dummy_script' ] )
94
96
95
- prog . spawn = function ( program , args ) {
96
- for ( let i = 0 ; i < args . length ; i ++ ) {
97
+ await new Promise ( ( resolve , reject ) => {
98
+ prog . spawn = function ( program , args ) {
97
99
const nodedir = process . config . variables . node_prefix
98
- if ( checkTargetPath ( nodedir , args [ i ] ) ) {
99
- assert . fail ( )
100
+ for ( let i = 0 ; i < args . length ; i ++ ) {
101
+ if ( checkTargetPath ( nodedir , args [ i ] ) ) {
102
+ return reject ( new Error ( 'Unexpected match found' ) )
103
+ }
100
104
}
101
- } ;
102
- return SPAWN_RESULT ( done )
103
- }
104
- configure2 ( prog , [ ] , assert . fail )
105
+ return SPAWN_RESULT ( resolve )
106
+ }
107
+ configure2 ( prog , [ ] , reject )
108
+ } )
105
109
} )
106
110
107
- it ( 'use-prefix-to-find-headers build time option, target specified' , function ( done ) {
111
+ it ( 'use-prefix-to-find-headers build time option, target specified' , async function ( ) {
108
112
const prog = gyp ( )
109
113
prog . parseArgv ( [ 'dummy_prog' , 'dummy_script' , '--target=8.0.0' ] )
110
114
111
- prog . spawn = function ( program , args ) {
112
- for ( let i = 0 ; i < args . length ; i ++ ) {
115
+ await new Promise ( ( resolve , reject ) => {
116
+ prog . spawn = function ( program , args ) {
113
117
const nodedir = process . config . variables . node_prefix
114
- if ( checkTargetPath ( nodedir , args [ i ] ) ) {
115
- assert . fail ( )
118
+ for ( let i = 0 ; i < args . length ; i ++ ) {
119
+ if ( checkTargetPath ( nodedir , args [ i ] ) ) {
120
+ return reject ( new Error ( 'Unexpected match found for target' ) )
121
+ }
116
122
}
117
- } ;
118
- return SPAWN_RESULT ( done )
119
- }
120
- configure ( prog , [ ] , assert . fail )
123
+ return SPAWN_RESULT ( resolve )
124
+ }
125
+ configure ( prog , [ ] , reject )
126
+ } )
121
127
} )
122
128
}
123
129
} )
0 commit comments