@aljazmc/testero 0.1.6 → 0.2.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 +79 -8
- package/bin/main.js +2133 -5
- package/bin/types/arguments.d.ts +14 -0
- package/bin/types/collector.d.ts +37 -0
- package/bin/types/config.d.ts +6 -0
- package/bin/types/each.d.ts +11 -0
- package/bin/types/expect/assertion.d.ts +58 -0
- package/bin/types/expect/asymmetric.d.ts +49 -0
- package/bin/types/expect/equality.d.ts +15 -0
- package/bin/types/expect/expect.d.ts +33 -0
- package/bin/types/expect/format.d.ts +10 -0
- package/bin/types/expect/matchers.d.ts +15 -0
- package/bin/types/globals.d.ts +12 -0
- package/bin/types/mock.d.ts +49 -0
- package/bin/types/reporter.d.ts +27 -0
- package/bin/types/rules.d.ts +19 -0
- package/bin/types/runner.d.ts +31 -0
- package/bin/types/suite.d.ts +41 -0
- package/bin/types/testero.d.ts +19 -4
- package/bin/types/transformer.d.ts +17 -0
- package/package.json +13 -7
package/README.md
CHANGED
|
@@ -1,15 +1,86 @@
|
|
|
1
|
-
    
|
|
2
2
|
|
|
3
|
-
# testero
|
|
3
|
+
# > testero
|
|
4
4
|
|
|
5
|
-
A simple test runner. Easy to understand, easy to customize and easy to extend.
|
|
5
|
+
A simple, Jest-like test runner. Easy to understand, easy to customize and easy to extend.
|
|
6
6
|
|
|
7
|
-
## >
|
|
7
|
+
## > usage
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
```sh
|
|
10
|
+
testero # run every test file
|
|
11
|
+
testero math unit/ # run test files whose path matches a pattern
|
|
12
|
+
testero -t "adds numbers" # run tests whose full name matches
|
|
13
|
+
testero --verbose --bail # list every test, stop at the first failing file
|
|
14
|
+
testero --listTests # print the test files instead of running them
|
|
15
|
+
testero --help
|
|
16
|
+
```
|
|
10
17
|
|
|
11
|
-
|
|
18
|
+
Test files are written like for [Jest](https://jestjs.io), in JavaScript, TypeScript or JSX, with the same globals:
|
|
12
19
|
|
|
13
|
-
|
|
14
|
-
|
|
20
|
+
```ts
|
|
21
|
+
import { add } from "../src/math.ts";
|
|
15
22
|
|
|
23
|
+
describe("add", () => {
|
|
24
|
+
beforeEach(() => testero.clearAllMocks()); // `jest` works too
|
|
25
|
+
|
|
26
|
+
test("adds numbers", () => {
|
|
27
|
+
expect(add(1, 2)).toBe(3);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test.each([
|
|
31
|
+
[1, 1, 2],
|
|
32
|
+
[2, 2, 4],
|
|
33
|
+
])("%i + %i = %i", (a, b, sum) => {
|
|
34
|
+
expect(add(a, b)).toBe(sum);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("calls back", async () => {
|
|
38
|
+
const callback = testero.fn().mockResolvedValue("done");
|
|
39
|
+
await expect(callback()).resolves.toBe("done");
|
|
40
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
- `describe`, `test` and `it`, with `.only`, `.skip`, `.each` and `test.todo`, also `fdescribe`, `xdescribe`, `fit`, `xit` and `xtest`
|
|
46
|
+
- `beforeAll`, `afterAll`, `beforeEach` and `afterEach`; tests and hooks may return promises or take a `done` callback, and time out
|
|
47
|
+
- `expect` with Jest's matchers, `.not`, `.resolves`, `.rejects`, `expect.extend`, `expect.assertions` and `expect.hasAssertions`
|
|
48
|
+
- asymmetric matchers: `expect.any`, `expect.anything`, `expect.objectContaining`, `expect.arrayContaining`, `expect.stringContaining`, `expect.stringMatching`, `expect.closeTo` and their `expect.not` variants
|
|
49
|
+
- `testero.fn`, `testero.spyOn`, `testero.clearAllMocks`, `testero.resetAllMocks`, `testero.restoreAllMocks` and `testero.setTimeout`, also as `jest`; imports from `@jest/globals` get the same functions
|
|
50
|
+
|
|
51
|
+
Failures show the message, a diff of expected and received values, and the code where they happened.
|
|
52
|
+
|
|
53
|
+
Settings follow Jest's names and defaults. Override them with `testero.config.ts` or `testero.config.js` in the current directory; objects are merged deeply, anything else (like `ignore`) replaces the default:
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
export default {
|
|
57
|
+
ignore: [".git", "node_modules"],
|
|
58
|
+
rules: {
|
|
59
|
+
// globs of test files in order, the last match decides, "!" excludes
|
|
60
|
+
testMatch: [
|
|
61
|
+
"**/__tests__/**/*.{js,jsx,ts,tsx,mjs,cjs,mts,cts}",
|
|
62
|
+
"**/*.{spec,test}.{js,jsx,ts,tsx,mjs,cjs,mts,cts}",
|
|
63
|
+
],
|
|
64
|
+
testTimeout: 5000, // milliseconds a test or hook may take
|
|
65
|
+
bail: false, // stop after the first failing test file
|
|
66
|
+
verbose: false, // list every test
|
|
67
|
+
passWithNoTests: false, // succeed when there are no test files
|
|
68
|
+
clearMocks: false, // clear the calls of every mock before each test
|
|
69
|
+
resetMocks: false, // also remove their implementations
|
|
70
|
+
restoreMocks: false, // also restore spies to the originals
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## > how it works
|
|
76
|
+
|
|
77
|
+
- `src/transformer.ts`: bundles each test file and the local files it imports with [esbuild](https://esbuild.github.io), the only dependency, into one module; installed packages stay external and the globals are injected where the file uses them
|
|
78
|
+
- `src/collector.ts`: the `describe`, `test` and hook functions, collecting what a test file declares into a tree of suites (`src/suite.ts`)
|
|
79
|
+
- `src/runner.ts`: runs the tests of the tree in order, with focus, skips, hooks, timeouts and `done` callbacks
|
|
80
|
+
- `src/expect`: the `expect` function, its matchers, deep equality and value printing with diffs
|
|
81
|
+
- `src/mock.ts`: mock functions and spies
|
|
82
|
+
- `src/reporter.ts`: prints results like Jest's default reporter
|
|
83
|
+
- `src/testero.ts`: finds the test files and runs them one after another
|
|
84
|
+
- `@aljazmc/config` (`shared/config`): loads `testero.config.ts`, finds the files and matches `testMatch`, shared with every package
|
|
85
|
+
|
|
86
|
+
Each test file is bundled on its own, so it gets fresh copies of the files it imports, and spies are restored after it. Test files run one after another in one process, without workers, module mocking, fake timers, snapshots or coverage.
|