mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
test: fix test-esm-addons
Move test-esm-addons to test/addons/hello-world-esm. Test should now work properly on CI machines where `addons` are not always built at the expected relative path from the es-modules tests. Test should now work in Debug builds. PR-URL: https://github.com/nodejs/node/pull/16174 Fixes: https://github.com/nodejs/node/issues/16155 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
This commit is contained in:
committed by
Michaël Zasso
parent
d09e489ec9
commit
68bfde9fb9
13
test/addons/hello-world-esm/binding.cc
Normal file
13
test/addons/hello-world-esm/binding.cc
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <node.h>
|
||||
#include <v8.h>
|
||||
|
||||
void Method(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, "world"));
|
||||
}
|
||||
|
||||
void init(v8::Local<v8::Object> exports) {
|
||||
NODE_SET_METHOD(exports, "hello", Method);
|
||||
}
|
||||
|
||||
NODE_MODULE(NODE_GYP_MODULE_NAME, init)
|
||||
9
test/addons/hello-world-esm/binding.gyp
Normal file
9
test/addons/hello-world-esm/binding.gyp
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
'targets': [
|
||||
{
|
||||
'target_name': 'binding',
|
||||
'defines': [ 'V8_DEPRECATION_WARNINGS=1' ],
|
||||
'sources': [ 'binding.cc' ]
|
||||
}
|
||||
]
|
||||
}
|
||||
20
test/addons/hello-world-esm/test.js
Normal file
20
test/addons/hello-world-esm/test.js
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
const common = require('../../common');
|
||||
|
||||
const assert = require('assert');
|
||||
const { spawnSync } = require('child_process');
|
||||
const { copyFileSync } = require('fs');
|
||||
const { join } = require('path');
|
||||
|
||||
const buildDir = join(__dirname, 'build');
|
||||
|
||||
copyFileSync(join(buildDir, common.buildType, 'binding.node'),
|
||||
join(buildDir, 'binding.node'));
|
||||
|
||||
const result = spawnSync(process.execPath,
|
||||
['--experimental-modules', `${__dirname}/test.mjs`]);
|
||||
|
||||
assert.ifError(result.error);
|
||||
// TODO: Uncomment this once ESM is no longer experimental.
|
||||
// assert.strictEqual(result.stderr.toString().trim(), '');
|
||||
assert.strictEqual(result.stdout.toString().trim(), 'binding.hello() = world');
|
||||
@@ -1,7 +1,6 @@
|
||||
// Flags: --experimental-modules
|
||||
/* eslint-disable required-modules */
|
||||
|
||||
import assert from 'assert';
|
||||
import binding from '../addons/hello-world/build/Release/binding.node';
|
||||
import binding from './build/binding.node';
|
||||
assert.strictEqual(binding.hello(), 'world');
|
||||
console.log('binding.hello() =', binding.hello());
|
||||
Reference in New Issue
Block a user