Skip to content

Commit e32a9fe

Browse files
committed
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. Fixes: #16155
1 parent c29e366 commit e32a9fe

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <node.h>
2+
#include <v8.h>
3+
4+
void Method(const v8::FunctionCallbackInfo<v8::Value>& args) {
5+
v8::Isolate* isolate = args.GetIsolate();
6+
args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, "world"));
7+
}
8+
9+
void init(v8::Local<v8::Object> exports) {
10+
NODE_SET_METHOD(exports, "hello", Method);
11+
}
12+
13+
NODE_MODULE(NODE_GYP_MODULE_NAME, init)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
'targets': [
3+
{
4+
'target_name': 'binding',
5+
'defines': [ 'V8_DEPRECATION_WARNINGS=1' ],
6+
'sources': [ 'binding.cc' ]
7+
}
8+
]
9+
}

test/addons/hello-world-esm/test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
const common = require('../../common');
3+
4+
const assert = require('assert');
5+
const { spawnSync } = require('child_process');
6+
const { copyFileSync } = require('fs');
7+
const { join } = require('path');
8+
9+
const buildDir = join(__dirname, 'build');
10+
11+
copyFileSync(join(buildDir, common.buildType, 'binding.node'),
12+
join(buildDir, 'binding.node'));
13+
14+
const result = spawnSync(process.execPath,
15+
['--experimental-modules', `${__dirname}/test.mjs`]);
16+
17+
assert.ifError(result.error);
18+
// TODO: Uncomment this once ESM is no longer experimental.
19+
// assert.strictEqual(result.stderr.toString().trim(), '');
20+
assert.strictEqual(result.stdout.toString().trim(), 'binding.hello() = world');
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
// Flags: --experimental-modules
21
/* eslint-disable required-modules */
32

43
import assert from 'assert';
5-
import binding from '../addons/hello-world/build/Release/binding.node';
4+
import binding from './build/binding.node';
65
assert.strictEqual(binding.hello(), 'world');
76
console.log('binding.hello() =', binding.hello());

0 commit comments

Comments
 (0)