From 1a98077794d484ebdde3e3721c6044a7e5b0262c Mon Sep 17 00:00:00 2001 From: Yavor Georgiev Date: Wed, 10 Aug 2016 15:47:55 +0200 Subject: [PATCH 1/3] Add tests to ensure realm-js is usable inside mocha and ava tests --- scripts/test.sh | 12 ++++++++++++ tests/test-runners/ava/package.json | 8 ++++++++ tests/test-runners/ava/test.js | 7 +++++++ tests/test-runners/mocha/package.json | 8 ++++++++ tests/test-runners/mocha/test.js | 9 +++++++++ tests/test-runners/node_modules/realm | 1 + 6 files changed, 45 insertions(+) create mode 100644 tests/test-runners/ava/package.json create mode 100644 tests/test-runners/ava/test.js create mode 100644 tests/test-runners/mocha/package.json create mode 100644 tests/test-runners/mocha/test.js create mode 120000 tests/test-runners/node_modules/realm diff --git a/scripts/test.sh b/scripts/test.sh index a6c7cc36..4c0c9c5e 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; 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/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 From fb7911e3fa594dd45645b360be59984614343a6f Mon Sep 17 00:00:00 2001 From: Yavor Georgiev Date: Wed, 10 Aug 2016 15:50:37 +0200 Subject: [PATCH 2/3] =?UTF-8?q?add=20support=20for=20the=20jest=20runner?= =?UTF-8?q?=E2=80=99s=20node=20environment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/index.js | 2 +- scripts/test.sh | 2 +- tests/test-runners/jest/package.json | 15 +++++++++++++++ tests/test-runners/jest/test.js | 7 +++++++ 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 tests/test-runners/jest/package.json create mode 100644 tests/test-runners/jest/test.js 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 4c0c9c5e..1389653e 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -162,7 +162,7 @@ case "$TARGET" in scripts/download-core.sh node src/node/build-node.sh $CONFIGURATION - for runner in ava mocha; do + for runner in ava mocha jest; do pushd "$SRCROOT/tests/test-runners/$runner" npm install npm test 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'); + }); +}); From b352b7eaafb80914b6eb0bf56e26cd29d01ba571 Mon Sep 17 00:00:00 2001 From: Yavor Georgiev Date: Wed, 10 Aug 2016 16:10:33 +0200 Subject: [PATCH 3/3] Ignore the test runner tests in eslint --- .eslintignore | 2 ++ 1 file changed, 2 insertions(+) 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