From fb7911e3fa594dd45645b360be59984614343a6f Mon Sep 17 00:00:00 2001 From: Yavor Georgiev Date: Wed, 10 Aug 2016 15:50:37 +0200 Subject: [PATCH] =?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'); + }); +});