Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

japa

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

japa - npm Package Compare versions

Comparing version 2.0.7 to 2.0.8

2

build/src/Callable/index.js

@@ -7,3 +7,3 @@ "use strict";

async function asPromise(fn, args) {
return await fn(...args);
return fn(...args);
}

@@ -10,0 +10,0 @@ function Callable(resolveFn, callback, timeout) {

@@ -71,2 +71,4 @@ export declare enum IEvents {

grep: string | RegExp;
before: ((runner: any, emitter: any) => Promise<void>)[];
after: ((runner: any, emitter: any) => Promise<void>)[];
reporterFn: (emitter: any) => void;

@@ -73,0 +75,0 @@ filter: (file: string) => void;

@@ -88,3 +88,3 @@ "use strict";

timeout(duration) {
ow_1.default(duration, ow_1.default.number.label('duration').integer);
ow_1.default(duration, 'duration', ow_1.default.number.integer);
if (this._tests.length) {

@@ -97,3 +97,3 @@ throw new Error('group.timeout must be called before defining the tests');

test(title, callback, testOptions) {
ow_1.default(title, ow_1.default.string.label('title').nonEmpty);
ow_1.default(title, 'title', ow_1.default.string.nonEmpty);
testOptions = Object.assign({

@@ -111,3 +111,3 @@ regression: false,

before(cb) {
ow_1.default(cb, ow_1.default.function.label('cb'));
ow_1.default(cb, 'cb', ow_1.default.function);
this._hooks.before.push(new Hook_1.Hook(this._resolveHookFn, cb, 'before'));

@@ -117,3 +117,3 @@ return this;

after(cb) {
ow_1.default(cb, ow_1.default.function.label('cb'));
ow_1.default(cb, 'cb', ow_1.default.function);
this._hooks.after.push(new Hook_1.Hook(this._resolveHookFn, cb, 'after'));

@@ -123,3 +123,3 @@ return this;

beforeEach(cb) {
ow_1.default(cb, ow_1.default.function.label('cb'));
ow_1.default(cb, 'cb', ow_1.default.function);
this._hooks.beforeEach.push(new Hook_1.Hook(this._resolveHookFn, cb, 'beforeEach'));

@@ -129,3 +129,3 @@ return this;

afterEach(cb) {
ow_1.default(cb, ow_1.default.function.label('cb'));
ow_1.default(cb, 'cb', ow_1.default.function);
this._hooks.afterEach.push(new Hook_1.Hook(this._resolveHookFn, cb, 'afterEach'));

@@ -132,0 +132,0 @@ return this;

import { IOptions } from '../Contracts';
import { Group } from '../Group';
declare type IRunnerHook<T extends any[], H extends any[]> = ((runner: Runner<T, H>, emitter: any) => Promise<void>);
export declare class Runner<T extends any[], H extends any[]> {

@@ -7,6 +8,10 @@ private _groups;

private _reporterFn;
private _hooks;
constructor(_groups: Group<T, H>[], _options: IOptions);
readonly hasErrors: boolean;
reporter(fn: (emitter: any) => void): this;
before(fn: IRunnerHook<T, H>): this;
after(fn: IRunnerHook<T, H>): this;
run(): Promise<void>;
}
export {};

@@ -5,2 +5,3 @@ "use strict";

const Emitter_1 = require("../Emitter");
const ow_1 = require("ow");
class Runner {

@@ -10,2 +11,6 @@ constructor(_groups, _options) {

this._options = _options;
this._hooks = {
before: [],
after: [],
};
}

@@ -16,5 +21,16 @@ get hasErrors() {

reporter(fn) {
ow_1.default(fn, 'callback', ow_1.default.function);
this._reporterFn = fn;
return this;
}
before(fn) {
ow_1.default(fn, 'callback', ow_1.default.function);
this._hooks.before.push(fn);
return this;
}
after(fn) {
ow_1.default(fn, 'callback', ow_1.default.function);
this._hooks.after.push(fn);
return this;
}
async run() {

@@ -24,2 +40,5 @@ if (typeof (this._reporterFn) !== 'function') {

}
for (let hook of this._hooks.before) {
await hook(this, Emitter_1.emitter);
}
this._reporterFn(Emitter_1.emitter, this._options);

@@ -34,4 +53,7 @@ Emitter_1.emitter.emit(Contracts_1.IEvents.STARTED);

Emitter_1.emitter.emit(Contracts_1.IEvents.COMPLETED);
for (let hook of this._hooks.after) {
await hook(this, Emitter_1.emitter);
}
}
}
exports.Runner = Runner;

@@ -5,5 +5,5 @@ import { Group } from '../Group';

import { ICallback, IConfigureOptions } from '../Contracts';
type testArgs = [Assert, Function];
type hookArgs = [Function];
type runnerGroup = Pick<Group<testArgs, hookArgs>, Exclude<keyof Group<testArgs, hookArgs>, 'run' | 'toJSON' | 'test'>>;
declare type testArgs = [Assert, Function];
declare type hookArgs = [Function];
declare type runnerGroup = Pick<Group<testArgs, hookArgs>, Exclude<keyof Group<testArgs, hookArgs>, 'run' | 'toJSON' | 'test'>>;
export declare function test(title: string, callback: ICallback<testArgs>): Pick<Test<[Assert, Function]>, "timeout" | "retry">;

@@ -10,0 +10,0 @@ export declare function run(exitProcess?: boolean): Promise<void>;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ow_1 = require("ow");
const chalk_1 = require("chalk");

@@ -26,2 +27,4 @@ const Runner_1 = require("../Runner");

let reporterFn = list_1.default;
let beforeHooks = [];
let afterHooks = [];
function addTest(title, callback, options) {

@@ -41,2 +44,4 @@ if (!activeGroup) {

runner.reporter(reporterFn);
beforeHooks.forEach((hook) => runner.before(hook));
afterHooks.forEach((hook) => runner.after(hook));
const loaderFiles = await loader.loadFiles();

@@ -106,2 +111,10 @@ if (loaderFiles.length && groups.length) {

}
if (options.before) {
ow_1.default(options.before, 'configure.before', ow_1.default.array);
beforeHooks = options.before;
}
if (options.after) {
ow_1.default(options.after, 'configure.after', ow_1.default.array);
afterHooks = options.after;
}
if (options.grep) {

@@ -108,0 +121,0 @@ runnerOptions.grep = options.grep instanceof RegExp ? options.grep : new RegExp(options.grep);

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ow_1 = require("ow");
const timeSpan = require("time-span");
const time_span_1 = require("time-span");
const retry = require("retry");

@@ -77,3 +77,3 @@ const isCI = require("is-ci");

retry(counts) {
ow_1.default(counts, ow_1.default.number.label('counts').integer);
ow_1.default(counts, 'counts', ow_1.default.number.integer);
this._retries = counts;

@@ -83,3 +83,3 @@ return this;

timeout(duration) {
ow_1.default(duration, ow_1.default.number.label('duration').integer);
ow_1.default(duration, 'duration', ow_1.default.number.integer);
this._timeout = duration;

@@ -90,3 +90,3 @@ return this;

Emitter_1.emitter.emit(Contracts_1.IEvents.TESTSTARTED, this.toJSON());
const start = timeSpan();
const start = time_span_1.default();
if (!this._todo && !this._skip) {

@@ -93,0 +93,0 @@ try {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const timeSpan = require("time-span");
const time_span_1 = require("time-span");
const Contracts_1 = require("../Contracts");

@@ -58,3 +58,3 @@ const exceptions = require("../Exceptions");

if (!this._processStart) {
this._processStart = timeSpan();
this._processStart = time_span_1.default();
}

@@ -61,0 +61,0 @@ }

@@ -0,1 +1,28 @@

## [2.0.8](https://github.com/thetutlage/japa/compare/2.0.7...2.0.8) (2019-03-23)
### Features
* **Runner:** add option to define before and after hooks ([12186db](https://github.com/thetutlage/japa/commit/12186db))
* **slimRunner:** expose before and after hooks via configure options ([fec01bb](https://github.com/thetutlage/japa/commit/fec01bb))
The runner hooks can be defined inside the `configure` method object.
```js
const { configure } = require('japa')
configure({
before: [
async (runner) => {
// setup db
}
],
after: [
async (runner) => {
// cleanup db
}
]
})
```
<a name="2.0.7"></a>

@@ -2,0 +29,0 @@ ## [2.0.7](https://github.com/thetutlage/japa/compare/v2.0.6...v2.0.7) (2019-01-01)

{
"name": "japa",
"version": "2.0.7",
"version": "2.0.8",
"description": "Lean test runner for Node.js",

@@ -17,3 +17,2 @@ "main": "build/index.js",

"test": "npm run test:win",
"posttest": "npm run coverage",
"commit": "git-cz",

@@ -24,3 +23,3 @@ "prepublishOnly": "npm run build && pkg-ok",

"compile": "npm run lint && npm run clean && tsc",
"build": "npm run compile && typedoc && node bin/postBuild.js",
"build": "npm run compile && node bin/postBuild.js",
"coverage": "nyc report --reporter=text-lcov | coveralls",

@@ -41,33 +40,35 @@ "lint": "tslint --project tsconfig.json"

"chai": "^4.2.0",
"chalk": "^2.4.1",
"chalk": "^2.4.2",
"debug": "^4.1.1",
"fast-glob": "^2.2.4",
"fast-glob": "^2.2.6",
"is-ci": "^2.0.0",
"ms": "^2.1.1",
"ow": "^0.8.0",
"ow": "^0.12.0",
"retry": "^0.12.0",
"right-pad": "^1.0.1",
"time-span": "^2.0.0",
"time-span": "^3.0.0",
"variable-diff": "^1.1.0"
},
"devDependencies": {
"@adonisjs/mrm-preset": "^1.0.14",
"@adonisjs/mrm-preset": "^1.0.16",
"@types/chai": "^4.1.7",
"@types/mocha": "^5.2.5",
"@types/node": "^10.12.18",
"commitizen": "^3.0.5",
"coveralls": "^3.0.2",
"@types/mocha": "^5.2.6",
"@types/node": "^11.11.6",
"commitizen": "^3.0.7",
"coveralls": "^3.0.3",
"cz-conventional-changelog": "^2.1.0",
"del-cli": "^1.1.0",
"mocha": "^5.2.0",
"doctoc": "^1.4.0",
"mocha": "^6.0.2",
"mrm": "^1.2.1",
"nyc": "^13.1.0",
"nyc": "^13.3.0",
"pkg-ok": "^2.3.1",
"ts-node": "^7.0.1",
"tslint": "^5.12.0",
"ts-node": "^8.0.3",
"tslint": "^5.14.0",
"tslint-eslint-rules": "^5.4.0",
"typedoc": "^0.13.0",
"typedoc-plugin-external-module-name": "^1.1.3",
"typedoc": "^0.14.2",
"typedoc-plugin-external-module-name": "^2.0.0",
"typedoc-plugin-single-line-tags": "^1.0.0",
"typescript": "^3.2.2"
"typescript": "^3.3.4000",
"yorkie": "^2.0.0"
},

@@ -95,3 +96,6 @@ "config": {

"test-runner"
]
],
"gitHooks": {
"pre-commit": "doctoc README.md --title='## Table of contents' && git add README.md"
}
}

@@ -14,26 +14,31 @@ ![](http://res.cloudinary.com/adonisjs/image/upload/v1484834197/monk_di16hz.png)

## Table of Contents
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
## Table of contents
* [Features](#features)
* [Why Japa?](#why-japa)
* [Faster boot time <g-emoji class="g-emoji" alias="alarm_clock" fallback-src="https://assets-cdn.github.com/images/icons/emoji/unicode/23f0.png">⏰</g-emoji>](#faster-boot-time-)
* [Simpler Syntax <g-emoji class="g-emoji" alias="nail_care" fallback-src="https://assets-cdn.github.com/images/icons/emoji/unicode/1f485.png">💅</g-emoji>](#simpler-syntax-)
* [Test your apps](#test-your-apps)
* [Installation](#installation)
* [Writing your first test](#writing-your-first-test)
* [async/await](#asyncawait)
* [Test timeouts](#test-timeouts)
* [Test groups](#test-groups)
* [Skipping tests](#skipping-tests)
* [Skipping/Running tests in CI](#skippingrunning-tests-in-ci)
* [Retry flaky tests](#retry-flaky-tests)
* [Regression tests](#regression-tests)
* [Assertion Planning](#assertion-planning)
* [Cleaner Error Stack](#cleaner-error-stack)
* [Japa flow](#japa-flow)
* [Running multiple test files](#running-multiple-test-files)
* [Filtering files](#filtering-files)
* [Configure options](#configure-options)
* [Running typescript tests](#running-typescript-tests)
- [Features](#features)
- [Why Japa?](#why-japa)
- [Faster boot time ⏰](#faster-boot-time-)
- [Simpler Syntax 💅](#simpler-syntax-)
- [Test your apps](#test-your-apps)
- [Installation](#installation)
- [Writing your first test](#writing-your-first-test)
- [async/await](#asyncawait)
- [Test timeouts](#test-timeouts)
- [Test groups](#test-groups)
- [Skipping tests](#skipping-tests)
- [Skipping/Running tests in CI](#skippingrunning-tests-in-ci)
- [Retry flaky tests](#retry-flaky-tests)
- [Regression tests](#regression-tests)
- [Assertion Planning](#assertion-planning)
- [Cleaner Error Stack](#cleaner-error-stack)
- [Runner hooks](#runner-hooks)
- [Japa flow](#japa-flow)
- [Running multiple test files](#running-multiple-test-files)
- [Filtering files](#filtering-files)
- [Configure options](#configure-options)
- [Running typescript tests](#running-typescript-tests)
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
<br>

@@ -385,2 +390,32 @@

<br>
---
## Runner hooks
Runner hooks are executed before and after running the entire test suite. These hooks can be used to perform global actions, which are required for all test groups.
The `before` and `after` hooks can be defined inside the configure object.
```js
const { configure } = require('japa')
configure({
before: [
async (runner) => {
// setup db
}
],
after: [
async (runner) => {
// cleanup db
}
]
})
```
<br>
---
## Japa flow

@@ -399,2 +434,6 @@

<br>
---
## Running multiple test files

@@ -437,2 +476,6 @@ Sooner or later, you will have multiple tests files, that you would like to run together, instead of running one file at a time. Doing same is very simple and is achieved using a **master test file**.

<br>
---
## Configure options

@@ -476,2 +519,15 @@ Here's the list of the options the `configure` method accepts.

<tr>
<td valign="top"><code>before:</code></td>
<td>
<p>An array of hooks to be executed before running all the tests. <strong>Hooks are executed in sequence</strong></p>
</td>
</tr>
<tr>
<td valign="top"><code>after
:</code></td>
<td>
<p>An array of hooks to be executed after running all the tests. <strong>Hooks are executed in sequence</strong></p>
</td>
</tr>
<tr>
<td colspan="2"><code>}</code></td>

@@ -481,2 +537,6 @@ </tr>

<br>
---
## Running typescript tests

@@ -483,0 +543,0 @@ Running test files written in `Typescript` is a piece of cake for Japa. Since everything is done inside the Javascript files, we can ask `japaFile.js` to load `ts-node`.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc