Add test for native modules.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 1 Aug 2013 07:40:54 +0000 (15:40 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 1 Aug 2013 07:40:54 +0000 (15:40 +0800)
package.json
spec/fixtures/module/int64_native.js [new file with mode: 0644]
spec/modules/native.coffee [new file with mode: 0644]

index 097ee5c..95f28a8 100644 (file)
@@ -7,7 +7,8 @@
 
     "mocha": "*",
     "walkdir": "*",
-    "unzip": "*"
+    "unzip": "*",
+    "int64-native": "*"
   },
 
   "private": true,
diff --git a/spec/fixtures/module/int64_native.js b/spec/fixtures/module/int64_native.js
new file mode 100644 (file)
index 0000000..bcc08d2
--- /dev/null
@@ -0,0 +1,6 @@
+process.on('uncaughtException', function(err) {
+  process.send(err.message);
+});
+
+require('int64-native');
+process.send('ok');
diff --git a/spec/modules/native.coffee b/spec/modules/native.coffee
new file mode 100644 (file)
index 0000000..ab04f73
--- /dev/null
@@ -0,0 +1,24 @@
+assert = require 'assert'
+path = require 'path'
+
+fixtures = path.resolve __dirname, '..', 'fixtures'
+
+describe 'modules', ->
+  describe 'native module', ->
+    it 'can be required in renderer', ->
+      Int64 = require 'int64-native'
+      x = new Int64()
+      y = new Int64(42)
+      z = new Int64(0xfedcba98, 0x76543210)
+      w = new Int64('fedcba9876543210')
+      assert.equal x.toString(), '0000000000000000'
+      assert.equal y.toString(), '000000000000002a'
+      assert.equal z.toString(), 'fedcba9876543210'
+      assert.equal w.toString(), 'fedcba9876543210'
+
+    it 'can be required in node binary', (done) ->
+      int64_native = path.join fixtures, 'module', 'int64_native.js'
+      child = require('child_process').fork int64_native
+      child.on 'message', (msg) ->
+        assert.equal msg, 'ok'
+        done()