Skip to content

Commit 3fcc7e6

Browse files
cjihrigaddaleax
authored andcommitted
test: handle missing V8 tests in n-api test
The N-API test testInstanceOf.js relies on several V8 test files which may not exist in downloadable archives. If the files are missing, this commit causes a warning to be emitted rather than failing the test. Refs: #14113Fixes: #13344 PR-URL: #14123 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent fe6ca44 commit 3fcc7e6

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

‎test/addons-napi/test_general/testInstanceOf.js‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ const assert = require('assert');
99
constaddon=require(`./build/${common.buildType}/test_general`);
1010
constpath=require('path');
1111

12+
// This test depends on a number of V8 tests.
13+
constv8TestsDir=path.resolve(__dirname,'..','..','..','deps','v8',
14+
'test','mjsunit');
15+
constv8TestsDirExists=fs.existsSync(v8TestsDir);
16+
1217
// The following assert functions are referenced by v8's unit tests
1318
// See for instance deps/v8/test/mjsunit/instanceof.js
1419
// eslint-disable-next-line no-unused-vars
@@ -34,19 +39,22 @@ function assertThrows(statement){
3439
}
3540

3641
functiontestFile(fileName){
37-
constcontents=fs.readFileSync(fileName,{encoding: 'utf8'});
38-
eval(contents.replace(/[(]([^\s(]+)\s+instanceof\s+([^)]+)[)]/g,
39-
'(addon.doInstanceOf($1, $2))'));
42+
try{
43+
constcontents=fs.readFileSync(fileName,{encoding: 'utf8'});
44+
eval(contents.replace(/[(]([^\s(]+)\s+instanceof\s+([^)]+)[)]/g,
45+
'(addon.doInstanceOf($1, $2))'));
46+
}catch(err){
47+
// This test depends on V8 test files, which may not exist in downloaded
48+
// archives. Emit a warning if the tests cannot be found instead of failing.
49+
if(err.code==='ENOENT'&&!v8TestsDirExists)
50+
process.emitWarning(`test file ${fileName} does not exist.`);
51+
else
52+
throwerr;
53+
}
4054
}
4155

42-
testFile(
43-
path.join(path.resolve(__dirname,'..','..','..',
44-
'deps','v8','test','mjsunit'),
45-
'instanceof.js'));
46-
testFile(
47-
path.join(path.resolve(__dirname,'..','..','..',
48-
'deps','v8','test','mjsunit'),
49-
'instanceof-2.js'));
56+
testFile(path.join(v8TestsDir,'instanceof.js'));
57+
testFile(path.join(v8TestsDir,'instanceof-2.js'));
5058

5159
// We can only perform this test if we have a working Symbol.hasInstance
5260
if(typeofSymbol!=='undefined'&&'hasInstance'inSymbol&&

0 commit comments

Comments
(0)