From bbb3e501e93bb0bb4ee4beb4a9488818432e22bf Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 30 Sep 2024 10:57:00 +0200 Subject: [PATCH] test: fix addons and node-api test assumptions --- test/addons/repl-domain-abort/test.js | 2 +- test/node-api/test_instance_data/test.js | 9 ++------- test/node-api/test_uv_threadpool_size/node-options.js | 5 +---- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/test/addons/repl-domain-abort/test.js b/test/addons/repl-domain-abort/test.js index 8d148432c31c21..0108de0d9ee67d 100644 --- a/test/addons/repl-domain-abort/test.js +++ b/test/addons/repl-domain-abort/test.js @@ -38,7 +38,7 @@ process.on('exit', () => { const lines = [ // This line shouldn't cause an assertion error. - `require('${buildPath}')` + + `require(${JSON.stringify(buildPath)})` + // Log output to double check callback ran. '.method(function(v1, v2) {' + 'console.log(\'cb_ran\'); return v1 === true && v2 === false; });', diff --git a/test/node-api/test_instance_data/test.js b/test/node-api/test_instance_data/test.js index 7f8e785ac43546..63274a5462bcab 100644 --- a/test/node-api/test_instance_data/test.js +++ b/test/node-api/test_instance_data/test.js @@ -38,13 +38,8 @@ if (module !== require.main) { function testProcessExit(addonName) { // Make sure that process exit is clean when the instance data has // references to JS objects. - const path = require - .resolve(`./build/${common.buildType}/${addonName}`) - // Replace any backslashes with double backslashes because they'll be re- - // interpreted back to single backslashes in the command line argument - // to the child process. Windows needs this. - .replace(/\\/g, '\\\\'); - const child = spawnSync(process.execPath, ['-e', `require('${path}');`]); + const path = require.resolve(`./build/${common.buildType}/${addonName}`) + const child = spawnSync(process.execPath, ['-e', `require(${JSON.stringify(path)});`]); assert.strictEqual(child.signal, null); assert.strictEqual(child.status, 0); assert.strictEqual(child.stderr.toString(), 'addon_free'); diff --git a/test/node-api/test_uv_threadpool_size/node-options.js b/test/node-api/test_uv_threadpool_size/node-options.js index 40610274acce4c..e853f5a101c0c0 100644 --- a/test/node-api/test_uv_threadpool_size/node-options.js +++ b/test/node-api/test_uv_threadpool_size/node-options.js @@ -13,11 +13,8 @@ const uvThreadPoolPath = '../../fixtures/dotenv/uv-threadpool.env'; // Should update UV_THREADPOOL_SIZE let filePath = path.join(__dirname, `./build/${common.buildType}/test_uv_threadpool_size`); -if (common.isWindows) { - filePath = filePath.replaceAll('\\', '\\\\'); -} const code = ` - const { test } = require('${filePath}'); + const { test } = require(${JSON.stringify(filePath)}); const size = parseInt(process.env.UV_THREADPOOL_SIZE, 10); require('assert').strictEqual(size, 4); test(size);