-
Notifications
You must be signed in to change notification settings - Fork 465
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: added tests to check the build process
Refs: #766 PR-URL: #808 Reviewed-By: Michael Dawson <[email protected]>
- Loading branch information
Showing
9 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
/build | ||
/benchmark/build | ||
/benchmark/src | ||
/test/addon_build/addons |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict'; | ||
|
||
const { promisify } = require('util'); | ||
const exec = promisify(require('child_process').exec); | ||
const { copy, remove } = require('fs-extra'); | ||
const path = require('path'); | ||
const assert = require('assert') | ||
|
||
const ADDONS_FOLDER = path.join(__dirname, 'addons'); | ||
|
||
const addons = [ | ||
'echo addon', | ||
'echo-addon' | ||
] | ||
|
||
async function beforeAll(addons) { | ||
console.log(' >Preparing native addons to build') | ||
for (const addon of addons) { | ||
await remove(path.join(ADDONS_FOLDER, addon)); | ||
await copy(path.join(__dirname, 'tpl'), path.join(ADDONS_FOLDER, addon)); | ||
} | ||
} | ||
|
||
async function test(addon) { | ||
console.log(` >Building addon: '${addon}'`); | ||
const { stderr, stdout } = await exec('npm install', { | ||
cwd: path.join(ADDONS_FOLDER, addon) | ||
}) | ||
console.log(` >Runting test for: '${addon}'`); | ||
// Disabled the checks on stderr and stdout because of this issuue on npm: | ||
// Stop using process.umask(): https://github.com/npm/cli/issues/1103 | ||
// We should enable the following checks again after the resolution of | ||
// the reported issue. | ||
// assert.strictEqual(stderr, ''); | ||
// assert.ok(stderr.length === 0); | ||
// assert.ok(stdout.length > 0); | ||
const binding = require(`${ADDONS_FOLDER}/${addon}`); | ||
assert.strictEqual(binding.except.echo('except'), 'except'); | ||
assert.strictEqual(binding.except.echo(101), 101); | ||
assert.strictEqual(binding.noexcept.echo('noexcept'), 'noexcept'); | ||
assert.strictEqual(binding.noexcept.echo(103), 103); | ||
} | ||
|
||
|
||
module.exports = (async function() { | ||
await beforeAll(addons); | ||
for (const addon of addons) { | ||
await test(addon); | ||
} | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <napi.h> | ||
|
||
Napi::Value Echo(const Napi::CallbackInfo& info) { | ||
Napi::Env env = info.Env(); | ||
if (info.Length() != 1) { | ||
Napi::TypeError::New(env, "Wrong number of arguments. One argument expected.") | ||
.ThrowAsJavaScriptException(); | ||
} | ||
return info[0].As<Napi::Value>(); | ||
} | ||
|
||
Napi::Object Init(Napi::Env env, Napi::Object exports) { | ||
exports.Set(Napi::String::New(env, "echo"), Napi::Function::New(env, Echo)); | ||
return exports; | ||
} | ||
|
||
NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
'target_defaults': { | ||
'include_dirs': [ | ||
"<!(node -p \"require('node-addon-api').include_dir\")" | ||
], | ||
'variables': { | ||
'NAPI_VERSION%': "<!(node -p \"process.versions.napi\")", | ||
'disable_deprecated': "<!(node -p \"process.env['npm_config_disable_deprecated']\")" | ||
}, | ||
'conditions': [ | ||
['NAPI_VERSION!=""', { 'defines': ['NAPI_VERSION=<@(NAPI_VERSION)'] } ], | ||
['disable_deprecated=="true"', { | ||
'defines': ['NODE_ADDON_API_DISABLE_DEPRECATED'] | ||
}], | ||
['OS=="mac"', { | ||
'cflags+': ['-fvisibility=hidden'], | ||
'xcode_settings': { | ||
'OTHER_CFLAGS': ['-fvisibility=hidden'] | ||
} | ||
}] | ||
], | ||
'sources': [ | ||
'addon.cc', | ||
], | ||
}, | ||
'targets': [ | ||
{ | ||
'target_name': 'addon', | ||
'defines': [ 'NAPI_CPP_EXCEPTIONS' ], | ||
'cflags!': [ '-fno-exceptions' ], | ||
'cflags_cc!': [ '-fno-exceptions' ], | ||
'msvs_settings': { | ||
'VCCLCompilerTool': { | ||
'ExceptionHandling': 1, | ||
'EnablePREfast': 'true', | ||
}, | ||
}, | ||
'xcode_settings': { | ||
'CLANG_CXX_LIBRARY': 'libc++', | ||
'MACOSX_DEPLOYMENT_TARGET': '10.7', | ||
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES', | ||
}, | ||
}, | ||
{ | ||
'target_name': 'addon_noexcept', | ||
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ], | ||
'cflags': [ '-fno-exceptions' ], | ||
'cflags_cc': [ '-fno-exceptions' ], | ||
'msvs_settings': { | ||
'VCCLCompilerTool': { | ||
'ExceptionHandling': 0, | ||
'EnablePREfast': 'true', | ||
}, | ||
}, | ||
'xcode_settings': { | ||
'CLANG_CXX_LIBRARY': 'libc++', | ||
'MACOSX_DEPLOYMENT_TARGET': '10.7', | ||
'GCC_ENABLE_CPP_EXCEPTIONS': 'NO', | ||
}, | ||
}, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict' | ||
|
||
const except = require('bindings')('addon') | ||
const noexcept = require('bindings')('addon_noexcept') | ||
|
||
module.exports = { | ||
except, | ||
noexcept | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "addon", | ||
"version": "0.0.0", | ||
"description": "Node.js addon", | ||
"private": true, | ||
"scripts": {}, | ||
"dependencies": { | ||
"node-addon-api": "file:../../../../" | ||
}, | ||
"gypfile": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters