@aljazmc/testero 0.1.5 → 0.2.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 CHANGED
@@ -1,17 +1,97 @@
1
- ![Custom](https://img.shields.io/badge/project_status-not_working-red) ![Custom](https://img.shields.io/badge/breaking_changes-common-red) ![NPM Downloads](https://img.shields.io/npm/dy/%40aljazmc%2Ftestero) ![GitHub package.json version](https://img.shields.io/github/package-json/v/aljazmc/aljazmc?filename=packages%2Ftestero%2Fpackage.json&color=green) ![GitHub License](https://img.shields.io/github/license/aljazmc/aljazmc)
1
+ ![Custom](https://img.shields.io/badge/project_status-barely_working-yellow) ![Custom](https://img.shields.io/badge/breaking_changes-common-red) ![NPM Downloads](https://img.shields.io/npm/dm/%40aljazmc%2Ftestero) ![GitHub package.json version](https://img.shields.io/github/package-json/v/aljazmc/aljazmc?filename=packages%2Ftestero%2Fpackage.json&color=green) ![GitHub License](https://img.shields.io/github/license/aljazmc/aljazmc)
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
+
7
+ ## > usage
8
+
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
+ ```
17
+
18
+ Test files are written like for [Jest](https://jestjs.io), in JavaScript, TypeScript or JSX, with the same globals:
19
+
20
+ ```ts
21
+ import { add } from "../src/math.ts";
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.
6
87
 
7
88
  ## > achieved milestones
8
89
 
9
- - setup toolchain
10
- - continuous integration
11
- - continuous delivery
12
- - recent tools
90
+ - setup toolchain (with continuous integration and continuous delivery, using recent tools)
91
+ - Jest like globals, matchers, mocks, hooks, configuration and reports, running this repository's tests
13
92
 
14
93
  ## > planned milestones
15
94
 
16
- - robust main loop in OO TypeScript
17
-
95
+ - formidable test coverage
96
+ - module mocking, fake timers and snapshots
97
+ - parallel test files