• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../../common');
3if (common.isWindows && (process.env.PROCESSOR_ARCHITEW6432 !== undefined))
4  common.skip('doesn\'t work on WOW64');
5
6const fs = require('fs');
7const path = require('path');
8const assert = require('assert');
9const { fork } = require('child_process');
10
11const tmpdir = require('../../common/tmpdir');
12
13// Make a path that is more than 260 chars long.
14// Any given folder cannot have a name longer than 260 characters,
15// so create 10 nested folders each with 30 character long names.
16let addonDestinationDir = path.resolve(tmpdir.path);
17
18for (let i = 0; i < 10; i++) {
19  addonDestinationDir = path.join(addonDestinationDir, 'x'.repeat(30));
20}
21
22const addonPath = path.join(__dirname,
23                            'build',
24                            common.buildType,
25                            'binding.node');
26const addonDestinationPath = path.join(addonDestinationDir, 'binding.node');
27
28// Loading an addon keeps the file open until the process terminates. Load
29// the addon in a child process so that when the parent terminates the file
30// is already closed and the tmpdir can be cleaned up.
31
32// Child
33if (process.argv[2] === 'child') {
34  // Attempt to load at long path destination
35  const addon = require(addonDestinationPath);
36  assert.notStrictEqual(addon, null);
37  assert.strictEqual(addon.hello(), 'world');
38  return;
39}
40
41// Parent
42tmpdir.refresh();
43
44// Copy binary to long path destination
45fs.mkdirSync(addonDestinationDir, { recursive: true });
46const contents = fs.readFileSync(addonPath);
47fs.writeFileSync(addonDestinationPath, contents);
48
49// Run test
50const child = fork(__filename, ['child'], { stdio: 'inherit' });
51child.on('exit', common.mustCall((code) => {
52  assert.strictEqual(code, 0);
53}));
54