mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
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:
parent
0a87084150
commit
05aa3a1c70
9
test/addons/esm-export-default/binding.gyp
Normal file
9
test/addons/esm-export-default/binding.gyp
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
'targets': [
|
||||||
|
{
|
||||||
|
'target_name': 'binding-export-default',
|
||||||
|
'sources': [ 'binding-export-default.cc' ],
|
||||||
|
'includes': ['../common.gypi'],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -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');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -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' ],
|
||||||
24
test/addons/esm-export-primitive/test-esm.mjs
Normal file
24
test/addons/esm-export-primitive/test-esm.mjs
Normal 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');
|
||||||
|
}
|
||||||
|
}
|
||||||
6
test/addons/esm-export-primitive/test-require.js
Normal file
6
test/addons/esm-export-primitive/test-require.js
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
// Flags: --experimental-addon-modules
|
||||||
|
'use strict';
|
||||||
|
const common = require('../../common');
|
||||||
|
|
||||||
|
require('./test-esm.mjs')
|
||||||
|
.run().then(common.mustCall());
|
||||||
9
test/addons/hello-world-2/binding.gyp
Normal file
9
test/addons/hello-world-2/binding.gyp
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
'targets': [
|
||||||
|
{
|
||||||
|
'target_name': 'binding',
|
||||||
|
'sources': [ 'binding.cc' ],
|
||||||
|
'includes': ['../common.gypi'],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
5
test/addons/hello-world-2/test.js
Normal file
5
test/addons/hello-world-2/test.js
Normal 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');
|
||||||
|
|
@ -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'],
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user