Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions test/addons/hello-world-esm/binding.cc
Original file line number Diff line number Diff line change
@@ -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 changes: 9 additions & 0 deletions test/addons/hello-world-esm/binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
'targets': [
{
'target_name': 'binding',
'defines': [ 'V8_DEPRECATION_WARNINGS=1' ],
'sources': [ 'binding.cc' ]
}
]
}
20 changes: 20 additions & 0 deletions test/addons/hello-world-esm/test.js
Original file line number Diff line number Diff line change
@@ -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'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should maybe just do this (or, on POSIX, do symlinks) for all addons.


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');
Original file line number Diff line number Diff line change
@@ -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());