beartest-js 5.0.4 → 6.0.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/.prettierrc +5 -0
- package/README.md +5 -5
- package/beartest.js +29 -24
- package/index.d.ts +15 -19
- package/package.json +3 -3
- package/testrunner.js +1 -5
package/.prettierrc
ADDED
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<img src="https://beartest-js.s3.amazonaws.com/beartest-logo.png" width="400">
|
|
2
2
|
|
|
3
|
-
_Beartest_ is an extremely simple JavaScript test runner inspired by Baretest and Jest. It has a tiny footprint while maintaining a familiar API.
|
|
3
|
+
_Beartest_ is an extremely simple JavaScript test runner inspired by Baretest, Playwright, and Jest. It has a tiny footprint while maintaining a familiar API.
|
|
4
4
|
|
|
5
5
|
### Install
|
|
6
6
|
|
|
@@ -27,15 +27,15 @@ _Beartest_ implements the following functions `describe`, `it`, `beforeAll`, `be
|
|
|
27
27
|
### Example
|
|
28
28
|
|
|
29
29
|
```javascript
|
|
30
|
-
import {
|
|
30
|
+
import { test } from "beartest-js";
|
|
31
31
|
import assert from "assert";
|
|
32
32
|
|
|
33
|
-
describe("Math Testing", () => {
|
|
34
|
-
|
|
33
|
+
test.describe("Math Testing", () => {
|
|
34
|
+
test("should add correctly", async () => {
|
|
35
35
|
assert.strictEqual(1 + 2, 3);
|
|
36
36
|
});
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
test("should subtract correctly", async () => {
|
|
39
39
|
assert.strictEqual(3 - 2, 1);
|
|
40
40
|
});
|
|
41
41
|
});
|
package/beartest.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const rgb = require(
|
|
1
|
+
const rgb = require("barecolor");
|
|
2
2
|
|
|
3
3
|
async function RunSerially(fnArray) {
|
|
4
4
|
for (const fn of fnArray) {
|
|
@@ -6,11 +6,12 @@ async function RunSerially(fnArray) {
|
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
const suiteStack = [];
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
let testRunPromise = Promise.resolve();
|
|
10
|
+
const top = () => (suiteStack.length ? suiteStack[suiteStack.length - 1] : null);
|
|
11
|
+
const topSafe = () => (suiteStack.length ? suiteStack[suiteStack.length - 1] : makeSuite(""));
|
|
11
12
|
|
|
12
13
|
const registerTest = (suite, name, fn) => async () => {
|
|
13
|
-
const prefix =
|
|
14
|
+
const prefix = " ".repeat(suite.depth);
|
|
14
15
|
try {
|
|
15
16
|
await suite.beforeEach();
|
|
16
17
|
await fn();
|
|
@@ -25,9 +26,9 @@ const registerTest = (suite, name, fn) => async () => {
|
|
|
25
26
|
};
|
|
26
27
|
|
|
27
28
|
async function runSuite(suite) {
|
|
28
|
-
const prefix =
|
|
29
|
+
const prefix = " ".repeat(suite.depth);
|
|
29
30
|
const tests = suite.only.length > 0 ? suite.only : suite.tests;
|
|
30
|
-
rgb.cyanln(prefix + suite.headline +
|
|
31
|
+
rgb.cyanln(prefix + suite.headline + " ");
|
|
31
32
|
try {
|
|
32
33
|
await suite.beforeAll();
|
|
33
34
|
await RunSerially(tests);
|
|
@@ -36,7 +37,7 @@ async function runSuite(suite) {
|
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
function makeSuite(headline, only = false, fn = null) {
|
|
40
41
|
const parent = top();
|
|
41
42
|
const self = {
|
|
42
43
|
depth: parent ? parent.depth + 1 : 0,
|
|
@@ -65,29 +66,33 @@ async function suite(headline, fn, only = false) {
|
|
|
65
66
|
if (parent && only) parent.only.push(() => runSuite(self));
|
|
66
67
|
if (parent && !only) parent.tests.push(() => runSuite(self));
|
|
67
68
|
suiteStack.push(self);
|
|
68
|
-
fn();
|
|
69
|
-
suiteStack.pop();
|
|
69
|
+
if (fn) fn();
|
|
70
|
+
if (fn) suiteStack.pop();
|
|
70
71
|
if (self.depth === 0) {
|
|
71
|
-
|
|
72
|
+
const timeoutPromise = new Promise((resolve) => setTimeout(resolve, 0));
|
|
73
|
+
testRunPromise = timeoutPromise.then(() => runSuite(self));
|
|
72
74
|
}
|
|
75
|
+
return self;
|
|
73
76
|
}
|
|
74
77
|
|
|
75
|
-
const describe = (headline, fn) =>
|
|
78
|
+
const describe = (headline, fn) => makeSuite(headline, false, fn);
|
|
76
79
|
describe.skip = () => {};
|
|
77
|
-
describe.only = (headline, fn) =>
|
|
78
|
-
const it = (name, fn) =>
|
|
79
|
-
it.only = (name, fn) =>
|
|
80
|
+
describe.only = (headline, fn) => makeSuite(headline, true, fn);
|
|
81
|
+
const it = (name, fn) => topSafe().tests.push(registerTest(topSafe(), name, fn));
|
|
82
|
+
it.only = (name, fn) => topSafe().only.push(registerTest(topSafe(), name, fn));
|
|
80
83
|
it.skip = () => {};
|
|
81
|
-
const beforeAll = (fn) =>
|
|
82
|
-
const afterAll = (fn) =>
|
|
83
|
-
const beforeEach = (fn) =>
|
|
84
|
-
const afterEach = (fn) =>
|
|
84
|
+
const beforeAll = (fn) => topSafe().beforeAllHooks.push(fn);
|
|
85
|
+
const afterAll = (fn) => topSafe().afterAllHooks.push(fn);
|
|
86
|
+
const beforeEach = (fn) => topSafe().beforeEachHooks.push(fn);
|
|
87
|
+
const afterEach = (fn) => topSafe().afterEachHooks.push(fn);
|
|
85
88
|
|
|
86
89
|
module.exports = {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
test: Object.assign(it, {
|
|
91
|
+
describe,
|
|
92
|
+
beforeAll,
|
|
93
|
+
afterAll,
|
|
94
|
+
beforeEach,
|
|
95
|
+
afterEach,
|
|
96
|
+
}),
|
|
97
|
+
runner: { waitForTests: () => testRunPromise },
|
|
93
98
|
};
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
type
|
|
1
|
+
type testFn = (name: string, fn: () => unknown) => void;
|
|
2
|
+
|
|
3
|
+
type test = testFn & {
|
|
4
|
+
skip: testFn;
|
|
5
|
+
only: testFn;
|
|
6
|
+
describe: testFn & { skip: testFn; only: testFn };
|
|
7
|
+
beforeAll(fn: () => unknown): void;
|
|
8
|
+
afterAll(fn: () => unknown): void;
|
|
9
|
+
beforeEach(fn: () => unknown): void;
|
|
10
|
+
afterEach(fn: () => unknown): void;
|
|
11
|
+
};
|
|
2
12
|
|
|
3
13
|
type Describe = (headline: string, fn: () => void) => Promise<boolean>;
|
|
4
14
|
type It = test & { only: test; skip: test };
|
|
@@ -7,21 +17,7 @@ type AfterAll = (fn: () => void | Promise<void>) => void;
|
|
|
7
17
|
type BeforeEach = (fn: () => void | Promise<void>) => void;
|
|
8
18
|
type AfterEach = (fn: () => void | Promise<void>) => void;
|
|
9
19
|
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export declare const afterAll: AfterAll;
|
|
15
|
-
export declare const beforeEach: BeforeEach;
|
|
16
|
-
export declare const afterEach: AfterEach;
|
|
17
|
-
|
|
18
|
-
interface BearTest {
|
|
19
|
-
describe: Describe;
|
|
20
|
-
it: It;
|
|
21
|
-
beforeAll: BeforeAll;
|
|
22
|
-
afterAll: AfterAll;
|
|
23
|
-
beforeEach: BeforeEach;
|
|
24
|
-
afterEach: AfterEach;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export default BearTest;
|
|
20
|
+
export declare const test: test;
|
|
21
|
+
export declare const runner: {
|
|
22
|
+
waitForTests: Promise<void>;
|
|
23
|
+
};
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "beartest-js",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "Bear Bones Testing",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/rubber-duck-software/beartest.git"
|
|
8
8
|
},
|
|
9
|
-
"types": "index.d.ts",
|
|
10
|
-
"main": "index.js",
|
|
9
|
+
"types": "./index.d.ts",
|
|
10
|
+
"main": "./index.js",
|
|
11
11
|
"bin": {
|
|
12
12
|
"beartest": "testrunner.js"
|
|
13
13
|
},
|
package/testrunner.js
CHANGED
|
@@ -2,17 +2,13 @@
|
|
|
2
2
|
const beartest = require("./beartest");
|
|
3
3
|
const glob = require("tiny-glob");
|
|
4
4
|
|
|
5
|
-
const tests = [];
|
|
6
|
-
const describe = beartest.describe;
|
|
7
|
-
beartest.describe = (headline, fn) => tests.push(describe(headline, fn));
|
|
8
|
-
|
|
9
5
|
async function runTests() {
|
|
10
6
|
try {
|
|
11
7
|
const globStr = process.argv[2] || "**/*.test.*";
|
|
12
8
|
const files = await glob(globStr, { absolute: true });
|
|
13
9
|
for (const file of files) {
|
|
14
10
|
require(file);
|
|
15
|
-
await
|
|
11
|
+
await beartest.runner.waitForTests();
|
|
16
12
|
}
|
|
17
13
|
process.exit(0);
|
|
18
14
|
} catch (e) {
|