From d23d60f2726e2cc845d60061ac5711e1e2973955 Mon Sep 17 00:00:00 2001 From: blagoev Date: Wed, 22 Mar 2017 14:01:09 +0200 Subject: [PATCH] refactor test.sh to use npm commands fixed license-check npm command added test-runners npm command --- package.json | 10 ++++++++-- scripts/test.sh | 27 +++------------------------ tests/test-runners/ava/test.js | 2 +- tests/test-runners/jest/test.js | 2 +- tests/test-runners/mocha/test.js | 2 +- 5 files changed, 14 insertions(+), 29 deletions(-) diff --git a/package.json b/package.json index 2d51325a..36a2c9cf 100644 --- a/package.json +++ b/package.json @@ -53,11 +53,17 @@ "install": "node-pre-gyp install --fallback-to-build", "prepublish": "node scripts/prepublish.js", "eslint": "npm install && npm run lint .", - "license-check": "license-checker --exclude \"MIT,ISC,BSD,Apache-2.0,BSD-2-Clause,BSD-3-Clause,WTFPL,Unlicense,(MIT AND CC-BY-3.0)\" | node scripts/handle-license-check.js", + "license-check": "npm install && license-checker --exclude \"MIT,ISC,BSD,Apache-2.0,BSD-2-Clause,BSD-3-Clause,WTFPL,Unlicense,(MIT AND CC-BY-3.0)\" | node scripts/handle-license-check.js", "jsdoc:clean": "rimraf ./docs/output", "jsdoc": "npm install && npm run jsdoc:clean && jsdoc -c docs/conf.json", "node-tests": "npm install --build-from-source && cd tests && npm install && npm run test-nosync && cd ..", - "node-nosync-tests": "npm install --build-from-source && cd tests && npm install && npm run test-nosync && cd .." + "node-nosync-tests": "npm install --build-from-source && cd tests && npm install && npm run test-nosync && cd ..", + "test-runner:ava" :"cd tests/test-runners/ava && npm install && npm test", + "test-runner:mocha" :"cd tests/test-runners/mocha && npm install && npm test", + "test-runner:jest" :"cd tests/test-runners/jest && npm install && npm test", + "test-runners" : "npm run test-runner:ava && npm run test-runner:mocha && npm run test-runner:jest", + "isMac" : "node -p \"if (process.platform == 'darwin') { process.exit(0); } else { process.exit(-1); }\"", + "testMac" : "npm run isMac -s && echo this is mac || echo . " }, "dependencies": { "extract-zip": "^1.6.0", diff --git a/scripts/test.sh b/scripts/test.sh index 4becaf74..bafaaf6a 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -244,9 +244,7 @@ rm -rf ~/.yarn-cache/npm-realm-* case "$TARGET" in "eslint") - [[ $CONFIGURATION == 'Debug' ]] && exit 0 - npm install - npm run lint . + npm run eslint ;; "eslint-ci") [[ $CONFIGURATION == 'Debug' ]] && exit 0 @@ -254,19 +252,10 @@ case "$TARGET" in ./node_modules/.bin/eslint -f checkstyle . > eslint.xml || true ;; "license-check") - [[ $CONFIGURATION == 'Debug' ]] && exit 0 - licenses=$(node_modules/.bin/license-checker --exclude "$ACCEPTED_LICENSES"); - if [[ $licenses ]]; then - echo "Unknown license detected in dependency:" - node_modules/.bin/license-checker --exclude "$ACCEPTED_LICENSES" - exit 1 - else - echo "All licenses are accepted" - fi + npm run license-check ;; "jsdoc") [[ $CONFIGURATION == 'Debug' ]] && exit 0 - npm install npm run jsdoc ;; "realmjs") @@ -378,18 +367,8 @@ case "$TARGET" in ;; "test-runners") # Create a fake realm module that points to the source root so that test-runner tests can require('realm') - rm -rf "$SRCROOT/tests/test-runners/node_modules/realm" - mkdir -p "$SRCROOT/tests/test-runners/node_modules" - ln -s "../../.." "$SRCROOT/tests/test-runners/node_modules/realm" - npm install --build-from-source - - for runner in ava mocha jest; do - pushd "$SRCROOT/tests/test-runners/$runner" - npm install - npm test - popd - done + npm run test-runners ;; "object-store") pushd src/object-store diff --git a/tests/test-runners/ava/test.js b/tests/test-runners/ava/test.js index 1829e6d3..cd2a9a24 100644 --- a/tests/test-runners/ava/test.js +++ b/tests/test-runners/ava/test.js @@ -1,7 +1,7 @@ import test from 'ava'; test('can require Realm', t => { - var realm = require('realm'); + var realm = require('../../../../realm-js'); t.is('function', typeof realm); t.is('Realm', realm.name); }); \ No newline at end of file diff --git a/tests/test-runners/jest/test.js b/tests/test-runners/jest/test.js index 6b5d9043..2bd0b1d2 100644 --- a/tests/test-runners/jest/test.js +++ b/tests/test-runners/jest/test.js @@ -1,6 +1,6 @@ describe('Realm', function() { it('should be requirable', function() { - var realm = require('realm'); + var realm = require('../../../../realm-js'); expect(typeof realm).toBe('function'); expect(realm.name).toBe('Realm'); }); diff --git a/tests/test-runners/mocha/test.js b/tests/test-runners/mocha/test.js index 7432c8db..51abb15a 100644 --- a/tests/test-runners/mocha/test.js +++ b/tests/test-runners/mocha/test.js @@ -2,7 +2,7 @@ var assert = require('assert'); describe('Realm', function() { it('should be requirable', function() { - var realm = require('realm'); + var realm = require('../../../../realm-js'); assert.equal(typeof realm, 'function'); assert.equal(realm.name, 'Realm'); });