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/symlinked-module/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> target) {
NODE_SET_METHOD(target, "hello", Method);
}

NODE_MODULE(binding, init);
8 changes: 8 additions & 0 deletions test/addons/symlinked-module/binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
'targets': [
{
'target_name': 'binding',
'sources': [ 'binding.cc' ]
}
]
}
9 changes: 9 additions & 0 deletions test/addons/symlinked-module/submodule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';
const common = require('../../common');
const path = require('path');
const assert = require('assert');

var destDir = path.resolve(common.tmpDir);
var mod = require(path.join(destDir, 'second', 'binding.node'));
assert(mod != null);
assert(mod.hello() == 'world');
32 changes: 32 additions & 0 deletions test/addons/symlinked-module/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';
const common = require('../../common');
const fs = require('fs');
const path = require('path');
const assert = require('assert');

common.refreshTmpDir();

var destDir = path.resolve(common.tmpDir);

var location = [path.join(destDir, 'first'), path.join(destDir, 'second')];
fs.mkdirSync(location[0]);
try {
fs.symlinkSync(location[0], location[1]);
} catch (EPERM) {
console.log('1..0 # Skipped: module identity test (no privs for symlinks)');
return;
}

const addonPath = path.join(__dirname, 'build', 'Release', 'binding.node');

var contents = fs.readFileSync(addonPath);
fs.writeFileSync(path.join(location[0], 'binding.node'), contents);
fs.writeFileSync(path.join(location[1], 'binding.node'), contents);

var primary = require(path.join(location[0], 'binding.node'));
assert(primary != null);
assert(primary.hello() == 'world');
var secondary = require(path.join(location[1], 'binding.node'));
assert(secondary != null);
assert(secondary.hello() == 'world');
var tertiary = require('./submodule');