test,win: split addon tests

PR-URL: https://github.com/nodejs/node/pull/59805
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Richard Lau <richard.lau@ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
StefanStojanovic 2025-10-03 10:19:59 +02:00 committed by Michaël Zasso
parent 0a87084150
commit 05aa3a1c70
No known key found for this signature in database
GPG Key ID: 770F7A9A5AE15600
13 changed files with 53 additions and 23 deletions

View File

@ -0,0 +1,9 @@
{
'targets': [
{
'target_name': 'binding-export-default',
'sources': [ 'binding-export-default.cc' ],
'includes': ['../common.gypi'],
},
]
}

View File

@ -24,14 +24,4 @@ export async function run() {
assert.strictEqual(ns.default, ns['module.exports']); assert.strictEqual(ns.default, ns['module.exports']);
assert.strictEqual(ns.default.default(), 'hello world'); assert.strictEqual(ns.default.default(), 'hello world');
} }
// binding-export-primitive.node
{
const bindingPath = require.resolve(`./build/${buildType}/binding-export-primitive.node`);
const ns = await import(pathToFileURL(bindingPath));
// As same as ESM-import-CJS, the default export is the value of `module.exports`.
assert.strictEqual(ns.default, ns['module.exports']);
assert.strictEqual(ns.default, 'hello world');
}
} }

View File

@ -1,10 +1,5 @@
{ {
'targets': [ 'targets': [
{
'target_name': 'binding-export-default',
'sources': [ 'binding-export-default.cc' ],
'includes': ['../common.gypi'],
},
{ {
'target_name': 'binding-export-primitive', 'target_name': 'binding-export-primitive',
'sources': [ 'binding-export-primitive.cc' ], 'sources': [ 'binding-export-primitive.cc' ],

View File

@ -0,0 +1,24 @@
/**
* This file is supposed to be loaded by `test-import.js` and `test-require.js`
* to verify that `import('*.node')` is working properly either been loaded with
* the ESM loader or the CJS loader.
*/
import { buildType } from '../../common/index.mjs';
import assert from 'node:assert';
import { createRequire } from 'node:module';
import { pathToFileURL } from 'node:url';
const require = createRequire(import.meta.url);
export async function run() {
// binding-export-primitive.node
{
const bindingPath = require.resolve(`./build/${buildType}/binding-export-primitive.node`);
const ns = await import(pathToFileURL(bindingPath));
// As same as ESM-import-CJS, the default export is the value of `module.exports`.
assert.strictEqual(ns.default, ns['module.exports']);
assert.strictEqual(ns.default, 'hello world');
}
}

View File

@ -0,0 +1,6 @@
// Flags: --experimental-addon-modules
'use strict';
const common = require('../../common');
require('./test-esm.mjs')
.run().then(common.mustCall());

View File

@ -0,0 +1,9 @@
{
'targets': [
{
'target_name': 'binding',
'sources': [ 'binding.cc' ],
'includes': ['../common.gypi'],
},
]
}

View File

@ -0,0 +1,5 @@
'use strict';
const common = require('../../common');
const assert = require('assert');
const binding = require(require.resolve(`./build/${common.buildType}/binding`));
assert.strictEqual(binding.hello(), 'world');

View File

@ -5,10 +5,5 @@
'sources': [ 'binding.cc' ], 'sources': [ 'binding.cc' ],
'includes': ['../common.gypi'], 'includes': ['../common.gypi'],
}, },
{
'target_name': 'binding2',
'sources': [ 'binding2.cc' ],
'includes': ['../common.gypi'],
}
] ]
} }

View File

@ -6,9 +6,6 @@ const binding = require(bindingPath);
assert.strictEqual(binding.hello(), 'world'); assert.strictEqual(binding.hello(), 'world');
console.log('binding.hello() =', binding.hello()); console.log('binding.hello() =', binding.hello());
const binding2 = require(require.resolve(`./build/${common.buildType}/binding2`));
assert.strictEqual(binding2.hello(), 'world');
// Test multiple loading of the same module. // Test multiple loading of the same module.
delete require.cache[bindingPath]; delete require.cache[bindingPath];
const rebinding = require(bindingPath); const rebinding = require(bindingPath);