Skip to content

Commit

Permalink
Saner test setup
Browse files Browse the repository at this point in the history
 - 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"
  • Loading branch information
bajtos committed Feb 2, 2017
1 parent 89794cc commit 0332f66
Show file tree
Hide file tree
Showing 18 changed files with 55 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lerna": "2.0.0-beta.32",
"lerna": "2.0.0-beta.35",
"packages": [
"packages/*"
],
Expand Down
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -19,6 +16,7 @@
"reflect-metadata": "^0.1.9"
},
"scripts": {
"bootstrap": "lerna bootstrap"
"bootstrap": "lerna bootstrap",
"test": "lerna run test"
}
}
1 change: 1 addition & 0 deletions packages/juggler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
2 changes: 2 additions & 0 deletions packages/juggler/test/black-box/smoke.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {expect} from '@loopback/testlab';

describe('white-box smoke test', () => {
it('passes', () => {
expect(true).to.be.true();
Expand Down
2 changes: 2 additions & 0 deletions packages/juggler/test/white-box/smoke.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {expect} from '@loopback/testlab';

suite('white-box smoke test', () => {
test('passes', () => {
expect(true).to.be.true();
Expand Down
5 changes: 5 additions & 0 deletions packages/loopback/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
1 change: 1 addition & 0 deletions packages/loopback/test/black-box/bootstrapping.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect} from '@loopback/testlab';
import * as util from 'loopback/test/support/util';

Feature('Bootstrapping',
Expand Down
1 change: 1 addition & 0 deletions packages/loopback/test/white-box/application.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Application, AppState} from 'loopback';
import {expect} from '@loopback/testlab';

suite('Application', () => {
suite('constructor(config?: AppConfig)', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/remoting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
2 changes: 2 additions & 0 deletions packages/remoting/test/black-box/smoke.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {expect} from '@loopback/testlab';

describe('black-box smoke test', () => {
it('passes', () => {
expect(true).to.be.true();
Expand Down
2 changes: 2 additions & 0 deletions packages/remoting/test/white-box/smoke.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {expect} from '@loopback/testlab';

suite('white-box smoke test', () => {
test('passes', () => {
expect(true).to.be.true();
Expand Down
13 changes: 13 additions & 0 deletions packages/testlab/README.md
Original file line number Diff line number Diff line change
@@ -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/).
15 changes: 15 additions & 0 deletions packages/testlab/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
4 changes: 2 additions & 2 deletions test/globals.ts → packages/testlab/testlab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import sinon = require('sinon');

chai.use(dirtyChai);

global['expect'] = chai.expect;
global['sinon'] = sinon;
export const expect = chai.expect;
export {sinon};
4 changes: 4 additions & 0 deletions packages/testlab/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../tsconfig.json",
"baseUrl": "."
}
2 changes: 0 additions & 2 deletions test/global-types.d.ts
Original file line number Diff line number Diff line change
@@ -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;
1 change: 0 additions & 1 deletion test/mocha.opts.black-box
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion test/mocha.opts.white-box
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
--require ../../test/ts-node.js
--compilers ts:tsconfig-paths/register
--require ../../test/globals.ts
--ui tdd
test/white-box/**/*.ts

0 comments on commit 0332f66

Please sign in to comment.