|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 | 3 | const common = require('../../common');
|
| 4 | +const tmpdir = require('../../common/tmpdir'); |
| 5 | +const child_process = require('child_process'); |
| 6 | +const fs = require('fs'); |
| 7 | +const path = require('path'); |
| 8 | +const url = require('url'); |
4 | 9 | const filename = require.resolve(`./build/${common.buildType}/test_general`);
|
5 | 10 | const test_general = require(filename);
|
6 | 11 | const assert = require('assert');
|
7 | 12 |
|
8 |
| -// TODO(gabrielschulhof): This test may need updating if/when the filename |
9 |
| -// becomes a full-fledged URL. |
10 |
| -assert.strictEqual(test_general.filename, `file://${filename}`); |
| 13 | +tmpdir.refresh(); |
11 | 14 |
|
12 |
| -const [ major, minor, patch, release ] = test_general.testGetNodeVersion(); |
13 |
| -assert.strictEqual(process.version.split('-')[0], |
14 |
| - `v${major}.${minor}.${patch}`); |
15 |
| -assert.strictEqual(release, process.release.name); |
| 15 | +{ |
| 16 | + // TODO(gabrielschulhof): This test may need updating if/when the filename |
| 17 | + // becomes a full-fledged URL. |
| 18 | + assert.strictEqual(test_general.filename, url.pathToFileURL(filename).href); |
| 19 | +} |
| 20 | + |
| 21 | +{ |
| 22 | + const urlTestDir = path.join(tmpdir.path, 'foo%#bar'); |
| 23 | + const urlTestFile = path.join(urlTestDir, path.basename(filename)); |
| 24 | + fs.mkdirSync(urlTestDir, { recursive: true }); |
| 25 | + fs.copyFileSync(filename, urlTestFile); |
| 26 | + // Use a child process as indirection so that the native module is not loaded |
| 27 | + // into this process and can be removed here. |
| 28 | + const reportedFilename = child_process.spawnSync( |
| 29 | + process.execPath, |
| 30 | + ['-p', `require(${JSON.stringify(urlTestFile)}).filename`], |
| 31 | + { encoding: 'utf8' }).stdout.trim(); |
| 32 | + assert.doesNotMatch(reportedFilename, /foo%#bar/); |
| 33 | + assert.strictEqual(reportedFilename, url.pathToFileURL(urlTestFile).href); |
| 34 | + fs.rmSync(urlTestDir, { |
| 35 | + force: true, |
| 36 | + recursive: true, |
| 37 | + maxRetries: 256 |
| 38 | + }); |
| 39 | +} |
| 40 | + |
| 41 | +{ |
| 42 | + const [ major, minor, patch, release ] = test_general.testGetNodeVersion(); |
| 43 | + assert.strictEqual(process.version.split('-')[0], |
| 44 | + `v${major}.${minor}.${patch}`); |
| 45 | + assert.strictEqual(release, process.release.name); |
| 46 | +} |
0 commit comments