From 0332f6602bceb27268a6600f8593ef6f05898aad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Thu, 2 Feb 2017 13:08:38 +0100 Subject: [PATCH] Saner test setup - Upgrade lerna to the currently latest beta version (2.0.0-beta.35) - Get rid of global expect/sinon - Create a new package "@loopback/testlab" for shared test helpers - Configure top-level "npm test" --- lerna.json | 2 +- package.json | 8 +++----- packages/juggler/package.json | 1 + packages/juggler/test/black-box/smoke.ts | 2 ++ packages/juggler/test/white-box/smoke.ts | 2 ++ packages/loopback/package.json | 5 +++++ packages/loopback/test/black-box/bootstrapping.ts | 1 + packages/loopback/test/white-box/application.ts | 1 + packages/remoting/package.json | 1 + packages/remoting/test/black-box/smoke.ts | 2 ++ packages/remoting/test/white-box/smoke.ts | 2 ++ packages/testlab/README.md | 13 +++++++++++++ packages/testlab/package.json | 15 +++++++++++++++ test/globals.ts => packages/testlab/testlab.ts | 4 ++-- packages/testlab/tsconfig.json | 4 ++++ test/global-types.d.ts | 2 -- test/mocha.opts.black-box | 1 - test/mocha.opts.white-box | 1 - 18 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 packages/testlab/README.md create mode 100644 packages/testlab/package.json rename test/globals.ts => packages/testlab/testlab.ts (69%) create mode 100644 packages/testlab/tsconfig.json diff --git a/lerna.json b/lerna.json index bd4018a1fdc6..2f2c482594b7 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "lerna": "2.0.0-beta.32", + "lerna": "2.0.0-beta.35", "packages": [ "packages/*" ], diff --git a/package.json b/package.json index e532fc1edfe7..98e5965f1441 100644 --- a/package.json +++ b/package.json @@ -3,12 +3,9 @@ "devDependencies": { "@types/mocha": "^2.2.38", "@types/node": "^7.0.4", - "chai": "^3.5.0", - "dirty-chai": "^1.2.2", - "lerna": "^2.0.0-beta.32", + "lerna": "2.0.0-beta.35", "request": "^2.79.0", "request-promise": "^4.1.1", - "sinon": "^1.17.7", "ts-node": "^2.0.0", "tsconfig-paths": "^2.1.0", "typescript": "^2.1.5" @@ -19,6 +16,7 @@ "reflect-metadata": "^0.1.9" }, "scripts": { - "bootstrap": "lerna bootstrap" + "bootstrap": "lerna bootstrap", + "test": "lerna run test" } } diff --git a/packages/juggler/package.json b/packages/juggler/package.json index 5c86c1191319..85b3e63ac431 100644 --- a/packages/juggler/package.json +++ b/packages/juggler/package.json @@ -11,6 +11,7 @@ "author": "IBM", "license": "MIT", "devDependencies": { + "@loopback/testlab": "^4.0.0-alpha.1", "mocha": "^3.2.0", "mocha-gherkin": "^0.2.0" } diff --git a/packages/juggler/test/black-box/smoke.ts b/packages/juggler/test/black-box/smoke.ts index 7fd3f6d83f14..1ecd24dc173f 100644 --- a/packages/juggler/test/black-box/smoke.ts +++ b/packages/juggler/test/black-box/smoke.ts @@ -1,3 +1,5 @@ +import {expect} from '@loopback/testlab'; + describe('white-box smoke test', () => { it('passes', () => { expect(true).to.be.true(); diff --git a/packages/juggler/test/white-box/smoke.ts b/packages/juggler/test/white-box/smoke.ts index 33b3a107cdcc..59d694a612dd 100644 --- a/packages/juggler/test/white-box/smoke.ts +++ b/packages/juggler/test/white-box/smoke.ts @@ -1,3 +1,5 @@ +import {expect} from '@loopback/testlab'; + suite('white-box smoke test', () => { test('passes', () => { expect(true).to.be.true(); diff --git a/packages/loopback/package.json b/packages/loopback/package.json index e945d8684218..28aec5500e41 100644 --- a/packages/loopback/package.json +++ b/packages/loopback/package.json @@ -10,7 +10,12 @@ }, "author": "IBM", "license": "MIT", + "dependencies": { + "@loopback/remoting": "^4.0.0-alpha.1", + "@loopback/juggler": "^4.0.0-alpha.1" + }, "devDependencies": { + "@loopback/testlab": "^4.0.0-alpha.1", "mocha": "^3.2.0", "mocha-gherkin": "^0.2.0" } diff --git a/packages/loopback/test/black-box/bootstrapping.ts b/packages/loopback/test/black-box/bootstrapping.ts index affe80a9fa67..5b0fbfe724fa 100644 --- a/packages/loopback/test/black-box/bootstrapping.ts +++ b/packages/loopback/test/black-box/bootstrapping.ts @@ -1,3 +1,4 @@ +import {expect} from '@loopback/testlab'; import * as util from 'loopback/test/support/util'; Feature('Bootstrapping', diff --git a/packages/loopback/test/white-box/application.ts b/packages/loopback/test/white-box/application.ts index 42fefa2cb241..6e86da386823 100644 --- a/packages/loopback/test/white-box/application.ts +++ b/packages/loopback/test/white-box/application.ts @@ -1,4 +1,5 @@ import {Application, AppState} from 'loopback'; +import {expect} from '@loopback/testlab'; suite('Application', () => { suite('constructor(config?: AppConfig)', () => { diff --git a/packages/remoting/package.json b/packages/remoting/package.json index 191bbdf44983..de3db5072c5b 100644 --- a/packages/remoting/package.json +++ b/packages/remoting/package.json @@ -11,6 +11,7 @@ "author": "IBM", "license": "MIT", "devDependencies": { + "@loopback/testlab": "^4.0.0-alpha.1", "mocha": "^3.2.0", "mocha-gherkin": "^0.2.0" } diff --git a/packages/remoting/test/black-box/smoke.ts b/packages/remoting/test/black-box/smoke.ts index 63f4950e6df6..83d993cb3383 100644 --- a/packages/remoting/test/black-box/smoke.ts +++ b/packages/remoting/test/black-box/smoke.ts @@ -1,3 +1,5 @@ +import {expect} from '@loopback/testlab'; + describe('black-box smoke test', () => { it('passes', () => { expect(true).to.be.true(); diff --git a/packages/remoting/test/white-box/smoke.ts b/packages/remoting/test/white-box/smoke.ts index 33b3a107cdcc..59d694a612dd 100644 --- a/packages/remoting/test/white-box/smoke.ts +++ b/packages/remoting/test/white-box/smoke.ts @@ -1,3 +1,5 @@ +import {expect} from '@loopback/testlab'; + suite('white-box smoke test', () => { test('passes', () => { expect(true).to.be.true(); diff --git a/packages/testlab/README.md b/packages/testlab/README.md new file mode 100644 index 000000000000..1883ac372fbb --- /dev/null +++ b/packages/testlab/README.md @@ -0,0 +1,13 @@ +# LoopBack Test Lab + +A collection of test utilities we use to write LoopBack tests. + +## `expect` + +Chai's [BDD API](http://chaijs.com/api/bdd/) configured with +[dirty-chai](https://github.com/graingert/dirty-chai/blob/master/README.md), +allowing us to avoid dangerous [asserts on property access](https://github.com/moll/js-must#asserting-on-property-access) + +## `sinon` + +Spies, mocks and stubs. Learn more at [http://sinonjs.org/](http://sinonjs.org/). diff --git a/packages/testlab/package.json b/packages/testlab/package.json new file mode 100644 index 000000000000..befc2fc02bea --- /dev/null +++ b/packages/testlab/package.json @@ -0,0 +1,15 @@ +{ + "name": "@loopback/testlab", + "version": "4.0.0-alpha.1", + "description": "A collection of test utilities we use to write LoopBack tests.", + "main": "testlab", + "author": "IBM", + "license": "MIT", + "dependencies": { + "@types/chai": "^3.4.34", + "@types/sinon": "^1.16.34", + "chai": "^3.5.0", + "dirty-chai": "^1.2.2", + "sinon": "^1.17.7" + } +} diff --git a/test/globals.ts b/packages/testlab/testlab.ts similarity index 69% rename from test/globals.ts rename to packages/testlab/testlab.ts index c1ec68cd21cf..535198bc1df2 100644 --- a/test/globals.ts +++ b/packages/testlab/testlab.ts @@ -4,5 +4,5 @@ import sinon = require('sinon'); chai.use(dirtyChai); -global['expect'] = chai.expect; -global['sinon'] = sinon; \ No newline at end of file +export const expect = chai.expect; +export {sinon}; \ No newline at end of file diff --git a/packages/testlab/tsconfig.json b/packages/testlab/tsconfig.json new file mode 100644 index 000000000000..4369662a423d --- /dev/null +++ b/packages/testlab/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../tsconfig.json", + "baseUrl": "." +} \ No newline at end of file diff --git a/test/global-types.d.ts b/test/global-types.d.ts index 7aff548ed53f..9f34505566aa 100644 --- a/test/global-types.d.ts +++ b/test/global-types.d.ts @@ -1,8 +1,6 @@ declare var And : any; -declare var expect : Function; declare var Feature : Function; declare var Given : any; declare var Scenario : any; -declare var sinon : any; declare var Then : any; declare var When : any; \ No newline at end of file diff --git a/test/mocha.opts.black-box b/test/mocha.opts.black-box index 4db7b03fa9e7..ec5e22a8ddd7 100644 --- a/test/mocha.opts.black-box +++ b/test/mocha.opts.black-box @@ -1,5 +1,4 @@ --require ../../test/ts-node.js --compilers ts:tsconfig-paths/register ---require ../../test/globals.ts --ui mocha-gherkin --reporter mocha-gherkin/build/spec test/black-box/**/*.ts diff --git a/test/mocha.opts.white-box b/test/mocha.opts.white-box index e4e0e75a2925..d857598404e6 100644 --- a/test/mocha.opts.white-box +++ b/test/mocha.opts.white-box @@ -1,5 +1,4 @@ --require ../../test/ts-node.js --compilers ts:tsconfig-paths/register ---require ../../test/globals.ts --ui tdd test/white-box/**/*.ts