diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6bf975cf9f..ef86b1981a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -77,7 +77,7 @@ jobs: mkdir -p $NODE_GYP_TEMP_DIR npm pack tar xzf *.tgz -C $NODE_GYP_TEMP_DIR --strip-components=1 - cp -r test/ $NODE_GYP_TEMP_DIR/test/ + cp -r tests/ $NODE_GYP_TEMP_DIR/tests/ echo "dir=$NODE_GYP_TEMP_DIR" >> "$GITHUB_OUTPUT" - name: Test working-directory: ${{ steps.pack.outputs.dir }} diff --git a/.npmignore b/.npmignore index 8f95594d44..47a2fff035 100644 --- a/.npmignore +++ b/.npmignore @@ -9,7 +9,7 @@ /gyp/test /gyp/tools/ /node-gyp-*.tgz -/test/ -/test/.node-gyp +/tests/ +/tests/.node-gyp /update-gyp.py node-gyp-*.tgz diff --git a/package.json b/package.json index f69a022ef3..ec32772cfe 100644 --- a/package.json +++ b/package.json @@ -40,13 +40,12 @@ "bindings": "^1.5.0", "cross-env": "^7.0.3", "eslint": "^9.16.0", - "mocha": "^11.0.1", "nan": "^2.14.2", "neostandard": "^0.11.9", "require-inject": "^1.4.4" }, "scripts": { - "lint": "eslint \"*/*.js\" \"test/**/*.js\" \".github/**/*.js\"", - "test": "cross-env NODE_GYP_NULL_LOGGER=true mocha --timeout 15000 test/test-download.js test/test-*" + "lint": "eslint \"*/*.js\" \"tests/**/*.js\" \".github/**/*.js\"", + "test": "cross-env NODE_GYP_NULL_LOGGER=true node --test" } } diff --git a/test/common.js b/test/common.js deleted file mode 100644 index 489502d4dd..0000000000 --- a/test/common.js +++ /dev/null @@ -1,33 +0,0 @@ -const envPaths = require('env-paths') -const semver = require('semver') - -module.exports.devDir = envPaths('node-gyp', { suffix: '' }).cache - -module.exports.poison = (object, property) => { - function fail () { - console.error(Error(`Property ${property} should not have been accessed.`)) - process.abort() - } - const descriptor = { - configurable: false, - enumerable: false, - get: fail, - set: fail - } - Object.defineProperty(object, property, descriptor) -} - -// Only run full test suite when instructed and on a non-prerelease version of node -module.exports.FULL_TEST = - process.env.FULL_TEST === '1' && - process.release.name === 'node' && - semver.prerelease(process.version) === null - -module.exports.platformTimeout = (def, obj) => { - for (const [key, value] of Object.entries(obj)) { - if (process.platform === key) { - return value * 60 * 1000 - } - } - return def * 60 * 1000 -} diff --git a/test/simple-proxy.js b/test/simple-proxy.js deleted file mode 100644 index 4f8c4137ef..0000000000 --- a/test/simple-proxy.js +++ /dev/null @@ -1,27 +0,0 @@ -'use strict' - -const http = require('http') -const https = require('https') -const server = http.createServer(handler) -const port = +process.argv[2] -const prefix = process.argv[3] -const upstream = process.argv[4] -let calls = 0 - -server.listen(port) - -function handler (req, res) { - if (req.url.indexOf(prefix) !== 0) { - throw new Error('request url [' + req.url + '] does not start with [' + prefix + ']') - } - - const upstreamUrl = upstream + req.url.substring(prefix.length) - https.get(upstreamUrl, function (ures) { - ures.on('end', function () { - if (++calls === 2) { - server.close() - } - }) - ures.pipe(res) - }) -} diff --git a/test/test-configure-python.js b/test/test-configure-python.js deleted file mode 100644 index 094e79182c..0000000000 --- a/test/test-configure-python.js +++ /dev/null @@ -1,78 +0,0 @@ -'use strict' - -const { describe, it } = require('mocha') -const assert = require('assert') -const path = require('path') -const { devDir } = require('./common') -const gyp = require('../lib/node-gyp') -const requireInject = require('require-inject') - -const configure = requireInject('../lib/configure', { - 'graceful-fs': { - openSync: () => 0, - closeSync: () => {}, - existsSync: () => {}, - promises: { - stat: async () => ({}), - mkdir: async () => {}, - writeFile: async () => {} - } - } -}) - -const EXPECTED_PYPATH = path.join(__dirname, '..', 'gyp', 'pylib') -const SEPARATOR = process.platform === 'win32' ? ';' : ':' -const SPAWN_RESULT = cb => ({ on: function () { cb() } }) - -describe('configure-python', function () { - it('configure PYTHONPATH with no existing env', function (done) { - delete process.env.PYTHONPATH - - const prog = gyp() - prog.parseArgv([]) - prog.spawn = function () { - assert.strictEqual(process.env.PYTHONPATH, EXPECTED_PYPATH) - return SPAWN_RESULT(done) - } - prog.devDir = devDir - configure(prog, [], assert.fail) - }) - - it('configure PYTHONPATH with existing env of one dir', function (done) { - const existingPath = path.join('a', 'b') - process.env.PYTHONPATH = existingPath - - const prog = gyp() - prog.parseArgv([]) - prog.spawn = function () { - assert.strictEqual(process.env.PYTHONPATH, [EXPECTED_PYPATH, existingPath].join(SEPARATOR)) - - const dirs = process.env.PYTHONPATH.split(SEPARATOR) - assert.deepStrictEqual(dirs, [EXPECTED_PYPATH, existingPath]) - - return SPAWN_RESULT(done) - } - prog.devDir = devDir - configure(prog, [], assert.fail) - }) - - it('configure PYTHONPATH with existing env of multiple dirs', function (done) { - const pythonDir1 = path.join('a', 'b') - const pythonDir2 = path.join('b', 'c') - const existingPath = [pythonDir1, pythonDir2].join(SEPARATOR) - process.env.PYTHONPATH = existingPath - - const prog = gyp() - prog.parseArgv([]) - prog.spawn = function () { - assert.strictEqual(process.env.PYTHONPATH, [EXPECTED_PYPATH, existingPath].join(SEPARATOR)) - - const dirs = process.env.PYTHONPATH.split(SEPARATOR) - assert.deepStrictEqual(dirs, [EXPECTED_PYPATH, pythonDir1, pythonDir2]) - - return SPAWN_RESULT(done) - } - prog.devDir = devDir - configure(prog, [], assert.fail) - }) -}) diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000000..319523f282 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1,2 @@ +!node_modules +node_modules/hello_world/build \ No newline at end of file diff --git a/tests/common.js b/tests/common.js new file mode 100644 index 0000000000..51f3961d00 --- /dev/null +++ b/tests/common.js @@ -0,0 +1,21 @@ +const { cache } = require('env-paths')('node-gyp', { suffix: '' }) +const semver = require('semver') + +module.exports = { + devDir: cache, + + poison (object, property) { + const fail = () => { + console.error(new Error(`Property ${property} should not have been accessed.`)) + process.abort() + } + Object.defineProperty(object, property, { configurable: false, enumerable: false, get: fail, set: fail }) + }, + + FULL_TEST: process.env.FULL_TEST === '1' && process.release.name === 'node' && !semver.prerelease(process.version), + + platformTimeout (def, obj) { + const platformTimeout = obj[process.platform] + return platformTimeout ? platformTimeout * 60 * 1000 : def * 60 * 1000 + } +} diff --git a/test/fixtures/VSSetup_VS_2019_Professional_workload.txt b/tests/fixtures/VSSetup_VS_2019_Professional_workload.txt similarity index 100% rename from test/fixtures/VSSetup_VS_2019_Professional_workload.txt rename to tests/fixtures/VSSetup_VS_2019_Professional_workload.txt diff --git a/test/fixtures/VSSetup_VS_2022_VS2019_workload.txt b/tests/fixtures/VSSetup_VS_2022_VS2019_workload.txt similarity index 100% rename from test/fixtures/VSSetup_VS_2022_VS2019_workload.txt rename to tests/fixtures/VSSetup_VS_2022_VS2019_workload.txt diff --git a/test/fixtures/VSSetup_VS_2022_multiple_install.txt b/tests/fixtures/VSSetup_VS_2022_multiple_install.txt similarity index 100% rename from test/fixtures/VSSetup_VS_2022_multiple_install.txt rename to tests/fixtures/VSSetup_VS_2022_multiple_install.txt diff --git a/test/fixtures/VSSetup_VS_2022_workload.txt b/tests/fixtures/VSSetup_VS_2022_workload.txt similarity index 100% rename from test/fixtures/VSSetup_VS_2022_workload.txt rename to tests/fixtures/VSSetup_VS_2022_workload.txt diff --git a/test/fixtures/VSSetup_VS_2022_workload_missing_sdk.txt b/tests/fixtures/VSSetup_VS_2022_workload_missing_sdk.txt similarity index 100% rename from test/fixtures/VSSetup_VS_2022_workload_missing_sdk.txt rename to tests/fixtures/VSSetup_VS_2022_workload_missing_sdk.txt diff --git a/test/fixtures/VS_2017_BuildTools_minimal.txt b/tests/fixtures/VS_2017_BuildTools_minimal.txt similarity index 100% rename from test/fixtures/VS_2017_BuildTools_minimal.txt rename to tests/fixtures/VS_2017_BuildTools_minimal.txt diff --git a/test/fixtures/VS_2017_Community_workload.txt b/tests/fixtures/VS_2017_Community_workload.txt similarity index 100% rename from test/fixtures/VS_2017_Community_workload.txt rename to tests/fixtures/VS_2017_Community_workload.txt diff --git a/test/fixtures/VS_2017_Express.txt b/tests/fixtures/VS_2017_Express.txt similarity index 100% rename from test/fixtures/VS_2017_Express.txt rename to tests/fixtures/VS_2017_Express.txt diff --git a/test/fixtures/VS_2017_Unusable.txt b/tests/fixtures/VS_2017_Unusable.txt similarity index 100% rename from test/fixtures/VS_2017_Unusable.txt rename to tests/fixtures/VS_2017_Unusable.txt diff --git a/test/fixtures/VS_2019_BuildTools_minimal.txt b/tests/fixtures/VS_2019_BuildTools_minimal.txt similarity index 100% rename from test/fixtures/VS_2019_BuildTools_minimal.txt rename to tests/fixtures/VS_2019_BuildTools_minimal.txt diff --git a/test/fixtures/VS_2019_Community_workload.txt b/tests/fixtures/VS_2019_Community_workload.txt similarity index 100% rename from test/fixtures/VS_2019_Community_workload.txt rename to tests/fixtures/VS_2019_Community_workload.txt diff --git a/test/fixtures/VS_2019_Preview.txt b/tests/fixtures/VS_2019_Preview.txt similarity index 100% rename from test/fixtures/VS_2019_Preview.txt rename to tests/fixtures/VS_2019_Preview.txt diff --git a/test/fixtures/VS_2022_BuildTools_arm64_only.txt b/tests/fixtures/VS_2022_BuildTools_arm64_only.txt similarity index 100% rename from test/fixtures/VS_2022_BuildTools_arm64_only.txt rename to tests/fixtures/VS_2022_BuildTools_arm64_only.txt diff --git a/test/fixtures/VS_2022_Community_workload.txt b/tests/fixtures/VS_2022_Community_workload.txt similarity index 100% rename from test/fixtures/VS_2022_Community_workload.txt rename to tests/fixtures/VS_2022_Community_workload.txt diff --git a/test/fixtures/certs.js b/tests/fixtures/certs.js similarity index 100% rename from test/fixtures/certs.js rename to tests/fixtures/certs.js diff --git a/test/fixtures/nodedir/include/node/config.gypi b/tests/fixtures/nodedir/include/node/config.gypi similarity index 100% rename from test/fixtures/nodedir/include/node/config.gypi rename to tests/fixtures/nodedir/include/node/config.gypi diff --git a/test/fixtures/test-charmap.py b/tests/fixtures/test-charmap.py similarity index 100% rename from test/fixtures/test-charmap.py rename to tests/fixtures/test-charmap.py diff --git a/test/node_modules/hello_napi/binding.gyp b/tests/node_modules/hello_napi/binding.gyp similarity index 100% rename from test/node_modules/hello_napi/binding.gyp rename to tests/node_modules/hello_napi/binding.gyp diff --git a/test/node_modules/hello_napi/common.gypi b/tests/node_modules/hello_napi/common.gypi similarity index 100% rename from test/node_modules/hello_napi/common.gypi rename to tests/node_modules/hello_napi/common.gypi diff --git a/test/node_modules/hello_napi/hello.c b/tests/node_modules/hello_napi/hello.c similarity index 100% rename from test/node_modules/hello_napi/hello.c rename to tests/node_modules/hello_napi/hello.c diff --git a/test/node_modules/hello_napi/hello.js b/tests/node_modules/hello_napi/hello.js similarity index 100% rename from test/node_modules/hello_napi/hello.js rename to tests/node_modules/hello_napi/hello.js diff --git a/test/node_modules/hello_napi/package.json b/tests/node_modules/hello_napi/package.json similarity index 100% rename from test/node_modules/hello_napi/package.json rename to tests/node_modules/hello_napi/package.json diff --git a/test/node_modules/hello_world/binding.gyp b/tests/node_modules/hello_world/binding.gyp similarity index 100% rename from test/node_modules/hello_world/binding.gyp rename to tests/node_modules/hello_world/binding.gyp diff --git a/test/node_modules/hello_world/hello.cc b/tests/node_modules/hello_world/hello.cc similarity index 100% rename from test/node_modules/hello_world/hello.cc rename to tests/node_modules/hello_world/hello.cc diff --git a/test/node_modules/hello_world/hello.js b/tests/node_modules/hello_world/hello.js similarity index 100% rename from test/node_modules/hello_world/hello.js rename to tests/node_modules/hello_world/hello.js diff --git a/test/node_modules/hello_world/package.json b/tests/node_modules/hello_world/package.json similarity index 100% rename from test/node_modules/hello_world/package.json rename to tests/node_modules/hello_world/package.json diff --git a/test/test-addon.js b/tests/test-addon.js similarity index 87% rename from test/test-addon.js rename to tests/test-addon.js index 1f4d95ed7e..676bca45d1 100644 --- a/test/test-addon.js +++ b/tests/test-addon.js @@ -1,6 +1,6 @@ 'use strict' -const { describe, it } = require('mocha') +const { describe, it } = require('node:test') const assert = require('assert') const path = require('path') const fs = require('graceful-fs') @@ -42,9 +42,9 @@ function checkCharmapValid () { } describe('addon', function () { - it('build simple addon', async function () { - this.timeout(platformTimeout(1, { win32: 5 })) + const timeout = platformTimeout(1, { win32: 5 }) + it('build simple addon', { timeout }, async function () { // Set the loglevel otherwise the output disappears when run via 'npm test' const cmd = [nodeGyp, 'rebuild', '-C', addonPath, '--loglevel=verbose'] const [err, logLines] = await execFile(cmd) @@ -54,9 +54,9 @@ describe('addon', function () { assert.strictEqual(runHello(), 'world') }) - it('build simple addon in path with non-ascii characters', async function () { + it('build simple addon in path with non-ascii characters', { timeout }, async function (t) { if (!checkCharmapValid()) { - return this.skip('python console app can\'t encode non-ascii character.') + return t.skip('python console app can\'t encode non-ascii character.') } // Select non-ascii characters by current encoding @@ -67,11 +67,9 @@ describe('addon', function () { }[getEncoding()] // If encoding is UTF-8 or other then no need to test if (!testDirName) { - return this.skip('no need to test') + return t.skip('no need to test') } - this.timeout(platformTimeout(1, { win32: 5 })) - let data const configPath = path.join(addonPath, 'build', 'config.gypi') try { @@ -115,9 +113,7 @@ describe('addon', function () { assert.strictEqual(runHello(), 'world') }) - it('addon works with renamed host executable', async function () { - this.timeout(platformTimeout(1, { win32: 5 })) - + it('addon works with renamed host executable', { timeout }, async function () { const notNodePath = path.join(os.tmpdir(), 'notnode' + path.extname(process.execPath)) fs.copyFileSync(process.execPath, notNodePath) diff --git a/test/test-configure-nodedir.js b/tests/test-configure-nodedir.js similarity index 58% rename from test/test-configure-nodedir.js rename to tests/test-configure-nodedir.js index a6debded06..17ddbaf8af 100644 --- a/test/test-configure-nodedir.js +++ b/tests/test-configure-nodedir.js @@ -1,7 +1,6 @@ 'use strict' -const { describe, it } = require('mocha') -const assert = require('assert') +const { describe, it } = require('node:test') const path = require('path') const os = require('os') const gyp = require('../lib/node-gyp') @@ -46,8 +45,7 @@ const SPAWN_RESULT = cb => ({ on: function () { cb() } }) const driveLetter = os.platform() === 'win32' ? `${process.cwd().split(path.sep)[0]}` : '' function checkTargetPath (target, value) { - let targetPath = path.join(path.sep, target, 'include', - 'node', 'common.gypi') + let targetPath = path.join(path.sep, target, 'include', 'node', 'common.gypi') if (process.platform === 'win32') { targetPath = driveLetter + targetPath } @@ -56,68 +54,76 @@ function checkTargetPath (target, value) { } describe('configure-nodedir', function () { - it('configure nodedir with node-gyp command line', function (done) { + it('configure nodedir with node-gyp command line', async function () { const prog = gyp() prog.parseArgv(['dummy_prog', 'dummy_script', '--nodedir=' + path.sep + 'usr']) - prog.spawn = function (program, args) { - for (let i = 0; i < args.length; i++) { - if (checkTargetPath('usr', args[i])) { - return SPAWN_RESULT(done) + await new Promise((resolve, reject) => { + prog.spawn = function (program, args) { + for (let i = 0; i < args.length; i++) { + if (checkTargetPath('usr', args[i])) { + return SPAWN_RESULT(resolve) + } } - }; - assert.fail() - } - configure(prog, [], assert.fail) + reject(new Error('Expected nodedir path not found')) + } + configure(prog, [], reject) + }) }) if (process.config.variables.use_prefix_to_find_headers) { - it('use-prefix-to-find-headers build time option - match', function (done) { + it('use-prefix-to-find-headers build time option - match', async function () { const prog = gyp() prog.parseArgv(['dummy_prog', 'dummy_script']) - prog.spawn = function (program, args) { - for (let i = 0; i < args.length; i++) { + await new Promise((resolve, reject) => { + prog.spawn = function (program, args) { const nodedir = process.config.variables.node_prefix - if (checkTargetPath(nodedir, args[i])) { - return SPAWN_RESULT(done) + for (let i = 0; i < args.length; i++) { + if (checkTargetPath(nodedir, args[i])) { + return SPAWN_RESULT(resolve) + } } - }; - assert.fail() - } - configure(prog, [], assert.fail) + reject(new Error('Expected nodedir path not found')) + } + configure(prog, [], reject) + }) }) - it('use-prefix-to-find-headers build time option - no match', function (done) { + it('use-prefix-to-find-headers build time option - no match', async function () { const prog = gyp() prog.parseArgv(['dummy_prog', 'dummy_script']) - prog.spawn = function (program, args) { - for (let i = 0; i < args.length; i++) { + await new Promise((resolve, reject) => { + prog.spawn = function (program, args) { const nodedir = process.config.variables.node_prefix - if (checkTargetPath(nodedir, args[i])) { - assert.fail() + for (let i = 0; i < args.length; i++) { + if (checkTargetPath(nodedir, args[i])) { + return reject(new Error('Unexpected match found')) + } } - }; - return SPAWN_RESULT(done) - } - configure2(prog, [], assert.fail) + return SPAWN_RESULT(resolve) + } + configure2(prog, [], reject) + }) }) - it('use-prefix-to-find-headers build time option, target specified', function (done) { + it('use-prefix-to-find-headers build time option, target specified', async function () { const prog = gyp() prog.parseArgv(['dummy_prog', 'dummy_script', '--target=8.0.0']) - prog.spawn = function (program, args) { - for (let i = 0; i < args.length; i++) { + await new Promise((resolve, reject) => { + prog.spawn = function (program, args) { const nodedir = process.config.variables.node_prefix - if (checkTargetPath(nodedir, args[i])) { - assert.fail() + for (let i = 0; i < args.length; i++) { + if (checkTargetPath(nodedir, args[i])) { + return reject(new Error('Unexpected match found for target')) + } } - }; - return SPAWN_RESULT(done) - } - configure(prog, [], assert.fail) + return SPAWN_RESULT(resolve) + } + configure(prog, [], reject) + }) }) } }) diff --git a/tests/test-configure-python.js b/tests/test-configure-python.js new file mode 100644 index 0000000000..cd7cd0a2a9 --- /dev/null +++ b/tests/test-configure-python.js @@ -0,0 +1,99 @@ +'use strict' + +const { describe, it } = require('node:test') +const assert = require('assert') +const path = require('path') +const { devDir } = require('./common') +const gyp = require('../lib/node-gyp') +const requireInject = require('require-inject') + +const configure = requireInject('../lib/configure', { + 'graceful-fs': { + openSync: () => 0, + closeSync: () => {}, + existsSync: () => {}, + promises: { + stat: async () => ({}), + mkdir: async () => {}, + writeFile: async () => {} + } + } +}) + +const EXPECTED_PYPATH = path.join(__dirname, '..', 'gyp', 'pylib') +const SEPARATOR = process.platform === 'win32' ? ';' : ':' +const SPAWN_RESULT = cb => ({ on: function () { cb() } }) + +describe('configure-python', function () { + it('configure PYTHONPATH with no existing env', async function () { + delete process.env.PYTHONPATH + + const prog = gyp() + prog.parseArgv([]) + + await new Promise((resolve, reject) => { + prog.spawn = function () { + try { + assert.strictEqual(process.env.PYTHONPATH, EXPECTED_PYPATH) + return SPAWN_RESULT(resolve) + } catch (err) { + reject(err) + } + } + prog.devDir = devDir + configure(prog, [], reject) + }) + }) + + it('configure PYTHONPATH with existing env of one dir', async function () { + const existingPath = path.join('a', 'b') + process.env.PYTHONPATH = existingPath + + const prog = gyp() + prog.parseArgv([]) + + await new Promise((resolve, reject) => { + prog.spawn = function () { + try { + assert.strictEqual(process.env.PYTHONPATH, [EXPECTED_PYPATH, existingPath].join(SEPARATOR)) + + const dirs = process.env.PYTHONPATH.split(SEPARATOR) + assert.deepStrictEqual(dirs, [EXPECTED_PYPATH, existingPath]) + + return SPAWN_RESULT(resolve) + } catch (err) { + reject(err) + } + } + prog.devDir = devDir + configure(prog, [], reject) + }) + }) + + it('configure PYTHONPATH with existing env of multiple dirs', async function () { + const pythonDir1 = path.join('a', 'b') + const pythonDir2 = path.join('b', 'c') + const existingPath = [pythonDir1, pythonDir2].join(SEPARATOR) + process.env.PYTHONPATH = existingPath + + const prog = gyp() + prog.parseArgv([]) + + await new Promise((resolve, reject) => { + prog.spawn = function () { + try { + assert.strictEqual(process.env.PYTHONPATH, [EXPECTED_PYPATH, existingPath].join(SEPARATOR)) + + const dirs = process.env.PYTHONPATH.split(SEPARATOR) + assert.deepStrictEqual(dirs, [EXPECTED_PYPATH, pythonDir1, pythonDir2]) + + return SPAWN_RESULT(resolve) + } catch (err) { + reject(err) + } + } + prog.devDir = devDir + configure(prog, [], reject) + }) + }) +}) diff --git a/test/test-create-config-gypi.js b/tests/test-create-config-gypi.js similarity index 97% rename from test/test-create-config-gypi.js rename to tests/test-create-config-gypi.js index 3c77b87859..efa447d164 100644 --- a/test/test-create-config-gypi.js +++ b/tests/test-create-config-gypi.js @@ -1,7 +1,7 @@ 'use strict' const path = require('path') -const { describe, it } = require('mocha') +const { describe, it } = require('node:test') const assert = require('assert') const gyp = require('../lib/node-gyp') const { parseConfigGypi, getCurrentConfigGypi } = require('../lib/create-config-gypi') diff --git a/test/test-download.js b/tests/test-download.js similarity index 96% rename from test/test-download.js rename to tests/test-download.js index a746c98cc6..9bfbaf8ffb 100644 --- a/test/test-download.js +++ b/tests/test-download.js @@ -1,6 +1,6 @@ 'use strict' -const { describe, it, after } = require('mocha') +const { describe, it, after } = require('node:test') const assert = require('assert') const fs = require('fs/promises') const path = require('path') @@ -155,13 +155,11 @@ describe('download', function () { // only run this test if we are running a version of Node with predictable version path behavior - it('download headers (actual)', async function () { + it('download headers (actual)', { timeout: platformTimeout(1, { win32: 5 }) }, async function (t) { if (!FULL_TEST) { - return this.skip('Skipping actual download of headers due to test environment configuration') + return t.skip('Skipping actual download of headers due to test environment configuration') } - this.timeout(platformTimeout(1, { win32: 5 })) - const expectedDir = path.join(devDir, process.version.replace(/^v/, '')) await fs.rm(expectedDir, { recursive: true, force: true, maxRetries: 3 }) diff --git a/test/test-find-accessible-sync.js b/tests/test-find-accessible-sync.js similarity index 98% rename from test/test-find-accessible-sync.js rename to tests/test-find-accessible-sync.js index 0c8a5ddf07..66f5090f5f 100644 --- a/test/test-find-accessible-sync.js +++ b/tests/test-find-accessible-sync.js @@ -1,6 +1,6 @@ 'use strict' -const { describe, it } = require('mocha') +const { describe, it } = require('node:test') const assert = require('assert') const path = require('path') const requireInject = require('require-inject') diff --git a/test/test-find-node-directory.js b/tests/test-find-node-directory.js similarity index 98% rename from test/test-find-node-directory.js rename to tests/test-find-node-directory.js index e36a5c04ea..284938f57b 100644 --- a/test/test-find-node-directory.js +++ b/tests/test-find-node-directory.js @@ -1,6 +1,6 @@ 'use strict' -const { describe, it } = require('mocha') +const { describe, it } = require('node:test') const assert = require('assert') const path = require('path') const findNodeDirectory = require('../lib/find-node-directory') diff --git a/test/test-find-python.js b/tests/test-find-python.js similarity index 99% rename from test/test-find-python.js rename to tests/test-find-python.js index dc7192809a..15fb44c129 100644 --- a/test/test-find-python.js +++ b/tests/test-find-python.js @@ -2,7 +2,7 @@ delete process.env.PYTHON -const { describe, it, after } = require('mocha') +const { describe, it, after } = require('node:test') const assert = require('assert') const PythonFinder = require('../lib/find-python') const { execFile } = require('../lib/util') diff --git a/test/test-find-visualstudio.js b/tests/test-find-visualstudio.js similarity index 99% rename from test/test-find-visualstudio.js rename to tests/test-find-visualstudio.js index e53b6678ed..aac8a034c2 100644 --- a/test/test-find-visualstudio.js +++ b/tests/test-find-visualstudio.js @@ -1,6 +1,6 @@ 'use strict' -const { describe, it } = require('mocha') +const { describe, it, before } = require('node:test') const assert = require('assert') const fs = require('fs') const path = require('path') @@ -22,7 +22,7 @@ class TestVisualStudioFinder extends VisualStudioFinder { } describe('find-visualstudio', function () { - this.beforeAll(function () { + before(function () { // Condition to skip the test suite if (process.env.SystemRoot === undefined) { process.env.SystemRoot = '/' diff --git a/test/test-install.js b/tests/test-install.js similarity index 93% rename from test/test-install.js rename to tests/test-install.js index 3343545ba6..2d7a9785e5 100644 --- a/test/test-install.js +++ b/tests/test-install.js @@ -1,6 +1,6 @@ 'use strict' -const { describe, it, afterEach, beforeEach } = require('mocha') +const { describe, it, afterEach, beforeEach } = require('node:test') const { rm, mkdtemp } = require('fs/promises') const { createWriteStream } = require('fs') const assert = require('assert') @@ -73,9 +73,8 @@ describe('install', function () { return it.skip('Skipping parallel installs test due to test environment configuration') } - return it(name, async function () { - this.timeout(platformTimeout(2, { win32: 20 })) - await fn.call(this) + return it(name, { timeout: platformTimeout(2, { win32: 20 }) }, async function () { + await fn() const expectedDir = path.join(prog.devDir, process.version.replace(/^v/, '')) await rm(expectedDir, { recursive: true, force: true, maxRetries: 3 }) await Promise.all(new Array(10).fill(0).map(async (_, i) => { diff --git a/test/test-options.js b/tests/test-options.js similarity index 96% rename from test/test-options.js rename to tests/test-options.js index 8d281db8e8..1ed185b7a5 100644 --- a/test/test-options.js +++ b/tests/test-options.js @@ -1,6 +1,6 @@ 'use strict' -const { describe, it } = require('mocha') +const { describe, it } = require('node:test') const assert = require('assert') const gyp = require('../lib/node-gyp') diff --git a/test/test-process-release.js b/tests/test-process-release.js similarity index 99% rename from test/test-process-release.js rename to tests/test-process-release.js index 31a87be9e9..74ce2bfd0d 100644 --- a/test/test-process-release.js +++ b/tests/test-process-release.js @@ -1,6 +1,6 @@ 'use strict' -const { describe, it } = require('mocha') +const { describe, it } = require('node:test') const assert = require('assert') const processRelease = require('../lib/process-release') diff --git a/test/test-windows-make.js b/tests/test-windows-make.js similarity index 93% rename from test/test-windows-make.js rename to tests/test-windows-make.js index edd9d36412..d24fa09d25 100644 --- a/test/test-windows-make.js +++ b/tests/test-windows-make.js @@ -1,6 +1,6 @@ 'use strict' -const { describe, it } = require('mocha') +const { describe, it } = require('node:test') const assert = require('assert') const path = require('path') const gracefulFs = require('graceful-fs') @@ -78,20 +78,19 @@ function quote (path) { } describe('windows-cross-compile', function () { - it('build simple node-api addon', async function () { + it('build simple node-api addon', { timeout: platformTimeout(1, { win32: 5 }) }, async function (t) { if (process.platform !== 'win32') { - return this.skip('This test is only for Windows') + return t.skip('This test is only for Windows') } const env = getEnv('wasm') if (!gracefulFs.existsSync(env.CC_target)) { - return this.skip('CC_target does not exist') + return t.skip('CC_target does not exist') } // handle bash whitespace env.AR_target = quote(env.AR_target) env.CC_target = quote(env.CC_target) env.CXX_target = quote(env.CXX_target) - this.timeout(platformTimeout(1, { win32: 5 })) const cmd = [ nodeGyp,