beartest-js 3.1.1 → 5.0.1
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 +17 -9
- package/beartest.js +93 -0
- package/index.d.ts +10 -9
- package/index.js +1 -0
- package/package.json +3 -3
- package/testrunner.js +4 -4
- package/beartest.cjs +0 -52
- package/index.cjs +0 -3
package/README.md
CHANGED
|
@@ -18,24 +18,24 @@ Jest, Mocha, and similar testing frameworks are richly featured, broadly compati
|
|
|
18
18
|
|
|
19
19
|
### Compatibility
|
|
20
20
|
|
|
21
|
-
The Beartest test runner uses
|
|
21
|
+
The Beartest test runner uses common js to load files.
|
|
22
22
|
|
|
23
23
|
### Usage
|
|
24
24
|
|
|
25
|
-
_Beartest_ implements the following functions `describe`, `it`, `beforeAll`, `beforeEach`, `afterEach`, `afterAll`, `it.skip`, and `it.only`.
|
|
25
|
+
_Beartest_ implements the following functions `describe`, `it`, `beforeAll`, `beforeEach`, `afterEach`, `afterAll`, `it.skip`, and `it.only`. All provided functions work in a similar way as the corresponding functions in Jest.
|
|
26
26
|
|
|
27
27
|
### Example
|
|
28
28
|
|
|
29
29
|
```javascript
|
|
30
|
-
import describe from
|
|
31
|
-
import assert from
|
|
30
|
+
import { describe, it } from "beartest-js";
|
|
31
|
+
import assert from "assert";
|
|
32
32
|
|
|
33
|
-
describe(
|
|
34
|
-
it(
|
|
33
|
+
describe("Math Testing", () => {
|
|
34
|
+
it("should add correctly", async () => {
|
|
35
35
|
assert.strictEqual(1 + 2, 3);
|
|
36
36
|
});
|
|
37
37
|
|
|
38
|
-
it(
|
|
38
|
+
it("should subtract correctly", async () => {
|
|
39
39
|
assert.strictEqual(3 - 2, 1);
|
|
40
40
|
});
|
|
41
41
|
});
|
|
@@ -43,8 +43,16 @@ describe('Math Testing', ({ it }) => {
|
|
|
43
43
|
|
|
44
44
|
### Running Tests
|
|
45
45
|
|
|
46
|
-
Additionally, a very basic test runner is included. This test runner accepts a glob pattern as a command line argument. The test runner can be invoked with `beartest "glob-pattern"`.
|
|
46
|
+
Additionally, a very basic test runner is included. This test runner accepts a glob pattern as a command line argument. The test runner can be invoked with `yarn beartest "glob-pattern"`. By default, it will look for `**/*.test.js`.
|
|
47
|
+
|
|
48
|
+
Suggested package script:
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
"scripts": {
|
|
52
|
+
"test": "beartest"
|
|
53
|
+
}
|
|
54
|
+
```
|
|
47
55
|
|
|
48
56
|
## License
|
|
49
57
|
|
|
50
|
-
|
|
58
|
+
Licensed under [MIT](./LICENSE).
|
package/beartest.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
const rgb = require('barecolor');
|
|
2
|
+
|
|
3
|
+
async function RunSerially(fnArray) {
|
|
4
|
+
for (const fn of fnArray) {
|
|
5
|
+
await fn();
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
const suiteStack = [];
|
|
9
|
+
const top = () =>
|
|
10
|
+
suiteStack.length ? suiteStack[suiteStack.length - 1] : undefined;
|
|
11
|
+
|
|
12
|
+
const registerTest = (suite, name, fn) => async () => {
|
|
13
|
+
const prefix = ' '.repeat(suite.depth);
|
|
14
|
+
try {
|
|
15
|
+
await suite.beforeEach();
|
|
16
|
+
await fn();
|
|
17
|
+
rgb.green(prefix + `✓`);
|
|
18
|
+
rgb.gray(` ${name}\n`);
|
|
19
|
+
} catch (e) {
|
|
20
|
+
rgb.red(`\n${prefix}✗ ${name} \n\n`);
|
|
21
|
+
throw e;
|
|
22
|
+
} finally {
|
|
23
|
+
await suite.afterEach();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
async function runSuite(suite) {
|
|
28
|
+
const prefix = ' '.repeat(suite.depth);
|
|
29
|
+
const tests = suite.only.length > 0 ? suite.only : suite.tests;
|
|
30
|
+
rgb.cyanln(prefix + suite.headline + ' ');
|
|
31
|
+
try {
|
|
32
|
+
await suite.beforeAll();
|
|
33
|
+
await RunSerially(tests);
|
|
34
|
+
} finally {
|
|
35
|
+
await suite.afterAll();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function suite(headline, fn, only = false) {
|
|
40
|
+
const parent = top();
|
|
41
|
+
const self = {
|
|
42
|
+
depth: parent ? parent.depth + 1 : 0,
|
|
43
|
+
headline,
|
|
44
|
+
beforeAllHooks: [],
|
|
45
|
+
async beforeAll() {
|
|
46
|
+
await RunSerially(this.beforeAllHooks);
|
|
47
|
+
},
|
|
48
|
+
beforeEachHooks: [],
|
|
49
|
+
async beforeEach() {
|
|
50
|
+
if (parent) await parent.beforeEach();
|
|
51
|
+
await RunSerially(this.beforeEachHooks);
|
|
52
|
+
},
|
|
53
|
+
afterAllHooks: [],
|
|
54
|
+
async afterAll() {
|
|
55
|
+
await RunSerially(this.afterAllHooks);
|
|
56
|
+
},
|
|
57
|
+
afterEachHooks: [],
|
|
58
|
+
async afterEach() {
|
|
59
|
+
await RunSerially(this.afterEachHooks);
|
|
60
|
+
if (parent) await parent.afterEach();
|
|
61
|
+
},
|
|
62
|
+
tests: [],
|
|
63
|
+
only: [],
|
|
64
|
+
};
|
|
65
|
+
if (parent && only) parent.only.push(() => runSuite(self));
|
|
66
|
+
if (parent && !only) parent.tests.push(() => runSuite(self));
|
|
67
|
+
suiteStack.push(self);
|
|
68
|
+
fn();
|
|
69
|
+
suiteStack.pop();
|
|
70
|
+
if (self.depth === 0) {
|
|
71
|
+
await runSuite(self);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const describe = (headline, fn) => suite(headline, fn);
|
|
76
|
+
describe.skip = () => {};
|
|
77
|
+
describe.only = (headline, fn) => suite(headline, fn, true);
|
|
78
|
+
const it = (name, fn) => top().tests.push(registerTest(top(), name, fn));
|
|
79
|
+
it.only = (name, fn) => top().only.push(registerTest(top(), name, fn));
|
|
80
|
+
it.skip = () => {};
|
|
81
|
+
const beforeAll = (fn) => top().beforeAllHooks.push(fn);
|
|
82
|
+
const afterAll = (fn) => top().afterAllHooks.push(fn);
|
|
83
|
+
const beforeEach = (fn) => top().beforeEachHooks.push(fn);
|
|
84
|
+
const afterEach = (fn) => top().afterEachHooks.push(fn);
|
|
85
|
+
|
|
86
|
+
module.exports = {
|
|
87
|
+
describe,
|
|
88
|
+
it,
|
|
89
|
+
beforeAll,
|
|
90
|
+
afterAll,
|
|
91
|
+
beforeEach,
|
|
92
|
+
afterEach,
|
|
93
|
+
};
|
package/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
type test = (name: string, fn: () => void | Promise<void>) => void
|
|
1
|
+
type test = (name: string, fn: () => void | Promise<void>) => void;
|
|
2
2
|
|
|
3
|
-
declare function describe(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
beforeEach: (fn: () => void | Promise<void>) => void
|
|
8
|
-
afterEach: (fn: () => void | Promise<void>) => void
|
|
9
|
-
}) => void): Promise<boolean>
|
|
3
|
+
export declare function describe(
|
|
4
|
+
headline: string,
|
|
5
|
+
fn: () => void
|
|
6
|
+
): Promise<boolean>;
|
|
10
7
|
|
|
11
|
-
export
|
|
8
|
+
export declare const it: test & { only: test; skip: test };
|
|
9
|
+
export declare function beforeAll(fn: () => void | Promise<void>): void;
|
|
10
|
+
export declare function afterAll(fn: () => void | Promise<void>): void;
|
|
11
|
+
export declare function beforeEach(fn: () => void | Promise<void>): void;
|
|
12
|
+
export declare function afterEach(fn: () => void | Promise<void>): void;
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require("./beartest.js");
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "beartest-js",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
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
9
|
"types": "index.d.ts",
|
|
10
|
-
"module": "index.
|
|
10
|
+
"module": "index.js",
|
|
11
11
|
"bin": {
|
|
12
12
|
"beartest": "testrunner.js"
|
|
13
13
|
},
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"url": "https://github.com/rubber-duck-software/beartest/issues"
|
|
23
23
|
},
|
|
24
24
|
"homepage": "https://github.com/rubber-duck-software/beartest#readme",
|
|
25
|
-
"main": "index.
|
|
25
|
+
"main": "index.js",
|
|
26
26
|
"devDependencies": {},
|
|
27
27
|
"scripts": {
|
|
28
28
|
"test": "echo \"Error: no test specified\" && exit 1"
|
package/testrunner.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const beartest = require("./beartest");
|
|
3
|
+
const glob = require("tiny-glob");
|
|
4
4
|
|
|
5
5
|
const tests = [];
|
|
6
6
|
const describe = beartest.describe;
|
|
@@ -8,10 +8,10 @@ beartest.describe = (headline, fn) => tests.push(describe(headline, fn));
|
|
|
8
8
|
|
|
9
9
|
async function runTests() {
|
|
10
10
|
try {
|
|
11
|
-
const globStr = process.argv[2] ||
|
|
11
|
+
const globStr = process.argv[2] || "**/*.test.*";
|
|
12
12
|
const files = await glob(globStr, { absolute: true });
|
|
13
13
|
for (const file of files) {
|
|
14
|
-
|
|
14
|
+
require(file);
|
|
15
15
|
await Promise.all(tests);
|
|
16
16
|
}
|
|
17
17
|
process.exit(0);
|
package/beartest.cjs
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
const rgb = require('barecolor');
|
|
2
|
-
|
|
3
|
-
async function describe(headline, fn) {
|
|
4
|
-
const suite = [];
|
|
5
|
-
const only = [];
|
|
6
|
-
let beforeAll = async () => {};
|
|
7
|
-
let afterAll = async () => {};
|
|
8
|
-
let beforeEach = async () => {};
|
|
9
|
-
let afterEach = async () => {};
|
|
10
|
-
const it = (name, fn) => suite.push({ name: name, fn: fn });
|
|
11
|
-
it.only = (name, fn) => only.push({ name: name, fn: fn });
|
|
12
|
-
it.skip = () => {};
|
|
13
|
-
|
|
14
|
-
fn({
|
|
15
|
-
it: it,
|
|
16
|
-
beforeAll: (fn) => {
|
|
17
|
-
beforeAll = fn;
|
|
18
|
-
},
|
|
19
|
-
afterAll: (fn) => {
|
|
20
|
-
afterAll = fn;
|
|
21
|
-
},
|
|
22
|
-
beforeEach: (fn) => {
|
|
23
|
-
beforeEach = fn;
|
|
24
|
-
},
|
|
25
|
-
afterEach: (fn) => {
|
|
26
|
-
afterEach = fn;
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const tests = only.length > 0 ? only : suite;
|
|
31
|
-
rgb.cyanln(headline + ' ');
|
|
32
|
-
|
|
33
|
-
await beforeAll();
|
|
34
|
-
for (const test of tests) {
|
|
35
|
-
try {
|
|
36
|
-
await beforeEach();
|
|
37
|
-
await test.fn();
|
|
38
|
-
rgb.green(`✓`);
|
|
39
|
-
rgb.gray(` ${test.name}\n`);
|
|
40
|
-
} catch (e) {
|
|
41
|
-
rgb.red(`\n✗ ${test.name} \n\n`);
|
|
42
|
-
throw e;
|
|
43
|
-
} finally {
|
|
44
|
-
await afterEach();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
await afterAll();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
module.exports = {
|
|
51
|
-
describe,
|
|
52
|
-
};
|
package/index.cjs
DELETED