11'use strict'
22
3- const { describe, it } = require ( 'mocha' )
4- const assert = require ( 'assert' )
3+ const { describe, it } = require ( 'node:test' )
54const path = require ( 'path' )
65const os = require ( 'os' )
76const gyp = require ( '../lib/node-gyp' )
@@ -46,8 +45,7 @@ const SPAWN_RESULT = cb => ({ on: function () { cb() } })
4645
4746const driveLetter = os . platform ( ) === 'win32' ? `${ process . cwd ( ) . split ( path . sep ) [ 0 ] } ` : ''
4847function 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' )
5149 if ( process . platform === 'win32' ) {
5250 targetPath = driveLetter + targetPath
5351 }
@@ -56,68 +54,76 @@ function checkTargetPath (target, value) {
5654}
5755
5856describe ( '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 ( ) {
6058 const prog = gyp ( )
6159 prog . parseArgv ( [ 'dummy_prog' , 'dummy_script' , '--nodedir=' + path . sep + 'usr' ] )
6260
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+ }
6767 }
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+ } )
7272 } )
7373
7474 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 ( ) {
7676 const prog = gyp ( )
7777 prog . parseArgv ( [ 'dummy_prog' , 'dummy_script' ] )
7878
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 ) {
8181 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+ }
8486 }
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+ } )
8991 } )
9092
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 ( ) {
9294 const prog = gyp ( )
9395 prog . parseArgv ( [ 'dummy_prog' , 'dummy_script' ] )
9496
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 ) {
9799 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+ }
100104 }
101- } ;
102- return SPAWN_RESULT ( done )
103- }
104- configure2 ( prog , [ ] , assert . fail )
105+ return SPAWN_RESULT ( resolve )
106+ }
107+ configure2 ( prog , [ ] , reject )
108+ } )
105109 } )
106110
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 ( ) {
108112 const prog = gyp ( )
109113 prog . parseArgv ( [ 'dummy_prog' , 'dummy_script' , '--target=8.0.0' ] )
110114
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 ) {
113117 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+ }
116122 }
117- } ;
118- return SPAWN_RESULT ( done )
119- }
120- configure ( prog , [ ] , assert . fail )
123+ return SPAWN_RESULT ( resolve )
124+ }
125+ configure ( prog , [ ] , reject )
126+ } )
121127 } )
122128 }
123129} )
0 commit comments