diff --git a/.eslintignore b/.eslintignore index ec9a0aae..43adc689 100644 --- a/.eslintignore +++ b/.eslintignore @@ -5,3 +5,5 @@ build/ node_modules/ vendor/ + +/tests/test-runners/ \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index 441e03f5..870bda94 100644 --- a/lib/index.js +++ b/lib/index.js @@ -29,7 +29,7 @@ if (typeof Realm != 'undefined') { // The userAgent will be defined when running in a browser (such as Chrome debugging mode). realmConstructor = require('./browser').default; // (exported as ES6 module) // eslint-disable-next-line -} else if (typeof process == 'object' && ('' + process) == '[object process]') { +} else if (typeof process == 'object' && (('' + process) == '[object process]' || typeof jest == 'object')) { // Prevent React Native packager from seeing this module. var bindings = 'bindings'; realmConstructor = require(bindings)('realm').Realm; diff --git a/scripts/test.sh b/scripts/test.sh index a6c7cc36..1389653e 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -157,6 +157,18 @@ case "$TARGET" in node "$SRCROOT/tests" ;; +"test-runners") + npm install + scripts/download-core.sh node + src/node/build-node.sh $CONFIGURATION + + for runner in ava mocha jest; do + pushd "$SRCROOT/tests/test-runners/$runner" + npm install + npm test + popd + done + ;; "object-store") pushd src/object-store cmake -DCMAKE_BUILD_TYPE=$CONFIGURATION . diff --git a/tests/test-runners/ava/package.json b/tests/test-runners/ava/package.json new file mode 100644 index 00000000..c4099996 --- /dev/null +++ b/tests/test-runners/ava/package.json @@ -0,0 +1,8 @@ +{ + "scripts": { + "test": "ava" + }, + "devDependencies": { + "ava": "^0.16.0" + } +} diff --git a/tests/test-runners/ava/test.js b/tests/test-runners/ava/test.js new file mode 100644 index 00000000..1829e6d3 --- /dev/null +++ b/tests/test-runners/ava/test.js @@ -0,0 +1,7 @@ +import test from 'ava'; + +test('can require Realm', t => { + var realm = require('realm'); + t.is('function', typeof realm); + t.is('Realm', realm.name); +}); \ No newline at end of file diff --git a/tests/test-runners/jest/package.json b/tests/test-runners/jest/package.json new file mode 100644 index 00000000..42391167 --- /dev/null +++ b/tests/test-runners/jest/package.json @@ -0,0 +1,15 @@ +{ + "scripts": { + "test": "jest" + }, + "devDependencies": { + "jest-cli": "^13.2.3" + }, + "jest": { + "testEnvironment": "node", + "unmockedModulePathPatterns": [ + "realm" + ], + "testRegex": "test.js" + } +} diff --git a/tests/test-runners/jest/test.js b/tests/test-runners/jest/test.js new file mode 100644 index 00000000..6b5d9043 --- /dev/null +++ b/tests/test-runners/jest/test.js @@ -0,0 +1,7 @@ +describe('Realm', function() { + it('should be requirable', function() { + var realm = require('realm'); + expect(typeof realm).toBe('function'); + expect(realm.name).toBe('Realm'); + }); +}); diff --git a/tests/test-runners/mocha/package.json b/tests/test-runners/mocha/package.json new file mode 100644 index 00000000..9c84aa0f --- /dev/null +++ b/tests/test-runners/mocha/package.json @@ -0,0 +1,8 @@ +{ + "scripts": { + "test": "mocha" + }, + "devDependencies": { + "mocha": "^3.0.2" + } +} diff --git a/tests/test-runners/mocha/test.js b/tests/test-runners/mocha/test.js new file mode 100644 index 00000000..7432c8db --- /dev/null +++ b/tests/test-runners/mocha/test.js @@ -0,0 +1,9 @@ +var assert = require('assert'); + +describe('Realm', function() { + it('should be requirable', function() { + var realm = require('realm'); + assert.equal(typeof realm, 'function'); + assert.equal(realm.name, 'Realm'); + }); +}); diff --git a/tests/test-runners/node_modules/realm b/tests/test-runners/node_modules/realm new file mode 120000 index 00000000..a8a4f8c2 --- /dev/null +++ b/tests/test-runners/node_modules/realm @@ -0,0 +1 @@ +../../.. \ No newline at end of file