poku 1.5.1 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -13
- package/lib/@types/poku.d.ts +28 -0
- package/lib/helpers/format.d.ts +1 -0
- package/lib/helpers/format.js +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +6 -1
- package/lib/modules/assert-promise.d.ts +31 -0
- package/lib/modules/assert-promise.js +357 -0
- package/lib/modules/assert.d.ts +5 -0
- package/lib/modules/assert.js +100 -34
- package/lib/modules/each.d.ts +50 -0
- package/lib/modules/each.js +84 -0
- package/lib/modules/list-files.d.ts +2 -0
- package/lib/modules/list-files.js +6 -2
- package/lib/modules/poku.d.ts +2 -2
- package/lib/modules/poku.js +2 -2
- package/lib/services/each.d.ts +3 -0
- package/lib/services/each.js +44 -0
- package/lib/services/run-test-file.d.ts +1 -2
- package/lib/services/run-test-file.js +19 -4
- package/lib/services/run-tests.js +4 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
[ql-image]: https://img.shields.io/github/actions/workflow/status/wellwelwel/poku/codeql.yml?event=push&style=flat&label=Code%20QL&branch=main
|
|
13
13
|
[license-url]: https://github.com/wellwelwel/poku/blob/main/LICENSE
|
|
14
14
|
[license-image]: https://img.shields.io/npm/l/poku.svg?maxAge=2592000&color=9c88ff&label=License
|
|
15
|
+
[downloads-image]: https://img.shields.io/npm/dt/poku.svg?&color=FFC312&label=Downloads
|
|
16
|
+
[downloads-url]: https://npmjs.org/package/poku
|
|
15
17
|
|
|
16
18
|
# Poku
|
|
17
19
|
|
|
@@ -27,20 +29,20 @@
|
|
|
27
29
|
[![TypeScript Version][typescript-version-image]][typescript-url]
|
|
28
30
|
[![GitHub Workflow Status (with event)][ci-image]][ci-url]
|
|
29
31
|
[![GitHub Workflow Status (with event)][ql-image]][ql-url]
|
|
32
|
+
[![NPM Downloads][downloads-image]][downloads-url]
|
|
30
33
|
[![License][license-image]][license-url]
|
|
31
34
|
|
|
32
35
|
Enjoying **Poku**? Consider giving him a star ⭐️
|
|
33
36
|
|
|
34
37
|
---
|
|
35
38
|
|
|
36
|
-
🐷 [**Documentation Website**](https://poku.dev) • 🔬 [**Compare Poku with the Most Popular Test Runners**](https://poku.dev/docs/comparing)
|
|
39
|
+
🐷 [**Documentation Website**](https://poku.dev) • 🔬 [**Compare Poku with the Most Popular Test Runners**](https://poku.dev/docs/comparing) • 🧪 [**Examples**](https://poku.dev/docs/category/examples)
|
|
37
40
|
|
|
38
41
|
---
|
|
39
42
|
|
|
40
43
|
## Why Poku?
|
|
41
44
|
|
|
42
|
-
|
|
43
|
-
After all, you don't need to learn what you already know ([**see why**](https://poku.dev/docs/examples/beforeEach)) ✨
|
|
45
|
+
Let's make `describe`, `beforeEach` and everything else easier 🚀 <br/>
|
|
44
46
|
|
|
45
47
|
- Supports **ESM** and **CJS**
|
|
46
48
|
- Designed to be highly intuitive
|
|
@@ -65,6 +67,12 @@ After all, you don't need to learn what you already know ([**see why**](https://
|
|
|
65
67
|
|
|
66
68
|
---
|
|
67
69
|
|
|
70
|
+
## Examples
|
|
71
|
+
|
|
72
|
+
- See real example usages in [**Examples**](https://poku.dev/docs/category/examples) section for **Poku**'s + **Mock**, **Virutal DOM** and more.
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
68
76
|
## Overview
|
|
69
77
|
|
|
70
78
|
### `poku`
|
|
@@ -117,47 +125,58 @@ import { poku } from 'npm:poku';
|
|
|
117
125
|
|
|
118
126
|
## Quick Start
|
|
119
127
|
|
|
120
|
-
###
|
|
128
|
+
### `poku`
|
|
129
|
+
|
|
130
|
+
#### CLI
|
|
131
|
+
|
|
132
|
+
> Try to set the flag `--parallel` before the target path 🚀
|
|
121
133
|
|
|
122
134
|
> <img src=".github/assets/readme/node-js.svg" width="24" />
|
|
123
135
|
|
|
124
136
|
```bash
|
|
125
|
-
npx poku
|
|
137
|
+
npx poku targetPath
|
|
138
|
+
npx poku targetPathA,targetPathB
|
|
126
139
|
```
|
|
127
140
|
|
|
128
141
|
> <img src=".github/assets/readme/bun.svg" width="24" />
|
|
129
142
|
|
|
130
143
|
```bash
|
|
131
|
-
bun poku
|
|
144
|
+
bun poku targetPath
|
|
145
|
+
bun poku targetPathA,targetPathB
|
|
132
146
|
```
|
|
133
147
|
|
|
134
148
|
> <img src=".github/assets/readme/deno.svg" width="24" />
|
|
135
149
|
|
|
136
150
|
```bash
|
|
137
|
-
deno run npm:poku
|
|
151
|
+
deno run npm:poku targetPath
|
|
152
|
+
deno run npm:poku targetPathA,targetPathB
|
|
138
153
|
```
|
|
139
154
|
|
|
140
|
-
|
|
155
|
+
#### API (_In-code_)
|
|
141
156
|
|
|
142
|
-
|
|
157
|
+
##### Node.js, TypeScript (Node.js) and Bun
|
|
143
158
|
|
|
144
159
|
```ts
|
|
145
160
|
import { poku } from 'poku';
|
|
146
161
|
|
|
147
|
-
await poku(['
|
|
162
|
+
await poku(['targetPath']);
|
|
148
163
|
```
|
|
149
164
|
|
|
150
|
-
|
|
165
|
+
##### Deno
|
|
151
166
|
|
|
152
167
|
```ts
|
|
153
168
|
import { poku } from 'npm:poku';
|
|
154
169
|
|
|
155
|
-
await poku(['
|
|
170
|
+
await poku(['targetPath']);
|
|
156
171
|
```
|
|
157
172
|
|
|
173
|
+
### `assert`
|
|
174
|
+
|
|
175
|
+
Use it exactly as it's for **Node.js** 💚
|
|
176
|
+
|
|
158
177
|
---
|
|
159
178
|
|
|
160
|
-
To see the detailed documentation, please visit the [**Documentation**](https://poku.dev/docs/category/documentation)
|
|
179
|
+
To see the detailed documentation, please visit the [**Documentation**](https://poku.dev/docs/category/documentation) and [**Examples**](https://poku.dev/docs/category/examples) sections in the [**Poku**'s website](https://poku.dev).
|
|
161
180
|
|
|
162
181
|
---
|
|
163
182
|
|
package/lib/@types/poku.d.ts
CHANGED
|
@@ -50,4 +50,32 @@ export type Configs = {
|
|
|
50
50
|
* @default 'node'
|
|
51
51
|
*/
|
|
52
52
|
platform?: 'node' | 'bun' | 'deno';
|
|
53
|
+
/**
|
|
54
|
+
* You can use this option to run a **callback** or a **file** before each test file on your suite.
|
|
55
|
+
*
|
|
56
|
+
* Ex.:
|
|
57
|
+
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* beforeEach(prepare)
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* ```ts
|
|
63
|
+
* beforeEach('/tools/prepare.ts')
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
beforeEach?: () => unknown | Promise<unknown>;
|
|
67
|
+
/**
|
|
68
|
+
* You can use this option to run a **callback** or a **file** after each test file on your suite.
|
|
69
|
+
*
|
|
70
|
+
* Ex.:
|
|
71
|
+
*
|
|
72
|
+
* ```ts
|
|
73
|
+
* afterEach(cleanup)
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* ```ts
|
|
77
|
+
* afterEach('/tools/cleanup.ts')
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
afterEach?: () => unknown | Promise<unknown>;
|
|
53
81
|
} & ListFilesConfigs;
|
package/lib/helpers/format.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare const format: {
|
|
|
4
4
|
bold: (value: string) => string;
|
|
5
5
|
underline: (value: string) => string;
|
|
6
6
|
info: (value: string) => string;
|
|
7
|
+
italic: (value: string) => string;
|
|
7
8
|
success: (value: string) => string;
|
|
8
9
|
fail: (value: string) => string;
|
|
9
10
|
bg: (bg: number, text: string) => string;
|
package/lib/helpers/format.js
CHANGED
|
@@ -11,6 +11,7 @@ exports.format = {
|
|
|
11
11
|
bold: (value) => `\x1b[1m${value}\x1b[0m`,
|
|
12
12
|
underline: (value) => `\x1b[4m${value}\x1b[0m`,
|
|
13
13
|
info: (value) => `\x1b[94m${value}\x1b[0m`,
|
|
14
|
+
italic: (value) => `\x1b[3m${value}\x1b[0m`,
|
|
14
15
|
success: (value) => `\x1b[32m${value}\x1b[0m`,
|
|
15
16
|
fail: (value) => `\x1b[91m${value}\x1b[0m`,
|
|
16
17
|
bg: (bg, text) => {
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { poku } from './modules/poku.js';
|
|
2
2
|
export { exit } from './modules/exit.js';
|
|
3
3
|
export { assert } from './modules/assert.js';
|
|
4
|
+
export { assertPromise } from './modules/assert-promise.js';
|
|
5
|
+
export { beforeEach, afterEach } from './modules/each.js';
|
|
4
6
|
export { publicListFiles as listFiles } from './modules/list-files.js';
|
|
5
7
|
export type { Code } from './@types/code.ts';
|
|
6
8
|
export type { Configs } from './@types/poku.ts';
|
package/lib/index.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.listFiles = exports.assert = exports.exit = exports.poku = void 0;
|
|
3
|
+
exports.listFiles = exports.afterEach = exports.beforeEach = exports.assertPromise = exports.assert = exports.exit = exports.poku = void 0;
|
|
4
4
|
var poku_js_1 = require("./modules/poku.js");
|
|
5
5
|
Object.defineProperty(exports, "poku", { enumerable: true, get: function () { return poku_js_1.poku; } });
|
|
6
6
|
var exit_js_1 = require("./modules/exit.js");
|
|
7
7
|
Object.defineProperty(exports, "exit", { enumerable: true, get: function () { return exit_js_1.exit; } });
|
|
8
8
|
var assert_js_1 = require("./modules/assert.js");
|
|
9
9
|
Object.defineProperty(exports, "assert", { enumerable: true, get: function () { return assert_js_1.assert; } });
|
|
10
|
+
var assert_promise_js_1 = require("./modules/assert-promise.js");
|
|
11
|
+
Object.defineProperty(exports, "assertPromise", { enumerable: true, get: function () { return assert_promise_js_1.assertPromise; } });
|
|
12
|
+
var each_js_1 = require("./modules/each.js");
|
|
13
|
+
Object.defineProperty(exports, "beforeEach", { enumerable: true, get: function () { return each_js_1.beforeEach; } });
|
|
14
|
+
Object.defineProperty(exports, "afterEach", { enumerable: true, get: function () { return each_js_1.afterEach; } });
|
|
10
15
|
var list_files_js_1 = require("./modules/list-files.js");
|
|
11
16
|
Object.defineProperty(exports, "listFiles", { enumerable: true, get: function () { return list_files_js_1.publicListFiles; } });
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as nodeAssert from 'node:assert';
|
|
3
|
+
import { ParseAssertionOptions } from '../helpers/parseAsssetion.js';
|
|
4
|
+
declare function doesNotReject(block: (() => Promise<unknown>) | Promise<unknown>, message?: string | Error): Promise<void>;
|
|
5
|
+
declare function doesNotReject(block: (() => Promise<unknown>) | Promise<unknown>, error: nodeAssert.AssertPredicate, message?: string | Error): Promise<void>;
|
|
6
|
+
declare function doesNotThrow(block: () => unknown, message?: string | ParseAssertionOptions['message']): void;
|
|
7
|
+
declare function doesNotThrow(block: () => unknown, error: nodeAssert.AssertPredicate, message?: ParseAssertionOptions['message']): void;
|
|
8
|
+
declare function throws(block: () => unknown, message?: ParseAssertionOptions['message']): void;
|
|
9
|
+
declare function throws(block: () => unknown, error: nodeAssert.AssertPredicate, message?: ParseAssertionOptions['message']): void;
|
|
10
|
+
declare function rejects(block: (() => Promise<unknown>) | Promise<unknown>, message?: string | Error): Promise<void>;
|
|
11
|
+
declare function rejects(block: (() => Promise<unknown>) | Promise<unknown>, error: nodeAssert.AssertPredicate, message?: string | Error): Promise<void>;
|
|
12
|
+
export declare const assertPromise: ((value: unknown, message?: ParseAssertionOptions['message']) => Promise<void>) & {
|
|
13
|
+
ok: (value: unknown, message?: ParseAssertionOptions['message']) => Promise<void>;
|
|
14
|
+
equal: (actual: unknown, expected: unknown, message?: ParseAssertionOptions['message']) => Promise<void>;
|
|
15
|
+
deepEqual: (actual: unknown, expected: unknown, message?: ParseAssertionOptions['message']) => Promise<void>;
|
|
16
|
+
strictEqual: (actual: unknown, expected: unknown, message?: ParseAssertionOptions['message']) => Promise<void>;
|
|
17
|
+
deepStrictEqual: (actual: unknown, expected: unknown, message?: ParseAssertionOptions['message']) => Promise<void>;
|
|
18
|
+
doesNotMatch: (value: string, regExp: RegExp, message?: ParseAssertionOptions['message']) => Promise<void>;
|
|
19
|
+
doesNotReject: typeof doesNotReject;
|
|
20
|
+
throws: typeof throws;
|
|
21
|
+
doesNotThrow: typeof doesNotThrow;
|
|
22
|
+
notEqual: (actual: unknown, expected: unknown, message?: ParseAssertionOptions['message']) => Promise<void>;
|
|
23
|
+
notDeepEqual: (actual: unknown, expected: unknown, message?: ParseAssertionOptions['message']) => Promise<void>;
|
|
24
|
+
notStrictEqual: (actual: unknown, expected: unknown, message?: ParseAssertionOptions['message']) => Promise<void>;
|
|
25
|
+
notDeepStrictEqual: (actual: unknown, expected: unknown, message?: ParseAssertionOptions['message']) => Promise<void>;
|
|
26
|
+
match: (value: string, regExp: RegExp, message?: ParseAssertionOptions['message']) => Promise<void>;
|
|
27
|
+
ifError: (value: unknown) => Promise<void>;
|
|
28
|
+
fail: (message?: ParseAssertionOptions['message']) => void;
|
|
29
|
+
rejects: typeof rejects;
|
|
30
|
+
};
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.assertPromise = void 0;
|
|
36
|
+
const nodeAssert = __importStar(require("assert"));
|
|
37
|
+
const parseAsssetion_js_1 = require("../helpers/parseAsssetion.js");
|
|
38
|
+
const assert_js_1 = require("./assert.js");
|
|
39
|
+
const ok = (value, message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
if (assert_js_1.each.before)
|
|
41
|
+
yield assert_js_1.each.before();
|
|
42
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => nodeAssert.ok(value), { message });
|
|
43
|
+
if (assert_js_1.each.after)
|
|
44
|
+
yield assert_js_1.each.after();
|
|
45
|
+
});
|
|
46
|
+
const equal = (actual, expected, message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
+
if (assert_js_1.each.before)
|
|
48
|
+
yield assert_js_1.each.before();
|
|
49
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => nodeAssert.equal(actual, expected), { message });
|
|
50
|
+
if (assert_js_1.each.after)
|
|
51
|
+
yield assert_js_1.each.after();
|
|
52
|
+
});
|
|
53
|
+
const deepEqual = (actual, expected, message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
+
if (assert_js_1.each.before)
|
|
55
|
+
yield assert_js_1.each.before();
|
|
56
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => nodeAssert.deepEqual(actual, expected), {
|
|
57
|
+
message,
|
|
58
|
+
});
|
|
59
|
+
if (assert_js_1.each.after)
|
|
60
|
+
yield assert_js_1.each.after();
|
|
61
|
+
});
|
|
62
|
+
const strictEqual = (actual, expected, message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
+
if (assert_js_1.each.before)
|
|
64
|
+
yield assert_js_1.each.before();
|
|
65
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => nodeAssert.strictEqual(actual, expected), {
|
|
66
|
+
message,
|
|
67
|
+
});
|
|
68
|
+
if (assert_js_1.each.after)
|
|
69
|
+
yield assert_js_1.each.after();
|
|
70
|
+
});
|
|
71
|
+
const deepStrictEqual = (actual, expected, message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
72
|
+
if (assert_js_1.each.before)
|
|
73
|
+
yield assert_js_1.each.before();
|
|
74
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => nodeAssert.deepStrictEqual(actual, expected), {
|
|
75
|
+
message,
|
|
76
|
+
});
|
|
77
|
+
if (assert_js_1.each.after)
|
|
78
|
+
yield assert_js_1.each.after();
|
|
79
|
+
});
|
|
80
|
+
const doesNotMatch = (value, regExp, message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
81
|
+
if (assert_js_1.each.before)
|
|
82
|
+
yield assert_js_1.each.before();
|
|
83
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => nodeAssert.doesNotMatch(value, regExp), {
|
|
84
|
+
message,
|
|
85
|
+
});
|
|
86
|
+
if (assert_js_1.each.after)
|
|
87
|
+
yield assert_js_1.each.after();
|
|
88
|
+
});
|
|
89
|
+
function doesNotReject(block, errorOrMessage, message) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
if (typeof errorOrMessage === 'function' ||
|
|
92
|
+
errorOrMessage instanceof RegExp ||
|
|
93
|
+
typeof errorOrMessage === 'object') {
|
|
94
|
+
try {
|
|
95
|
+
if (assert_js_1.each.before)
|
|
96
|
+
yield assert_js_1.each.before();
|
|
97
|
+
yield nodeAssert.doesNotReject(block, errorOrMessage);
|
|
98
|
+
if (assert_js_1.each.after)
|
|
99
|
+
yield assert_js_1.each.after();
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => {
|
|
103
|
+
throw error;
|
|
104
|
+
}, {
|
|
105
|
+
message,
|
|
106
|
+
defaultMessage: 'Got unwanted rejection',
|
|
107
|
+
hideDiff: true,
|
|
108
|
+
throw: true,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
try {
|
|
114
|
+
if (assert_js_1.each.before)
|
|
115
|
+
yield assert_js_1.each.before();
|
|
116
|
+
yield nodeAssert.doesNotReject(block);
|
|
117
|
+
if (assert_js_1.each.after)
|
|
118
|
+
yield assert_js_1.each.after();
|
|
119
|
+
}
|
|
120
|
+
catch (error_1) {
|
|
121
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => {
|
|
122
|
+
throw error_1;
|
|
123
|
+
}, {
|
|
124
|
+
message: typeof errorOrMessage === 'string' ? errorOrMessage : undefined,
|
|
125
|
+
defaultMessage: 'Got unwanted rejection',
|
|
126
|
+
hideDiff: true,
|
|
127
|
+
throw: true,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function doesNotThrow(block, errorOrMessage, message) {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
if (typeof errorOrMessage === 'function' ||
|
|
136
|
+
errorOrMessage instanceof RegExp ||
|
|
137
|
+
typeof errorOrMessage === 'object') {
|
|
138
|
+
try {
|
|
139
|
+
if (assert_js_1.each.before)
|
|
140
|
+
yield assert_js_1.each.before();
|
|
141
|
+
nodeAssert.doesNotThrow(block, errorOrMessage, message);
|
|
142
|
+
if (assert_js_1.each.after)
|
|
143
|
+
yield assert_js_1.each.after();
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => {
|
|
147
|
+
throw error;
|
|
148
|
+
}, {
|
|
149
|
+
message: message,
|
|
150
|
+
defaultMessage: 'Expected function not to throw',
|
|
151
|
+
hideDiff: true,
|
|
152
|
+
throw: true,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
const msg = typeof errorOrMessage === 'string' ? errorOrMessage : undefined;
|
|
158
|
+
try {
|
|
159
|
+
if (assert_js_1.each.before)
|
|
160
|
+
yield assert_js_1.each.before();
|
|
161
|
+
nodeAssert.doesNotThrow(block, msg);
|
|
162
|
+
if (assert_js_1.each.after)
|
|
163
|
+
yield assert_js_1.each.after();
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => {
|
|
167
|
+
throw error;
|
|
168
|
+
}, {
|
|
169
|
+
message: msg,
|
|
170
|
+
defaultMessage: 'Expected function not to throw',
|
|
171
|
+
hideDiff: true,
|
|
172
|
+
throw: true,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
function throws(block, errorOrMessage, message) {
|
|
179
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
180
|
+
if (typeof errorOrMessage === 'function' ||
|
|
181
|
+
errorOrMessage instanceof RegExp ||
|
|
182
|
+
typeof errorOrMessage === 'object') {
|
|
183
|
+
try {
|
|
184
|
+
if (assert_js_1.each.before)
|
|
185
|
+
yield assert_js_1.each.before();
|
|
186
|
+
nodeAssert.throws(block, errorOrMessage, message);
|
|
187
|
+
if (assert_js_1.each.after)
|
|
188
|
+
yield assert_js_1.each.after();
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => {
|
|
192
|
+
throw error;
|
|
193
|
+
}, {
|
|
194
|
+
message: message,
|
|
195
|
+
defaultMessage: 'Expected function to throw',
|
|
196
|
+
hideDiff: true,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
const msg = typeof errorOrMessage === 'string' ? errorOrMessage : undefined;
|
|
202
|
+
try {
|
|
203
|
+
if (assert_js_1.each.before)
|
|
204
|
+
yield assert_js_1.each.before();
|
|
205
|
+
nodeAssert.throws(block, message);
|
|
206
|
+
if (assert_js_1.each.after)
|
|
207
|
+
yield assert_js_1.each.after();
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => {
|
|
211
|
+
throw error;
|
|
212
|
+
}, {
|
|
213
|
+
message: msg,
|
|
214
|
+
defaultMessage: 'Expected function to throw',
|
|
215
|
+
hideDiff: true,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
const notEqual = (actual, expected, message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
222
|
+
if (assert_js_1.each.before)
|
|
223
|
+
yield assert_js_1.each.before();
|
|
224
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => nodeAssert.notEqual(actual, expected), {
|
|
225
|
+
message,
|
|
226
|
+
});
|
|
227
|
+
if (assert_js_1.each.after)
|
|
228
|
+
yield assert_js_1.each.after();
|
|
229
|
+
});
|
|
230
|
+
const notDeepEqual = (actual, expected, message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
231
|
+
if (assert_js_1.each.before)
|
|
232
|
+
yield assert_js_1.each.before();
|
|
233
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => nodeAssert.notDeepEqual(actual, expected), {
|
|
234
|
+
message,
|
|
235
|
+
});
|
|
236
|
+
if (assert_js_1.each.after)
|
|
237
|
+
yield assert_js_1.each.after();
|
|
238
|
+
});
|
|
239
|
+
const notStrictEqual = (actual, expected, message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
240
|
+
if (assert_js_1.each.before)
|
|
241
|
+
yield assert_js_1.each.before();
|
|
242
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => nodeAssert.notStrictEqual(actual, expected), {
|
|
243
|
+
message,
|
|
244
|
+
});
|
|
245
|
+
if (assert_js_1.each.after)
|
|
246
|
+
yield assert_js_1.each.after();
|
|
247
|
+
});
|
|
248
|
+
const notDeepStrictEqual = (actual, expected, message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
249
|
+
if (assert_js_1.each.before)
|
|
250
|
+
yield assert_js_1.each.before();
|
|
251
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => nodeAssert.notDeepStrictEqual(actual, expected), {
|
|
252
|
+
message,
|
|
253
|
+
});
|
|
254
|
+
if (assert_js_1.each.after)
|
|
255
|
+
yield assert_js_1.each.after();
|
|
256
|
+
});
|
|
257
|
+
const match = (value, regExp, message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
258
|
+
if (assert_js_1.each.before)
|
|
259
|
+
yield assert_js_1.each.before();
|
|
260
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => nodeAssert.match(value, regExp), { message });
|
|
261
|
+
if (assert_js_1.each.after)
|
|
262
|
+
yield assert_js_1.each.after();
|
|
263
|
+
});
|
|
264
|
+
const ifError = (value) => __awaiter(void 0, void 0, void 0, function* () {
|
|
265
|
+
try {
|
|
266
|
+
if (assert_js_1.each.before)
|
|
267
|
+
yield assert_js_1.each.before();
|
|
268
|
+
nodeAssert.ifError(value);
|
|
269
|
+
if (assert_js_1.each.after)
|
|
270
|
+
yield assert_js_1.each.after();
|
|
271
|
+
}
|
|
272
|
+
catch (error) {
|
|
273
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => {
|
|
274
|
+
throw error;
|
|
275
|
+
}, {
|
|
276
|
+
defaultMessage: 'Expected no error, but received an error',
|
|
277
|
+
hideDiff: true,
|
|
278
|
+
throw: true,
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
const fail = (message) => {
|
|
283
|
+
try {
|
|
284
|
+
nodeAssert.fail(message);
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => {
|
|
288
|
+
throw error;
|
|
289
|
+
}, {
|
|
290
|
+
message,
|
|
291
|
+
defaultMessage: 'Test failed intentionally',
|
|
292
|
+
hideDiff: true,
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
function rejects(block, errorOrMessage, message) {
|
|
297
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
298
|
+
if (typeof errorOrMessage === 'function' ||
|
|
299
|
+
errorOrMessage instanceof RegExp ||
|
|
300
|
+
typeof errorOrMessage === 'object') {
|
|
301
|
+
try {
|
|
302
|
+
if (assert_js_1.each.before)
|
|
303
|
+
yield assert_js_1.each.before();
|
|
304
|
+
yield nodeAssert.rejects(block, errorOrMessage);
|
|
305
|
+
if (assert_js_1.each.after)
|
|
306
|
+
yield assert_js_1.each.after();
|
|
307
|
+
}
|
|
308
|
+
catch (error) {
|
|
309
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => {
|
|
310
|
+
throw error;
|
|
311
|
+
}, {
|
|
312
|
+
message,
|
|
313
|
+
defaultMessage: 'Expected promise to be rejected with specified error',
|
|
314
|
+
hideDiff: true,
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
const msg = typeof errorOrMessage === 'string' ? errorOrMessage : undefined;
|
|
320
|
+
try {
|
|
321
|
+
if (assert_js_1.each.before)
|
|
322
|
+
yield assert_js_1.each.before();
|
|
323
|
+
yield nodeAssert.rejects(block);
|
|
324
|
+
if (assert_js_1.each.after)
|
|
325
|
+
yield assert_js_1.each.after();
|
|
326
|
+
}
|
|
327
|
+
catch (error_1) {
|
|
328
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => {
|
|
329
|
+
throw error_1;
|
|
330
|
+
}, {
|
|
331
|
+
message: msg,
|
|
332
|
+
defaultMessage: 'Expected promise to be rejected',
|
|
333
|
+
hideDiff: true,
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
exports.assertPromise = Object.assign((value, message) => ok(value, message), {
|
|
340
|
+
ok,
|
|
341
|
+
equal,
|
|
342
|
+
deepEqual,
|
|
343
|
+
strictEqual,
|
|
344
|
+
deepStrictEqual,
|
|
345
|
+
doesNotMatch,
|
|
346
|
+
doesNotReject,
|
|
347
|
+
throws,
|
|
348
|
+
doesNotThrow,
|
|
349
|
+
notEqual,
|
|
350
|
+
notDeepEqual,
|
|
351
|
+
notStrictEqual,
|
|
352
|
+
notDeepStrictEqual,
|
|
353
|
+
match,
|
|
354
|
+
ifError,
|
|
355
|
+
fail,
|
|
356
|
+
rejects,
|
|
357
|
+
});
|
package/lib/modules/assert.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import * as nodeAssert from 'node:assert';
|
|
3
3
|
import { ParseAssertionOptions } from '../helpers/parseAsssetion.js';
|
|
4
|
+
type Each = {
|
|
5
|
+
before?: undefined | (() => unknown);
|
|
6
|
+
after?: undefined | (() => unknown);
|
|
7
|
+
};
|
|
8
|
+
export declare const each: Each;
|
|
4
9
|
declare function doesNotReject(block: (() => Promise<unknown>) | Promise<unknown>, message?: string | Error): Promise<void>;
|
|
5
10
|
declare function doesNotReject(block: (() => Promise<unknown>) | Promise<unknown>, error: nodeAssert.AssertPredicate, message?: string | Error): Promise<void>;
|
|
6
11
|
declare function doesNotThrow(block: () => unknown, message?: string | ParseAssertionOptions['message']): void;
|
package/lib/modules/assert.js
CHANGED
|
@@ -32,29 +32,59 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.assert = void 0;
|
|
35
|
+
exports.assert = exports.each = void 0;
|
|
36
36
|
const nodeAssert = __importStar(require("assert"));
|
|
37
37
|
const parseAsssetion_js_1 = require("../helpers/parseAsssetion.js");
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
38
|
+
exports.each = {
|
|
39
|
+
before: undefined,
|
|
40
|
+
after: undefined,
|
|
41
|
+
};
|
|
42
|
+
const ok = (value, message) => {
|
|
43
|
+
exports.each.before && exports.each.before();
|
|
44
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => nodeAssert.ok(value), { message });
|
|
45
|
+
exports.each.after && exports.each.after();
|
|
46
|
+
};
|
|
47
|
+
const equal = (actual, expected, message) => {
|
|
48
|
+
exports.each.before && exports.each.before();
|
|
49
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => nodeAssert.equal(actual, expected), { message });
|
|
50
|
+
exports.each.after && exports.each.after();
|
|
51
|
+
};
|
|
52
|
+
const deepEqual = (actual, expected, message) => {
|
|
53
|
+
exports.each.before && exports.each.before();
|
|
54
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => nodeAssert.deepEqual(actual, expected), { message });
|
|
55
|
+
exports.each.after && exports.each.after();
|
|
56
|
+
};
|
|
57
|
+
const strictEqual = (actual, expected, message) => {
|
|
58
|
+
exports.each.before && exports.each.before();
|
|
59
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => nodeAssert.strictEqual(actual, expected), { message });
|
|
60
|
+
exports.each.after && exports.each.after();
|
|
61
|
+
};
|
|
62
|
+
const deepStrictEqual = (actual, expected, message) => {
|
|
63
|
+
exports.each.before && exports.each.before();
|
|
64
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => nodeAssert.deepStrictEqual(actual, expected), {
|
|
65
|
+
message,
|
|
66
|
+
});
|
|
67
|
+
exports.each.after && exports.each.after();
|
|
68
|
+
};
|
|
69
|
+
const doesNotMatch = (value, regExp, message) => {
|
|
70
|
+
exports.each.before && exports.each.before();
|
|
71
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => nodeAssert.doesNotMatch(value, regExp), {
|
|
72
|
+
message,
|
|
73
|
+
actual: 'Value',
|
|
74
|
+
expected: 'RegExp',
|
|
75
|
+
defaultMessage: 'Value should not match regExp',
|
|
76
|
+
});
|
|
77
|
+
exports.each.after && exports.each.after();
|
|
78
|
+
};
|
|
51
79
|
function doesNotReject(block, errorOrMessage, message) {
|
|
52
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
81
|
if (typeof errorOrMessage === 'function' ||
|
|
54
82
|
errorOrMessage instanceof RegExp ||
|
|
55
83
|
typeof errorOrMessage === 'object') {
|
|
56
84
|
try {
|
|
57
|
-
|
|
85
|
+
exports.each.before && exports.each.before();
|
|
86
|
+
yield nodeAssert.doesNotReject(block, errorOrMessage);
|
|
87
|
+
exports.each.after && exports.each.after();
|
|
58
88
|
}
|
|
59
89
|
catch (error) {
|
|
60
90
|
(0, parseAsssetion_js_1.parseAssertion)(() => {
|
|
@@ -69,7 +99,9 @@ function doesNotReject(block, errorOrMessage, message) {
|
|
|
69
99
|
}
|
|
70
100
|
else {
|
|
71
101
|
try {
|
|
72
|
-
|
|
102
|
+
exports.each.before && exports.each.before();
|
|
103
|
+
yield nodeAssert.doesNotReject(block);
|
|
104
|
+
exports.each.after && exports.each.after();
|
|
73
105
|
}
|
|
74
106
|
catch (error_1) {
|
|
75
107
|
(0, parseAsssetion_js_1.parseAssertion)(() => {
|
|
@@ -89,7 +121,9 @@ function doesNotThrow(block, errorOrMessage, message) {
|
|
|
89
121
|
errorOrMessage instanceof RegExp ||
|
|
90
122
|
typeof errorOrMessage === 'object') {
|
|
91
123
|
try {
|
|
124
|
+
exports.each.before && exports.each.before();
|
|
92
125
|
nodeAssert.doesNotThrow(block, errorOrMessage, message);
|
|
126
|
+
exports.each.after && exports.each.after();
|
|
93
127
|
}
|
|
94
128
|
catch (error) {
|
|
95
129
|
(0, parseAsssetion_js_1.parseAssertion)(() => {
|
|
@@ -105,7 +139,9 @@ function doesNotThrow(block, errorOrMessage, message) {
|
|
|
105
139
|
else {
|
|
106
140
|
const msg = typeof errorOrMessage === 'string' ? errorOrMessage : undefined;
|
|
107
141
|
try {
|
|
142
|
+
exports.each.before && exports.each.before();
|
|
108
143
|
nodeAssert.doesNotThrow(block, msg);
|
|
144
|
+
exports.each.after && exports.each.after();
|
|
109
145
|
}
|
|
110
146
|
catch (error) {
|
|
111
147
|
(0, parseAsssetion_js_1.parseAssertion)(() => {
|
|
@@ -124,7 +160,9 @@ function throws(block, errorOrMessage, message) {
|
|
|
124
160
|
errorOrMessage instanceof RegExp ||
|
|
125
161
|
typeof errorOrMessage === 'object') {
|
|
126
162
|
try {
|
|
163
|
+
exports.each.before && exports.each.before();
|
|
127
164
|
nodeAssert.throws(block, errorOrMessage, message);
|
|
165
|
+
exports.each.after && exports.each.after();
|
|
128
166
|
}
|
|
129
167
|
catch (error) {
|
|
130
168
|
(0, parseAsssetion_js_1.parseAssertion)(() => {
|
|
@@ -139,7 +177,9 @@ function throws(block, errorOrMessage, message) {
|
|
|
139
177
|
else {
|
|
140
178
|
const msg = typeof errorOrMessage === 'string' ? errorOrMessage : undefined;
|
|
141
179
|
try {
|
|
180
|
+
exports.each.before && exports.each.before();
|
|
142
181
|
nodeAssert.throws(block, message);
|
|
182
|
+
exports.each.after && exports.each.after();
|
|
143
183
|
}
|
|
144
184
|
catch (error) {
|
|
145
185
|
(0, parseAsssetion_js_1.parseAssertion)(() => {
|
|
@@ -152,25 +192,47 @@ function throws(block, errorOrMessage, message) {
|
|
|
152
192
|
}
|
|
153
193
|
}
|
|
154
194
|
}
|
|
155
|
-
const notEqual = (actual, expected, message) =>
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
195
|
+
const notEqual = (actual, expected, message) => {
|
|
196
|
+
exports.each.before && exports.each.before();
|
|
197
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => nodeAssert.notEqual(actual, expected), {
|
|
198
|
+
message,
|
|
199
|
+
});
|
|
200
|
+
exports.each.after && exports.each.after();
|
|
201
|
+
};
|
|
202
|
+
const notDeepEqual = (actual, expected, message) => {
|
|
203
|
+
exports.each.before && exports.each.before();
|
|
204
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => nodeAssert.notDeepEqual(actual, expected), { message });
|
|
205
|
+
exports.each.after && exports.each.after();
|
|
206
|
+
};
|
|
207
|
+
const notStrictEqual = (actual, expected, message) => {
|
|
208
|
+
exports.each.before && exports.each.before();
|
|
209
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => nodeAssert.notStrictEqual(actual, expected), {
|
|
210
|
+
message,
|
|
211
|
+
});
|
|
212
|
+
exports.each.after && exports.each.after();
|
|
213
|
+
};
|
|
214
|
+
const notDeepStrictEqual = (actual, expected, message) => {
|
|
215
|
+
exports.each.before && exports.each.before();
|
|
216
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => nodeAssert.notDeepStrictEqual(actual, expected), {
|
|
217
|
+
message,
|
|
218
|
+
});
|
|
219
|
+
exports.each.after && exports.each.after();
|
|
220
|
+
};
|
|
221
|
+
const match = (value, regExp, message) => {
|
|
222
|
+
exports.each.before && exports.each.before();
|
|
223
|
+
(0, parseAsssetion_js_1.parseAssertion)(() => nodeAssert.match(value, regExp), {
|
|
224
|
+
message,
|
|
225
|
+
actual: 'Value',
|
|
226
|
+
expected: 'RegExp',
|
|
227
|
+
defaultMessage: 'Value should match regExp',
|
|
228
|
+
});
|
|
229
|
+
exports.each.after && exports.each.after();
|
|
230
|
+
};
|
|
171
231
|
const ifError = (value) => {
|
|
172
232
|
try {
|
|
233
|
+
exports.each.before && exports.each.before();
|
|
173
234
|
nodeAssert.ifError(value);
|
|
235
|
+
exports.each.after && exports.each.after();
|
|
174
236
|
}
|
|
175
237
|
catch (error) {
|
|
176
238
|
(0, parseAsssetion_js_1.parseAssertion)(() => {
|
|
@@ -202,7 +264,9 @@ function rejects(block, errorOrMessage, message) {
|
|
|
202
264
|
errorOrMessage instanceof RegExp ||
|
|
203
265
|
typeof errorOrMessage === 'object') {
|
|
204
266
|
try {
|
|
205
|
-
|
|
267
|
+
exports.each.before && exports.each.before();
|
|
268
|
+
yield nodeAssert.rejects(block, errorOrMessage);
|
|
269
|
+
exports.each.after && exports.each.after();
|
|
206
270
|
}
|
|
207
271
|
catch (error) {
|
|
208
272
|
(0, parseAsssetion_js_1.parseAssertion)(() => {
|
|
@@ -217,7 +281,9 @@ function rejects(block, errorOrMessage, message) {
|
|
|
217
281
|
else {
|
|
218
282
|
const msg = typeof errorOrMessage === 'string' ? errorOrMessage : undefined;
|
|
219
283
|
try {
|
|
220
|
-
|
|
284
|
+
exports.each.before && exports.each.before();
|
|
285
|
+
yield nodeAssert.rejects(block);
|
|
286
|
+
exports.each.after && exports.each.after();
|
|
221
287
|
}
|
|
222
288
|
catch (error_1) {
|
|
223
289
|
(0, parseAsssetion_js_1.parseAssertion)(() => {
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
type Control = {
|
|
2
|
+
pause: () => void;
|
|
3
|
+
continue: () => void;
|
|
4
|
+
reset: () => void;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* - ✅ Handling **global** and **external** services (_preparing a database, for example_)
|
|
8
|
+
* - ✅ It's made for **exclusive use** in combination with **Poku**'s **`assert`** methods
|
|
9
|
+
* - ❌ Changing local variables values and states ([_use a mock instead_](https://poku.dev/docs/category/mock))
|
|
10
|
+
*
|
|
11
|
+
* ---
|
|
12
|
+
*
|
|
13
|
+
* ### Available methos:
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { assert, beforeEach } from 'poku';
|
|
17
|
+
*
|
|
18
|
+
* const before = beforeEach(() => {
|
|
19
|
+
* // preparing an external or global state
|
|
20
|
+
* };
|
|
21
|
+
*
|
|
22
|
+
* before.pause();
|
|
23
|
+
* before.continue();
|
|
24
|
+
* before.reset();
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare const beforeEach: (callback: () => unknown) => Control;
|
|
28
|
+
/**
|
|
29
|
+
* - ✅ Handling **global** and **external** services (_preparing a database, for example_)
|
|
30
|
+
* - ✅ It's made for **exclusive use** in combination with **Poku**'s **`assert`** methods
|
|
31
|
+
* - ❌ Changing local variables values and states ([_use a mock instead_](https://poku.dev/docs/category/mock))
|
|
32
|
+
*
|
|
33
|
+
* ---
|
|
34
|
+
*
|
|
35
|
+
* ### Available methos:
|
|
36
|
+
*
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { assert, afterEach } from 'poku';
|
|
39
|
+
*
|
|
40
|
+
* const after = afterEach(() => {
|
|
41
|
+
* // cleanup an external or global state
|
|
42
|
+
* };
|
|
43
|
+
*
|
|
44
|
+
* after.pause();
|
|
45
|
+
* after.continue();
|
|
46
|
+
* after.reset();
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare const afterEach: (callback: () => unknown) => Control;
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.afterEach = exports.beforeEach = void 0;
|
|
4
|
+
const assert_js_1 = require("../modules/assert.js");
|
|
5
|
+
const status = {
|
|
6
|
+
before: true,
|
|
7
|
+
after: true,
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* - ✅ Handling **global** and **external** services (_preparing a database, for example_)
|
|
11
|
+
* - ✅ It's made for **exclusive use** in combination with **Poku**'s **`assert`** methods
|
|
12
|
+
* - ❌ Changing local variables values and states ([_use a mock instead_](https://poku.dev/docs/category/mock))
|
|
13
|
+
*
|
|
14
|
+
* ---
|
|
15
|
+
*
|
|
16
|
+
* ### Available methos:
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { assert, beforeEach } from 'poku';
|
|
20
|
+
*
|
|
21
|
+
* const before = beforeEach(() => {
|
|
22
|
+
* // preparing an external or global state
|
|
23
|
+
* };
|
|
24
|
+
*
|
|
25
|
+
* before.pause();
|
|
26
|
+
* before.continue();
|
|
27
|
+
* before.reset();
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
const beforeEach = (callback) => {
|
|
31
|
+
assert_js_1.each.before = () => {
|
|
32
|
+
if (status.before)
|
|
33
|
+
callback();
|
|
34
|
+
};
|
|
35
|
+
const pause = () => {
|
|
36
|
+
status.before = false;
|
|
37
|
+
};
|
|
38
|
+
const continueFunc = () => {
|
|
39
|
+
status.before = true;
|
|
40
|
+
};
|
|
41
|
+
const reset = () => {
|
|
42
|
+
assert_js_1.each.before = undefined;
|
|
43
|
+
};
|
|
44
|
+
return { pause, continue: continueFunc, reset };
|
|
45
|
+
};
|
|
46
|
+
exports.beforeEach = beforeEach;
|
|
47
|
+
/**
|
|
48
|
+
* - ✅ Handling **global** and **external** services (_preparing a database, for example_)
|
|
49
|
+
* - ✅ It's made for **exclusive use** in combination with **Poku**'s **`assert`** methods
|
|
50
|
+
* - ❌ Changing local variables values and states ([_use a mock instead_](https://poku.dev/docs/category/mock))
|
|
51
|
+
*
|
|
52
|
+
* ---
|
|
53
|
+
*
|
|
54
|
+
* ### Available methos:
|
|
55
|
+
*
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { assert, afterEach } from 'poku';
|
|
58
|
+
*
|
|
59
|
+
* const after = afterEach(() => {
|
|
60
|
+
* // cleanup an external or global state
|
|
61
|
+
* };
|
|
62
|
+
*
|
|
63
|
+
* after.pause();
|
|
64
|
+
* after.continue();
|
|
65
|
+
* after.reset();
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
const afterEach = (callback) => {
|
|
69
|
+
assert_js_1.each.after = () => {
|
|
70
|
+
if (status.after)
|
|
71
|
+
callback();
|
|
72
|
+
};
|
|
73
|
+
const pause = () => {
|
|
74
|
+
status.after = false;
|
|
75
|
+
};
|
|
76
|
+
const continueFunc = () => {
|
|
77
|
+
status.after = true;
|
|
78
|
+
};
|
|
79
|
+
const reset = () => {
|
|
80
|
+
assert_js_1.each.after = undefined;
|
|
81
|
+
};
|
|
82
|
+
return { pause, continue: continueFunc, reset };
|
|
83
|
+
};
|
|
84
|
+
exports.afterEach = afterEach;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { Configs } from '../@types/list-files.js';
|
|
2
2
|
export declare const sanitizePath: (input: string, ensureTarget?: boolean) => string;
|
|
3
3
|
export declare const escapeRegExp: (string: string) => string;
|
|
4
|
+
export declare const isFile: (fullPath: string) => boolean;
|
|
5
|
+
export declare const isDir: (fullPath: string) => boolean;
|
|
4
6
|
export declare const listFiles: (dirPath: string, files?: string[], configs?: Configs) => string[];
|
|
5
7
|
export declare const publicListFiles: (targetDir: string, configs?: Configs) => string[];
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
var _a;
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.publicListFiles = exports.listFiles = exports.escapeRegExp = exports.sanitizePath = void 0;
|
|
7
|
+
exports.publicListFiles = exports.listFiles = exports.isDir = exports.isFile = exports.escapeRegExp = exports.sanitizePath = void 0;
|
|
8
8
|
const node_process_1 = __importDefault(require("process"));
|
|
9
9
|
const node_fs_1 = __importDefault(require("fs"));
|
|
10
10
|
const node_path_1 = __importDefault(require("path"));
|
|
@@ -19,6 +19,10 @@ const sanitizePath = (input, ensureTarget) => {
|
|
|
19
19
|
exports.sanitizePath = sanitizePath;
|
|
20
20
|
const escapeRegExp = (string) => string.replace(/[.*{}[\]\\]/g, '\\$&');
|
|
21
21
|
exports.escapeRegExp = escapeRegExp;
|
|
22
|
+
const isFile = (fullPath) => node_fs_1.default.statSync(fullPath).isFile();
|
|
23
|
+
exports.isFile = isFile;
|
|
24
|
+
const isDir = (fullPath) => node_fs_1.default.statSync(fullPath).isDirectory();
|
|
25
|
+
exports.isDir = isDir;
|
|
22
26
|
const envFilter = ((_a = node_process_1.default.env.FILTER) === null || _a === void 0 ? void 0 : _a.trim())
|
|
23
27
|
? new RegExp((0, exports.escapeRegExp)(node_process_1.default.env.FILTER), 'i')
|
|
24
28
|
: null;
|
|
@@ -41,7 +45,7 @@ const listFiles = (dirPath, files = [], configs) => {
|
|
|
41
45
|
continue;
|
|
42
46
|
if (exclude && exclude.some((regex) => regex.test(fullPath)))
|
|
43
47
|
continue;
|
|
44
|
-
if (
|
|
48
|
+
if ((0, exports.isDir)(fullPath))
|
|
45
49
|
(0, exports.listFiles)(fullPath, files, configs);
|
|
46
50
|
else if (filter.test(fullPath))
|
|
47
51
|
files.push(fullPath);
|
package/lib/modules/poku.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Code } from '../@types/code.js';
|
|
2
2
|
import { Configs } from '../@types/poku.js';
|
|
3
|
-
export declare function poku(
|
|
3
|
+
export declare function poku(targetPaths: string | string[], configs: Configs & {
|
|
4
4
|
noExit: true;
|
|
5
5
|
}): Promise<Code>;
|
|
6
|
-
export declare function poku(
|
|
6
|
+
export declare function poku(targetPaths: string | string[], configs?: Configs): Promise<void>;
|
package/lib/modules/poku.js
CHANGED
|
@@ -19,10 +19,10 @@ const logs_js_1 = require("../helpers/logs.js");
|
|
|
19
19
|
const hr_js_1 = require("../helpers/hr.js");
|
|
20
20
|
const run_test_file_js_1 = require("../services/run-test-file.js");
|
|
21
21
|
const indentation_js_1 = require("../helpers/indentation.js");
|
|
22
|
-
function poku(
|
|
22
|
+
function poku(targetPaths, configs) {
|
|
23
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24
24
|
let code = 0;
|
|
25
|
-
const prepareDirs = (0, force_array_js_1.forceArray)(
|
|
25
|
+
const prepareDirs = (0, force_array_js_1.forceArray)(targetPaths);
|
|
26
26
|
const dirs = prepareDirs.length > 0 ? prepareDirs : ['./'];
|
|
27
27
|
const showLogs = !(0, logs_js_1.isQuiet)(configs);
|
|
28
28
|
if (configs === null || configs === void 0 ? void 0 : configs.parallel) {
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.afterEach = exports.beforeEach = void 0;
|
|
13
|
+
const node_os_1 = require("os");
|
|
14
|
+
const format_js_1 = require("../helpers/format.js");
|
|
15
|
+
const eachCore = (type, fileRelative, configs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
if (typeof (configs === null || configs === void 0 ? void 0 : configs[type]) !== 'function')
|
|
18
|
+
return true;
|
|
19
|
+
const functionName = (_a = configs[type]) === null || _a === void 0 ? void 0 : _a.name;
|
|
20
|
+
console.log(` ${format_js_1.format.dim(format_js_1.format.info('◯'))} ${format_js_1.format.dim(format_js_1.format.italic(`${configs[type]}: ${functionName !== configs[type] ? functionName : 'anonymous function'}`))}`);
|
|
21
|
+
try {
|
|
22
|
+
yield ((_b = configs[type]) === null || _b === void 0 ? void 0 : _b.call(configs));
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
console.log(format_js_1.format.bold(format_js_1.format.fail(` ✘ ${type} callback failed ${format_js_1.format.dim(`› ${configs[type]}`)}`)));
|
|
27
|
+
console.log(format_js_1.format.fail(` ├─ Who's trying to run this ${type}?${node_os_1.EOL} │ └─ ${format_js_1.format.underline(fileRelative)}`));
|
|
28
|
+
error instanceof Error &&
|
|
29
|
+
console.log(format_js_1.format.fail(` ├─ Message:${node_os_1.EOL} │ └─ ${error.message}`));
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
const beforeEach = (fileRelative, configs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
if (configs === null || configs === void 0 ? void 0 : configs.beforeEach)
|
|
35
|
+
return yield eachCore('beforeEach', fileRelative, configs);
|
|
36
|
+
return true;
|
|
37
|
+
});
|
|
38
|
+
exports.beforeEach = beforeEach;
|
|
39
|
+
const afterEach = (fileRelative, configs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
if (configs === null || configs === void 0 ? void 0 : configs.afterEach)
|
|
41
|
+
return yield eachCore('afterEach', fileRelative, configs);
|
|
42
|
+
return true;
|
|
43
|
+
});
|
|
44
|
+
exports.afterEach = afterEach;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Configs } from '../@types/poku.js';
|
|
2
|
-
type FileResults = {
|
|
2
|
+
export type FileResults = {
|
|
3
3
|
success: string[];
|
|
4
4
|
fail: string[];
|
|
5
5
|
};
|
|
6
6
|
export declare const fileResults: FileResults;
|
|
7
7
|
export declare const runTestFile: (filePath: string, configs?: Configs) => Promise<boolean>;
|
|
8
|
-
export {};
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
@@ -13,11 +22,12 @@ const indentation_js_1 = require("../helpers/indentation.js");
|
|
|
13
22
|
const format_js_1 = require("../helpers/format.js");
|
|
14
23
|
const logs_js_1 = require("../helpers/logs.js");
|
|
15
24
|
const remove_repeats_js_1 = require("../helpers/remove-repeats.js");
|
|
25
|
+
const each_js_1 = require("./each.js");
|
|
16
26
|
exports.fileResults = {
|
|
17
27
|
success: [],
|
|
18
28
|
fail: [],
|
|
19
29
|
};
|
|
20
|
-
const runTestFile = (filePath, configs) => new Promise((resolve) => {
|
|
30
|
+
const runTestFile = (filePath, configs) => new Promise((resolve) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
31
|
const runtimeOptions = (0, runner_js_1.runner)(filePath, configs);
|
|
22
32
|
const runtime = runtimeOptions.shift();
|
|
23
33
|
const runtimeArguments = runtimeOptions.length > 1 ? [...runtimeOptions, filePath] : [filePath];
|
|
@@ -60,6 +70,9 @@ const runTestFile = (filePath, configs) => new Promise((resolve) => {
|
|
|
60
70
|
showLogs &&
|
|
61
71
|
console.log(`${indentation_js_1.indentation.test}${format_js_1.format.info(format_js_1.format.dim('●'))} ${format_js_1.format.dim(fileRelative)}`);
|
|
62
72
|
}
|
|
73
|
+
if (!(yield (0, each_js_1.beforeEach)(fileRelative, configs)))
|
|
74
|
+
return false;
|
|
75
|
+
// Export spawn helper is not an option
|
|
63
76
|
const child = (0, node_child_process_1.spawn)(runtime, runtimeArguments, {
|
|
64
77
|
stdio: ['inherit', 'pipe', 'pipe'],
|
|
65
78
|
shell: false,
|
|
@@ -67,20 +80,22 @@ const runTestFile = (filePath, configs) => new Promise((resolve) => {
|
|
|
67
80
|
});
|
|
68
81
|
child.stdout.on('data', stdOut);
|
|
69
82
|
child.stderr.on('data', stdOut);
|
|
70
|
-
child.on('close', (code) => {
|
|
83
|
+
child.on('close', (code) => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
84
|
if (showLogs)
|
|
72
85
|
log();
|
|
86
|
+
if (!(yield (0, each_js_1.afterEach)(fileRelative, configs)))
|
|
87
|
+
return false;
|
|
73
88
|
const result = code === 0;
|
|
74
89
|
if (result)
|
|
75
90
|
exports.fileResults.success.push(fileRelative);
|
|
76
91
|
else
|
|
77
92
|
exports.fileResults.fail.push(fileRelative);
|
|
78
93
|
resolve(result);
|
|
79
|
-
});
|
|
94
|
+
}));
|
|
80
95
|
child.on('error', (err) => {
|
|
81
96
|
console.log(`Failed to start test: ${filePath}`, err);
|
|
82
97
|
exports.fileResults.fail.push(fileRelative);
|
|
83
98
|
resolve(false);
|
|
84
99
|
});
|
|
85
|
-
});
|
|
100
|
+
}));
|
|
86
101
|
exports.runTestFile = runTestFile;
|
|
@@ -31,13 +31,14 @@ const runTests = (dir, configs) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
31
31
|
const cwd = node_process_1.default.cwd();
|
|
32
32
|
const testDir = node_path_1.default.join(cwd, (0, list_files_js_1.sanitizePath)(dir));
|
|
33
33
|
const currentDir = node_path_1.default.relative(cwd, testDir);
|
|
34
|
-
const
|
|
34
|
+
const isFile = (0, list_files_js_1.isFile)(testDir);
|
|
35
|
+
const files = isFile ? [testDir] : (0, list_files_js_1.listFiles)(testDir, undefined, configs);
|
|
35
36
|
const totalTests = files.length;
|
|
36
37
|
const showLogs = !(0, logs_js_1.isQuiet)(configs);
|
|
37
38
|
let passed = true;
|
|
38
39
|
if (showLogs) {
|
|
39
40
|
(0, hr_js_1.hr)();
|
|
40
|
-
console.log(`${format_js_1.format.bold('Directory:')} ${format_js_1.format.underline(`./${currentDir}`)}${node_os_1.EOL}`);
|
|
41
|
+
console.log(`${format_js_1.format.bold(isFile ? 'File:' : 'Directory:')} ${format_js_1.format.underline(`./${currentDir}`)}${node_os_1.EOL}`);
|
|
41
42
|
}
|
|
42
43
|
for (let i = 0; i < files.length; i++) {
|
|
43
44
|
const filePath = files[i];
|
|
@@ -66,7 +67,7 @@ exports.runTests = runTests;
|
|
|
66
67
|
const runTestsParallel = (dir, configs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
68
|
const cwd = node_process_1.default.cwd();
|
|
68
69
|
const testDir = node_path_1.default.join(cwd, dir);
|
|
69
|
-
const files = (0, list_files_js_1.listFiles)(testDir, undefined, configs);
|
|
70
|
+
const files = (0, list_files_js_1.isFile)(dir) ? [dir] : (0, list_files_js_1.listFiles)(testDir, undefined, configs);
|
|
70
71
|
const promises = files.map((filePath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
72
|
const testPassed = yield (0, run_test_file_js_1.runTestFile)(filePath, configs);
|
|
72
73
|
if (!testPassed) {
|