Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Improve Flow coverage #112

Merged
merged 4 commits into from
May 11, 2018
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
105 changes: 105 additions & 0 deletions flow-typed/tape-cup_v4.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/* eslint-disable */

declare type tape$TestOpts = {
skip: boolean,
timeout?: number,
} | {
skip?: boolean,
timeout: number,
};

declare type tape$TestCb = (t: tape$Context) => mixed;
declare type tape$TestFn = (a: string | tape$TestOpts | tape$TestCb, b?: tape$TestOpts | tape$TestCb, c?: tape$TestCb) => void;

declare interface tape$Context {
fail(msg?: string): void,
pass(msg?: string): void,

error(err: mixed, msg?: string): void,
ifError(err: mixed, msg?: string): void,
ifErr(err: mixed, msg?: string): void,
iferror(err: mixed, msg?: string): void,

ok(value: mixed, msg?: string): void,
true(value: mixed, msg?: string): void,
assert(value: mixed, msg?: string): void,

notOk(value: mixed, msg?: string): void,
false(value: mixed, msg?: string): void,
notok(value: mixed, msg?: string): void,

// equal + aliases
equal(actual: mixed, expected: mixed, msg?: string): void,
equals(actual: mixed, expected: mixed, msg?: string): void,
isEqual(actual: mixed, expected: mixed, msg?: string): void,
is(actual: mixed, expected: mixed, msg?: string): void,
strictEqual(actual: mixed, expected: mixed, msg?: string): void,
strictEquals(actual: mixed, expected: mixed, msg?: string): void,

// notEqual + aliases
notEqual(actual: mixed, expected: mixed, msg?: string): void,
notEquals(actual: mixed, expected: mixed, msg?: string): void,
notStrictEqual(actual: mixed, expected: mixed, msg?: string): void,
notStrictEquals(actual: mixed, expected: mixed, msg?: string): void,
isNotEqual(actual: mixed, expected: mixed, msg?: string): void,
isNot(actual: mixed, expected: mixed, msg?: string): void,
not(actual: mixed, expected: mixed, msg?: string): void,
doesNotEqual(actual: mixed, expected: mixed, msg?: string): void,
isInequal(actual: mixed, expected: mixed, msg?: string): void,

// deepEqual + aliases
deepEqual(actual: mixed, expected: mixed, msg?: string): void,
deepEquals(actual: mixed, expected: mixed, msg?: string): void,
isEquivalent(actual: mixed, expected: mixed, msg?: string): void,
same(actual: mixed, expected: mixed, msg?: string): void,

// notDeepEqual
notDeepEqual(actual: mixed, expected: mixed, msg?: string): void,
notEquivalent(actual: mixed, expected: mixed, msg?: string): void,
notDeeply(actual: mixed, expected: mixed, msg?: string): void,
notSame(actual: mixed, expected: mixed, msg?: string): void,
isNotDeepEqual(actual: mixed, expected: mixed, msg?: string): void,
isNotDeeply(actual: mixed, expected: mixed, msg?: string): void,
isNotEquivalent(actual: mixed, expected: mixed, msg?: string): void,
isInequivalent(actual: mixed, expected: mixed, msg?: string): void,

// deepLooseEqual
deepLooseEqual(actual: mixed, expected: mixed, msg?: string): void,
looseEqual(actual: mixed, expected: mixed, msg?: string): void,
looseEquals(actual: mixed, expected: mixed, msg?: string): void,

// notDeepLooseEqual
notDeepLooseEqual(actual: mixed, expected: mixed, msg?: string): void,
notLooseEqual(actual: mixed, expected: mixed, msg?: string): void,
notLooseEquals(actual: mixed, expected: mixed, msg?: string): void,

throws(fn: Function, expected?: RegExp | Function, msg?: string): void,
doesNotThrow(fn: Function, expected?: RegExp | Function, msg?: string): void,

timeoutAfter(ms: number): void,

skip(msg?: string): void,
plan(n: number): void,
onFinish(fn: Function): void,
end(): void,
comment(msg: string): void,
test: tape$TestFn,
}

declare module 'tape-cup' {
declare type TestHarness = Tape;
declare type StreamOpts = {
objectMode?: boolean,
};

declare type Tape = {
(a: string | tape$TestOpts | tape$TestCb, b?: tape$TestCb | tape$TestOpts, c?: tape$TestCb, ...rest: Array<void>): void,
test: tape$TestFn,
skip: (name: string, cb?: tape$TestCb) => void,
createHarness: () => TestHarness,
createStream: (opts?: StreamOpts) => stream$Readable,
only: (a: string | tape$TestOpts | tape$TestCb, b?: tape$TestCb | tape$TestOpts, c?: tape$TestCb, ...rest: Array<void>) => void,
};

declare module.exports: Tape;
}
35 changes: 18 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"name": "fusion-plugin-error-handling",
"description":
"Collects browser errors and server request errors, and emits them through an EventEmitter",
"description": "Collects browser errors and server request errors, and emits them through an EventEmitter",
"version": "1.0.3",
"license": "MIT",
"repository": "fusionjs/fusion-plugin-error-handling",
"files": ["dist", "src"],
"files": [
"dist",
"src"
],
"main": "./dist/index.js",
"module": "./dist/index.es.js",
"browser": {
Expand All @@ -23,22 +25,22 @@
"koa-bodyparser": "4.2.0"
},
"devDependencies": {
"babel-eslint": "8.2.3",
"babel-eslint": "^8.2.3",
"babel-plugin-transform-flow-strip-types": "6.22.0",
"create-universal-package": "3.4.4",
"create-universal-package": "^3.4.4",
"eslint": "4.19.1",
"eslint-config-fusion": "^1.0.0",
"eslint-plugin-cup": "1.0.2",
"eslint-plugin-flowtype": "2.46.3",
"eslint-plugin-import": "^2.9.0",
"eslint-config-fusion": "^1.0.1",
"eslint-plugin-cup": "^1.0.2",
"eslint-plugin-flowtype": "^2.46.3",
"eslint-plugin-import": "^2.11.0",
"eslint-plugin-prettier": "2.6.0",
"eslint-plugin-react": "7.7.0",
"flow-bin": "0.72.0",
"fusion-core": "^1.2.0",
"fusion-test-utils": "^1.0.1",
"fusion-tokens": "^1.0.2",
"nyc": "11.7.3",
"prettier": "1.12.1",
"flow-bin": "^0.72.0",
"fusion-core": "^1.2.6",
"fusion-test-utils": "^1.0.5",
"fusion-tokens": "^1.0.3",
"nyc": "^11.7.3",
"prettier": "^1.12.1",
"tape-cup": "4.7.1",
"unitest": "2.1.1"
},
Expand All @@ -51,8 +53,7 @@
"lint": "eslint . --ignore-path .gitignore",
"transpile": "npm run clean && cup build",
"build-test": "rm -rf dist-tests && npm run transpile && cup build-tests",
"just-test":
"node_modules/.bin/unitest --browser=dist-tests/browser.js --node=dist-tests/node.js",
"just-test": "node_modules/.bin/unitest --browser=dist-tests/browser.js --node=dist-tests/node.js",
"cover": "npm run build-test && npm run just-cover",
"just-cover": "nyc --reporter=text --reporter=html npm run just-test",
"test": "npm run build-test && npm run just-test",
Expand Down
10 changes: 7 additions & 3 deletions src/__tests__/index.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

/* eslint-env browser */

import App from 'fusion-core';
import test from 'tape-cup';

import App from 'fusion-core';
import {getSimulator} from 'fusion-test-utils';
import ErrorHandling, {ErrorHandlingEmitterToken} from '../client';

import ErrorHandlingPlugin, {ErrorHandlingEmitterToken} from '../client';

test('Get exception stack frames', t => {
t.plan(4);
Expand All @@ -35,7 +39,7 @@ test('Get exception stack frames', t => {

window.__foo__ = Foo;

app.register(ErrorHandling);
app.register(ErrorHandlingPlugin);
app.register(ErrorHandlingEmitterToken, mockEmit);

getSimulator(app);
Expand Down
14 changes: 10 additions & 4 deletions src/__tests__/index.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

/* eslint-env node */
import App, {consumeSanitizedHTML} from 'fusion-core';

import test from 'tape-cup';
import {getSimulator} from 'fusion-test-utils';
import {fork} from 'child_process';

import App, {consumeSanitizedHTML} from 'fusion-core';
import {getSimulator} from 'fusion-test-utils';

import ErrorHandling, {ErrorHandlerToken} from '../server';

test('request errors', async t => {
Expand Down Expand Up @@ -72,8 +77,7 @@ test('adds script', async t => {
app.register(ErrorHandling);
app.register(ErrorHandlerToken, () => {});

const ctx = await getSimulator(app).render('/');

const ctx = await await getSimulator(app).render('/');
t.ok(
consumeSanitizedHTML(ctx.template.head[0]).match(/<script/),
'adds script to head'
Expand All @@ -83,6 +87,7 @@ test('adds script', async t => {
});

test('Uncaught exceptions', async t => {
// $FlowFixMe
const forked = fork('./fixtures/uncaught-exception.js', {stdio: 'pipe'});
let stdout = '';
forked.stdout.on('data', data => {
Expand All @@ -97,6 +102,7 @@ test('Uncaught exceptions', async t => {
});

test('Unhandled rejections', async t => {
// $FlowFixMe
const forked = fork('./fixtures/unhandled-rejection.js', {stdio: 'pipe'});
let stdout = '';
forked.stdout.on('data', data => {
Expand Down
12 changes: 10 additions & 2 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

/* eslint-env browser */

import {createPlugin, createToken} from 'fusion-core';
import type {Token} from 'fusion-core';

import type {ErrorHandlerPluginType} from './types.js';

export const ErrorHandlingEmitterToken = createToken(
export const ErrorHandlingEmitterToken: Token<any> = createToken(
'ErrorHandlingEmitterToken'
);

export default __BROWSER__ &&
const plugin =
__BROWSER__ &&
createPlugin({
deps: {emit: ErrorHandlingEmitterToken.optional},
provides: ({emit}) => {
Expand Down Expand Up @@ -56,3 +62,5 @@ export default __BROWSER__ &&
});
},
});

export default ((plugin: any): ErrorHandlerPluginType);
7 changes: 4 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

// @flow
import serverPlugin from './server';
import clientPlugin from './client';

declare var __NODE__: Boolean;
export default (__NODE__ ? serverPlugin : clientPlugin);
export {ErrorHandlerToken} from './server';

export {ErrorHandlerToken} from './server.js';
20 changes: 16 additions & 4 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,32 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

/* eslint-env node */

import {createPlugin, html, createToken} from 'fusion-core';
import bodyParser from 'koa-bodyparser';
import assert from 'assert';

import {createPlugin, createToken, html} from 'fusion-core';
import type {Token} from 'fusion-core';

import type {ErrorHandlerPluginType, ErrorHandlerType} from './types.js';

export const ErrorHandlerToken: Token<ErrorHandlerType> = createToken(
'ErrorHandlerToken'
);

const captureTypes = {
browser: 'browser',
request: 'request',
server: 'server',
};

export const ErrorHandlerToken = createToken('ErrorHandlerToken');

export default __NODE__ &&
const plugin =
__NODE__ &&
createPlugin({
deps: {onError: ErrorHandlerToken},
provides({onError}) {
Expand Down Expand Up @@ -61,6 +70,7 @@ onerror = function(m,s,l,c,e) {
ctx.template.head.unshift(script);
} else if (ctx.path === '/_errors') {
await parseBody(ctx, () => Promise.resolve());
// $FlowFixMe
await onError(ctx.request.body, captureTypes.browser);
ctx.body = {ok: 1};
}
Expand All @@ -75,3 +85,5 @@ onerror = function(m,s,l,c,e) {
return middleware;
},
});

export default ((plugin: any): ErrorHandlerPluginType);
21 changes: 21 additions & 0 deletions src/types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/** Copyright (c) 2018 Uber Technologies, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import type {FusionPlugin} from 'fusion-core';

import {ErrorHandlingEmitterToken} from './client.js';
import {ErrorHandlerToken} from './server.js';

type DepsType = {
onError?: typeof ErrorHandlerToken,
emit?: typeof ErrorHandlingEmitterToken.optional,
};

export type ErrorHandlerPluginType = FusionPlugin<DepsType, empty>;

export type ErrorHandlerType = (e: Error, captureType: string) => Promise<*>;
Loading