Skip to content

Commit a9c08d1

Browse files
committed
Add simple test binding
1 parent 04b3abd commit a9c08d1

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

test/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build/
2+
src/

test/binding.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "napi.h"
2+
3+
using namespace Napi;
4+
5+
Value Test1(const CallbackInfo& info) {
6+
auto env = info.Env();
7+
Object obj = Object::New(env);
8+
9+
obj["foo"] = String::New(env, "bar");
10+
11+
return obj;
12+
}
13+
14+
void Init(Env env, Object exports, Object module) {
15+
exports.Set("test1", Function::New(env, Test1));
16+
}
17+
18+
NODE_API_MODULE(addon, Init)

test/binding.gyp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
'targets': [
3+
{
4+
'target_name': 'binding',
5+
'sources': [ 'binding.cc' ],
6+
'include_dirs': ['<!(node -p \'require("../").include\')'],
7+
'dependencies': ['<!(node -p \'require("../").gyp\')'],
8+
'cflags!': [ '-fno-exceptions' ],
9+
'cflags_cc!': [ '-fno-exceptions' ],
10+
'xcode_settings': { 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES' }
11+
}
12+
]
13+
}

test/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
const binding = require('./build/Release/binding.node');
3+
const assert = require('assert');
4+
5+
assert.deepStrictEqual(binding.test1(), { "foo": "bar" });

0 commit comments

Comments
 (0)