summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/addons/hello-world-esm/binding.cc13
-rw-r--r--test/addons/hello-world-esm/binding.gyp9
-rw-r--r--test/addons/hello-world-esm/test.js20
-rw-r--r--test/addons/hello-world-esm/test.mjs (renamed from test/es-module/test-esm-addon.mjs)3
4 files changed, 43 insertions, 2 deletions
diff --git a/test/addons/hello-world-esm/binding.cc b/test/addons/hello-world-esm/binding.cc
new file mode 100644
index 0000000000..944f563195
--- /dev/null
+++ b/test/addons/hello-world-esm/binding.cc
@@ -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)
diff --git a/test/addons/hello-world-esm/binding.gyp b/test/addons/hello-world-esm/binding.gyp
new file mode 100644
index 0000000000..7ede63d94a
--- /dev/null
+++ b/test/addons/hello-world-esm/binding.gyp
@@ -0,0 +1,9 @@
+{
+ 'targets': [
+ {
+ 'target_name': 'binding',
+ 'defines': [ 'V8_DEPRECATION_WARNINGS=1' ],
+ 'sources': [ 'binding.cc' ]
+ }
+ ]
+}
diff --git a/test/addons/hello-world-esm/test.js b/test/addons/hello-world-esm/test.js
new file mode 100644
index 0000000000..d0faf65540
--- /dev/null
+++ b/test/addons/hello-world-esm/test.js
@@ -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');
diff --git a/test/es-module/test-esm-addon.mjs b/test/addons/hello-world-esm/test.mjs
index 90ed9ffa50..6e481ab4f7 100644
--- a/test/es-module/test-esm-addon.mjs
+++ b/test/addons/hello-world-esm/test.mjs
@@ -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());