Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saner test setup #27

Merged
merged 1 commit into from
Feb 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "."
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file required?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it in a subsequent PR as everything works without this file anyways -- #30

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point, TS was not detecting @types installed in test-lab's node_modules. If everything works for you without this file, then I am fine with removing it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be working for me (I'm getting autocompletion for both sinon/chai with it removed). Will add back later if we run into issues.

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