diff options
Diffstat (limited to 'test/addons/load-long-path/test.js')
-rw-r--r-- | test/addons/load-long-path/test.js | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/test/addons/load-long-path/test.js b/test/addons/load-long-path/test.js index 0160591746..168dad492b 100644 --- a/test/addons/load-long-path/test.js +++ b/test/addons/load-long-path/test.js @@ -6,9 +6,9 @@ if (common.isWindows && (process.env.PROCESSOR_ARCHITEW6432 !== undefined)) const fs = require('fs'); const path = require('path'); const assert = require('assert'); +const { fork } = require('child_process'); const tmpdir = require('../../common/tmpdir'); -tmpdir.refresh(); // Make a path that is more than 260 chars long. // Any given folder cannot have a name longer than 260 characters, @@ -17,7 +17,6 @@ let addonDestinationDir = path.resolve(tmpdir.path); for (let i = 0; i < 10; i++) { addonDestinationDir = path.join(addonDestinationDir, 'x'.repeat(30)); - fs.mkdirSync(addonDestinationDir); } const addonPath = path.join(__dirname, @@ -26,11 +25,29 @@ const addonPath = path.join(__dirname, 'binding.node'); const addonDestinationPath = path.join(addonDestinationDir, 'binding.node'); +// Loading an addon keeps the file open until the process terminates. Load +// the addon in a child process so that when the parent terminates the file +// is already closed and the tmpdir can be cleaned up. + +// Child +if (process.argv[2] === 'child') { + // Attempt to load at long path destination + const addon = require(addonDestinationPath); + assert.notStrictEqual(addon, null); + assert.strictEqual(addon.hello(), 'world'); + return; +} + +// Parent +tmpdir.refresh(); + // Copy binary to long path destination +fs.mkdirSync(addonDestinationDir, { recursive: true }); const contents = fs.readFileSync(addonPath); fs.writeFileSync(addonDestinationPath, contents); -// Attempt to load at long path destination -const addon = require(addonDestinationPath); -assert.notStrictEqual(addon, null); -assert.strictEqual(addon.hello(), 'world'); +// Run test +const child = fork(__filename, ['child'], { stdio: 'inherit' }); +child.on('exit', common.mustCall(function(code) { + assert.strictEqual(code, 0); +})); |