From 981595c316d254f359786f659dba004244cf7cd5 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 12 Oct 2017 22:02:59 -0700 Subject: [PATCH] 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 Reviewed-By: Daniel Bevenius Reviewed-By: Refael Ackermann --- test/addons/hello-world-esm/binding.cc | 13 ++++++++++++ test/addons/hello-world-esm/binding.gyp | 9 +++++++++ test/addons/hello-world-esm/test.js | 20 +++++++++++++++++++ .../hello-world-esm/test.mjs} | 3 +-- 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 test/addons/hello-world-esm/binding.cc create mode 100644 test/addons/hello-world-esm/binding.gyp create mode 100644 test/addons/hello-world-esm/test.js rename test/{es-module/test-esm-addon.mjs => addons/hello-world-esm/test.mjs} (61%) 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 +#include + +void Method(const v8::FunctionCallbackInfo& args) { + v8::Isolate* isolate = args.GetIsolate(); + args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, "world")); +} + +void init(v8::Local 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 similarity index 61% rename from test/es-module/test-esm-addon.mjs rename to 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());