Skip to content

Commit

Permalink
test: improve overall test coverage (#287)
Browse files Browse the repository at this point in the history
* test: improve overall test coverage

* style: consistent descriptions in freezeable tests

* test: add more unit tests

* test: add more unit tests

* test: complete test coverage for utils

* refactor: do not rely on global mocha functions

* test: add unit test for jsonapi, serializer, and more

* test: add unit tests for Router and Config

* test: start adding fs unit tests

* test: add unit tests for loader

* add unit test for fs#exists

* test: add unit test for fs#rmrf

* test: add unit tests for Logger

* test: add initial Route unit tests

* test: add unit tests for route utils

* test: add unit test for filter-param

* fix: get tests passing on windows

* fix: ensure tmp dir exists on appveyor builds

* test: get tests to pass after merge

* test: use social-network as test-app

* fix: get unit tests passing and remove integration tests for now

* test: add unit test for route parameters

* refactor: change test-app name back to test-app

* test: add unit test for route parameter groups

* test: add unit test for route action

* test: start unit test for controller

* test: complete unit test for controller

* fix: use bcryptjs instead of bcrypt-as-promised in test-app

* test: add unit test for database validations

* fix: use relative paths in test-app until rollup aliases are fixed

* fix: use relative file path for windows in test-app

* fix: replace remaining aliased file paths in test-app

* fix: create root tmp dir in appveyor before running tests

* test: increase mocha timeout

* test: add unit tests for server/request and server/response

* test: use local timeout in root before hook

* test: add unit tests for server/responder and server

* refactor: run tests without building

* test: add unit tests to fs

- adds sinon as dev-dep for mocking and spying native node fs modules
- refactor fs test setup and cleanup utils into shared modules
- adds test coverage for lux fs delegation and promise-wrapping

* test: add unit tests for database and static methods of database/model

* test: add unit tests in model for #save() and #update()

* test: add remaining unit test for model instance methods

* test: improve #save() unit test for model

* test: add unit tests for model hooks

* test: add unit test for migration

* test: add unit test for static methods of database/query

* test: normalize test naming conventions

* test: improve unit test for .from() in database/query

* test: add codecov integration

* test: begin adding unit test for database/query instance methods

* test: add unit test for logger #line()

* test: do not include custom errors in test coverage

* test: add unit tests for query instance methods and properly extend Promise

* fix: use valid integer to prevent postgres errors in controller test

* fix: do not user deep equal for query #include() include unit tests
  • Loading branch information
zacharygolba authored Sep 20, 2016
1 parent cd1e822 commit 4d35d59
Show file tree
Hide file tree
Showing 183 changed files with 8,292 additions and 1,526 deletions.
14 changes: 8 additions & 6 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# compiled output
dist/*
coverage/
dist/
.nyc_output/

# tests
test/*
test/

# docs
docs/*
docs/

# dependencies
node_modules/*
node_modules/

# misc
decl/*
examples/*
decl/
examples/
*interfaces.js
18 changes: 9 additions & 9 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
"plugins": ["flowtype"],
"extends": "eslint:recommended",
"env": {
"es6": true,
"node": true
},
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"impliedStrict": true
}
},
"globals": {
"T": true,
"Map": true,
"Set": true,
"Class": true,
"Proxy": true,
"Promise": true,
"Reflect": true,
"WeakMap": true,
"WeakSet": true,
"Iterable": true,
"Generator": true,
"$PropertyType": true
},
"settings": {
Expand Down
12 changes: 7 additions & 5 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ decl
.*/lib/.*
.*/dist/.*
.*/docs/.*
.*/test/.*
.*/scripts/.*
.*/examples/.*
.*/node_modules/.*
.*/node_modules/bcryptjs/*

[options]
esproposal.class_instance_fields=enable
esproposal.class_static_fields=enable
suppress_comment=\\(.\\|\n\\)*\\$FlowIgnore

module.name_mapper='LUX_LOCAL' -> '<PROJECT_ROOT>'

unsafe.enable_getters_and_setters=true

esproposal.class_static_fields=enable
esproposal.class_instance_fields=enable
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
*.lcov
coverage/
dist/
docs/
.nyc_output/

# dependencies
node_modules/
Expand Down
13 changes: 8 additions & 5 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# dependencies
/node_modules
node_modules/

# misc
.git
*.DS_Store
/examples
*.lcov
.nyc_output/
coverage/
examples/

# docs
/docs
docs/

# logs
/log
log/
npm-debug.log

# tests
/test
test/
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,8 @@ before_script:
install:
- bash -e scripts/travis/install.sh

after_success:
- npm run test:codecov

notifications:
email: false
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Lux

[![Build Status](https://travis-ci.org/postlight/lux.svg?branch=master)](https://travis-ci.org/postlight/lux) [![Build status](https://ci.appveyor.com/api/projects/status/xxwunscfe3rsxdmr/branch/master?svg=true)](https://ci.appveyor.com/project/zacharygolba/lux/branch/master)
[![Build Status](https://travis-ci.org/postlight/lux.svg?branch=master)](https://travis-ci.org/postlight/lux) [![Build status](https://ci.appveyor.com/api/projects/status/xxwunscfe3rsxdmr/branch/master?svg=true)](https://ci.appveyor.com/project/zacharygolba/lux/branch/master) [![codecov](https://codecov.io/gh/postlight/lux/branch/master/graph/badge.svg)](https://codecov.io/gh/postlight/lux)
[![Dependency Status](https://david-dm.org/postlight/lux.svg)](https://david-dm.org/postlight/lux) [![npm version](https://badge.fury.io/js/lux-framework.svg)](https://badge.fury.io/js/lux-framework) [![Join the chat at https://gitter.im/postlight/lux](https://badges.gitter.im/postlight/lux.svg)](https://gitter.im/postlight/lux?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

A MVC style framework for building highly performant, large scale JSON APIs that anybody who knows the JavaScript language and its modern features will understand.
Expand Down
115 changes: 115 additions & 0 deletions decl/chai.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
//@flow
// src: github.com/flowtype/flow-typed/tree/master/definitions/npm/chai_v3.5.x
declare module 'chai' {
declare type ExpectChain<T> = {
and: ExpectChain<T>;
at: ExpectChain<T>;
be: ExpectChain<T>;
been: ExpectChain<T>;
have: ExpectChain<T>;
has: ExpectChain<T>;
is: ExpectChain<T>;
of: ExpectChain<T>;
same: ExpectChain<T>;
that: ExpectChain<T>;
to: ExpectChain<T>;
which: ExpectChain<T>;
with: ExpectChain<T>;

not: ExpectChain<T>;
deep: ExpectChain<T>;
any: ExpectChain<T>;
all: ExpectChain<T>;

a: ExpectChain<T> & (type: string) => ExpectChain<T>;
an: ExpectChain<T> & (type: string) => ExpectChain<T>;

frozen: ExpectChain<T> & (value: mixed) => ExpectChain<T>;
sealed: ExpectChain<T> & (value: mixed) => ExpectChain<T>;
include: ExpectChain<T> & (value: mixed) => ExpectChain<T>;
includes: ExpectChain<T> & (value: mixed) => ExpectChain<T>;
contain: ExpectChain<T> & (value: mixed) => ExpectChain<T>;
contains: ExpectChain<T> & (value: mixed) => ExpectChain<T>;

eql: (value: T) => ExpectChain<T>;
equal: (value: T) => ExpectChain<T>;
equals: (value: T) => ExpectChain<T>;

above: (value: T & number) => ExpectChain<T>;
least: (value: T & number) => ExpectChain<T>;
below: (value: T & number) => ExpectChain<T>;
most: (value: T & number) => ExpectChain<T>;
within: (start: T & number, finish: T & number) => ExpectChain<T>;

instanceof: (constructor: mixed) => ExpectChain<T>;

property: (
<P>(name: string, value?: P) => ExpectChain<P>
& (name: string) => ExpectChain<mixed>
);

length: ExpectChain<number>;
lengthOf: (value: number) => ExpectChain<T>;

match: (regex: RegExp) => ExpectChain<T>;
string: (string: string) => ExpectChain<T>;

key: (key: string) => ExpectChain<T>;

keys: (
key: string | Array<string>,
...keys: Array<string>
) => ExpectChain<T>;

throw: <E>(
err: Class<E> | Error | RegExp | string,
msg?: RegExp | string
) => ExpectChain<T>;

respondTo: (method: string) => ExpectChain<T>;
itself: ExpectChain<T>;

satisfy: (method: (value: T) => bool) => ExpectChain<T>;

closeTo: (expected: T & number, delta: number) => ExpectChain<T>;

members: (set: mixed) => ExpectChain<T>;
oneOf: (list: Array<T>) => ExpectChain<T>;

change: (obj: mixed, key: string) => ExpectChain<T>;
increase: (obj: mixed, key: string) => ExpectChain<T>;
decrease: (obj: mixed, key: string) => ExpectChain<T>;

// dirty-chai
ok: () => ExpectChain<T>;
true: () => ExpectChain<T>;
false: () => ExpectChain<T>;
null: () => ExpectChain<T>;
undefined: () => ExpectChain<T>;
exist: () => ExpectChain<T>;
empty: () => ExpectChain<T>;

// chai-immutable
size: (n: number) => ExpectChain<T>;

// sinon-chai
called: () => ExpectChain<T>;
callCount: (n: number) => ExpectChain<T>;
calledOnce: () => ExpectChain<T>;
calledBefore: (spy: mixed) => ExpectChain<T>;
calledAfter: (spy: mixed) => ExpectChain<T>;
calledWith: (...args: Array<mixed>) => ExpectChain<T>;
calledWithMatch: (...args: Array<mixed>) => ExpectChain<T>;
calledWithExactly: (...args: Array<mixed>) => ExpectChain<T>;
};

declare function expect<T>(actual: T): ExpectChain<T>;

declare function use(plugin: (chai: Object, utils: Object) => void): void;

declare var config: {
includeStack: boolean;
showDiff: boolean;
truncateThreshold: boolean;
};
}
26 changes: 26 additions & 0 deletions decl/mocha.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// @flow
// src: github.com/flowtype/flow-typed/tree/master/definitions/npm/mocha_v2.4.x
type $npm$mocha$testFunction = (done: () => void) => void | Promise<mixed>;

declare module 'mocha' {
declare var describe: {
(name: string, spec: () => void): void;
only(description: string, spec: () => void): void;
skip(description: string, spec: () => void): void;
timeout(ms: number): void;
};

declare var context: typeof describe;

declare var it: {
(name: string, spec?: $npm$mocha$testFunction): void;
only(description: string, spec: $npm$mocha$testFunction): void;
skip(description: string, spec: $npm$mocha$testFunction): void;
timeout(ms: number): void;
};

declare function before(method: $npm$mocha$testFunction): void;
declare function beforeEach(method: $npm$mocha$testFunction): void;
declare function after(method: $npm$mocha$testFunction): void;
declare function afterEach(method: $npm$mocha$testFunction): void;
}
56 changes: 56 additions & 0 deletions decl/node-fetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// @flow
declare module 'node-fetch' {
declare var exports: (url: string, options?: {
body?: any;
referrer?: string;
integrity?: string;

mode?:
| 'cors'
| 'no-cors'
| 'same-origin';

cache?:
| 'default'
| 'no-store'
| 'reload'
| 'no-cache'
| 'force-cache'
| 'only-if-cached';

method?:
| 'GET'
| 'HEAD'
| 'OPTIONS'
| 'PATCH'
| 'POST'
| 'DELETE';

headers?: {
[key: string]: string;
};

redirect?:
| 'follow'
| 'manual'
| 'error';

credentials?:
| 'omit'
| 'include'
| 'same-origin';

referrerPolicy?:
| 'no-referrer'
| 'no-referrer-when-downgrade'
| 'origin'
| 'origin-when-cross-origin'
| 'unsafe-url';
}) => Promise<{
status: number;
headers: Map<string, string>;

text(): Promise<string>;
json(): Promise<Object>;
}>;
}
11 changes: 11 additions & 0 deletions decl/sinon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @flow

declare module 'sinon' {
declare type Spy = {
calledWith: (...args: Array<any>) => boolean;
calledOnce: boolean;
restore: () => void;
reset: () => void;
};
declare function spy(module: Object, method: string): Spy;
}
49 changes: 34 additions & 15 deletions lib/babel-hook.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
'use strict';

// Require this module to use code in the /src dir prior to transpilation.
/***************************************************************************
* Require this module to use code in the /src dir prior to transpilation. *
***************************************************************************/

const plugins = (...items) => items.concat([
'syntax-flow',
'syntax-trailing-function-commas',
'transform-async-to-generator',
'transform-class-properties',
'transform-es2015-destructuring',
'transform-es2015-parameters',
'transform-es2015-spread',
'transform-exponentiation-operator',
'transform-flow-strip-types',
'transform-object-rest-spread',
'transform-es2015-modules-commonjs'
]);

require('babel-register')({
babelrc: false,

plugins: [
'syntax-flow',
'syntax-trailing-function-commas',
'transform-async-to-generator',
'transform-class-properties',
'transform-es2015-destructuring',
'transform-es2015-parameters',
'transform-es2015-spread',
'transform-exponentiation-operator',
'transform-flow-strip-types',
'transform-object-rest-spread',
'transform-es2015-modules-commonjs'
]
plugins: plugins(),
env: {
test: {
sourceMaps: 'inline',
plugins: plugins(['istanbul', {
include: [
'src/**/*.js'
],
exclude: [
'**/test',
'**/errors',
'**/interfaces.js'
]
}])
}
}
});
Loading

0 comments on commit 4d35d59

Please sign in to comment.