11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../../common');
41cb0ef41Sopenharmony_ciconst tmpdir = require('../../common/tmpdir');
51cb0ef41Sopenharmony_ciconst child_process = require('child_process');
61cb0ef41Sopenharmony_ciconst fs = require('fs');
71cb0ef41Sopenharmony_ciconst path = require('path');
81cb0ef41Sopenharmony_ciconst url = require('url');
91cb0ef41Sopenharmony_ciconst filename = require.resolve(`./build/${common.buildType}/test_general`);
101cb0ef41Sopenharmony_ciconst test_general = require(filename);
111cb0ef41Sopenharmony_ciconst assert = require('assert');
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_citmpdir.refresh();
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci{
161cb0ef41Sopenharmony_ci  // TODO(gabrielschulhof): This test may need updating if/when the filename
171cb0ef41Sopenharmony_ci  // becomes a full-fledged URL.
181cb0ef41Sopenharmony_ci  assert.strictEqual(test_general.filename, url.pathToFileURL(filename).href);
191cb0ef41Sopenharmony_ci}
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci{
221cb0ef41Sopenharmony_ci  const urlTestDir = path.join(tmpdir.path, 'foo%#bar');
231cb0ef41Sopenharmony_ci  const urlTestFile = path.join(urlTestDir, path.basename(filename));
241cb0ef41Sopenharmony_ci  fs.mkdirSync(urlTestDir, { recursive: true });
251cb0ef41Sopenharmony_ci  fs.copyFileSync(filename, urlTestFile);
261cb0ef41Sopenharmony_ci  // Use a child process as indirection so that the built-in modules is not loaded
271cb0ef41Sopenharmony_ci  // into this process and can be removed here.
281cb0ef41Sopenharmony_ci  const reportedFilename = child_process.spawnSync(
291cb0ef41Sopenharmony_ci    process.execPath,
301cb0ef41Sopenharmony_ci    ['-p', `require(${JSON.stringify(urlTestFile)}).filename`],
311cb0ef41Sopenharmony_ci    { encoding: 'utf8' }).stdout.trim();
321cb0ef41Sopenharmony_ci  assert.doesNotMatch(reportedFilename, /foo%#bar/);
331cb0ef41Sopenharmony_ci  assert.strictEqual(reportedFilename, url.pathToFileURL(urlTestFile).href);
341cb0ef41Sopenharmony_ci  fs.rmSync(urlTestDir, {
351cb0ef41Sopenharmony_ci    force: true,
361cb0ef41Sopenharmony_ci    recursive: true,
371cb0ef41Sopenharmony_ci    maxRetries: 256,
381cb0ef41Sopenharmony_ci  });
391cb0ef41Sopenharmony_ci}
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci{
421cb0ef41Sopenharmony_ci  const [ major, minor, patch, release ] = test_general.testGetNodeVersion();
431cb0ef41Sopenharmony_ci  assert.strictEqual(process.version.split('-')[0],
441cb0ef41Sopenharmony_ci                     `v${major}.${minor}.${patch}`);
451cb0ef41Sopenharmony_ci  assert.strictEqual(release, process.release.name);
461cb0ef41Sopenharmony_ci}
47