@yaks/testing 0.0.0-stage → 0.2.36
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/LICENSE +202 -0
- package/README.md +427 -2
- package/_dist/assert.d.ts +40 -0
- package/_dist/assert.d.ts.map +1 -0
- package/_dist/choose.d.ts +39 -0
- package/_dist/choose.d.ts.map +1 -0
- package/_dist/clock.d.ts +8 -0
- package/_dist/clock.d.ts.map +1 -0
- package/_dist/deps.d.ts +113 -0
- package/_dist/deps.d.ts.map +1 -0
- package/_dist/examples.d.ts +69 -0
- package/_dist/examples.d.ts.map +1 -0
- package/_dist/find.d.ts +23 -0
- package/_dist/find.d.ts.map +1 -0
- package/_dist/kept.d.ts +27 -0
- package/_dist/kept.d.ts.map +1 -0
- package/_dist/lend.d.ts +15 -0
- package/_dist/lend.d.ts.map +1 -0
- package/_dist/main.d.ts +2 -0
- package/_dist/main.d.ts.map +1 -0
- package/_dist/mod.d.ts +45 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/names.d.ts +31 -0
- package/_dist/names.d.ts.map +1 -0
- package/_dist/own.d.ts +25 -0
- package/_dist/own.d.ts.map +1 -0
- package/_dist/reads.d.ts +8 -0
- package/_dist/reads.d.ts.map +1 -0
- package/_dist/suite.d.ts +82 -0
- package/_dist/suite.d.ts.map +1 -0
- package/_dist/typist.d.ts +24 -0
- package/_dist/typist.d.ts.map +1 -0
- package/_dist/wait.d.ts +21 -0
- package/_dist/wait.d.ts.map +1 -0
- package/assert.js +114 -0
- package/assert.js.map +1 -0
- package/assert.ts +143 -0
- package/choose.js +197 -0
- package/choose.js.map +1 -0
- package/choose.ts +327 -0
- package/clock.js +45 -0
- package/clock.js.map +1 -0
- package/clock.ts +60 -0
- package/deno.json +1 -0
- package/deps.js +868 -0
- package/deps.js.map +1 -0
- package/deps.ts +1004 -0
- package/drive.js +43 -0
- package/drive.js.map +1 -0
- package/drive.ts +41 -0
- package/examples.js +279 -0
- package/examples.js.map +1 -0
- package/examples.ts +380 -0
- package/find.js +86 -0
- package/find.js.map +1 -0
- package/find.ts +102 -0
- package/kept.js +128 -0
- package/kept.js.map +1 -0
- package/kept.ts +146 -0
- package/lend.js +30 -0
- package/lend.js.map +1 -0
- package/lend.ts +31 -0
- package/load.js +106 -0
- package/load.js.map +1 -0
- package/load.ts +139 -0
- package/main.js +214 -0
- package/main.js.map +1 -0
- package/main.ts +217 -0
- package/mod.js +45 -0
- package/mod.js.map +1 -0
- package/mod.ts +55 -0
- package/names.js +209 -0
- package/names.js.map +1 -0
- package/names.ts +204 -0
- package/own.js +109 -0
- package/own.js.map +1 -0
- package/own.ts +136 -0
- package/package.json +56 -4
- package/reads.js +88 -0
- package/reads.js.map +1 -0
- package/reads.ts +98 -0
- package/run.js +306 -0
- package/run.js.map +1 -0
- package/run.ts +405 -0
- package/suite.js +191 -0
- package/suite.js.map +1 -0
- package/suite.ts +224 -0
- package/typist.js +74 -0
- package/typist.js.map +1 -0
- package/typist.ts +79 -0
- package/wait.js +34 -0
- package/wait.js.map +1 -0
- package/wait.ts +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Jeff Peterson
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,428 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @yaks/testing
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Declare tests, check their results, and run test modules and examples in one
|
|
4
|
+
runtime. The runner skips files whose dependencies have not changed since they
|
|
5
|
+
passed.
|
|
6
|
+
|
|
7
|
+
An **assertion** checks a value and throws when it does not meet the
|
|
8
|
+
expectation. A **test** is a named function that fails by throwing or rejecting.
|
|
9
|
+
A **test module** is a file named `*_test.ts` (also `.js`, `.tsx`, `.jsx`,
|
|
10
|
+
`.mts`, `.mjs`, `.cts` or `.cjs`) that declares tests. A **suite** groups tests
|
|
11
|
+
under one name and supplies assertions to its body. A **tag** is a string used
|
|
12
|
+
to select tests, such as `'math'`.
|
|
13
|
+
|
|
14
|
+
An **example** is code in a Markdown fence, a module's doc comment fence, or a
|
|
15
|
+
module's doctest. A **doctest** is a `///` line that checks an expression or
|
|
16
|
+
declares a statement shared by the module's doctests. A **page** is a Markdown
|
|
17
|
+
file or a module containing examples. The **runner** is `@yaks/testing/main`: it
|
|
18
|
+
loads test modules and pages and runs their tests in one runtime.
|
|
19
|
+
|
|
20
|
+
## A complete test module
|
|
21
|
+
|
|
22
|
+
A module declares behavior through `test` or `suite`. The suite's clauses
|
|
23
|
+
inherit its tag; `it.skip` declares a skipped test.
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { equal, suite, test } from '@yaks/testing'
|
|
27
|
+
|
|
28
|
+
test('two and two', () => equal(2 + 2, 4), { tags: ['math'] })
|
|
29
|
+
suite('sum', ({ it, equal }) => {
|
|
30
|
+
it('adds', () => equal([1, 2].reduce((a, b) => a + b, 0), 3))
|
|
31
|
+
it.skip('later', () => {
|
|
32
|
+
throw new Error('skipped')
|
|
33
|
+
})
|
|
34
|
+
}, { tags: ['math'] })
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
From this repository, `deno task test` selects tests through the dependency
|
|
38
|
+
graph and recorded reads. It keeps changed tests and their closest consumers,
|
|
39
|
+
then uses what remains of the six-second budget for farther consumers. Main's CI
|
|
40
|
+
runs the full suite after the push. The closing line counts deferred files. It
|
|
41
|
+
applies formatting to changed files, lints changed code, checks the public API
|
|
42
|
+
of each changed package for slow types, and checks the types of the modules a
|
|
43
|
+
change reaches, those changed, those importing one, and those of their package
|
|
44
|
+
importing one however far, with their doc comment examples
|
|
45
|
+
(`deno task check:types` alone); main CI checks every module after the push
|
|
46
|
+
(`--all`). Paths and tags narrow a run while iterating; the finished change uses
|
|
47
|
+
the no-path command to include its consumers. Tests run in process; page
|
|
48
|
+
behavior uses linkedom, and terminal behavior uses @yaks/tui's `lay`. There are
|
|
49
|
+
no browser tests or slow platform tier.
|
|
50
|
+
|
|
51
|
+
## Exports
|
|
52
|
+
|
|
53
|
+
| Export | Provides |
|
|
54
|
+
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
55
|
+
| `@yaks/testing` | `test`, `suite`, `equal`, `ok`, `match`, `throws`, `tick`, `until`, `typist`, `clock`, `own`, `waits`; types `Test`, `Options`, `It`, `Spec`, `Wait`, `Clock`, `Looks` |
|
|
56
|
+
| `@yaks/testing/own` | `own`, `waits`, `held`, `started`: a process's own time, for a coordinator that imports no tests |
|
|
57
|
+
| `@yaks/testing/find` | `tested`, `paged`, `walk`, `examples`, `find` |
|
|
58
|
+
| `@yaks/testing/examples` | `fences`, `doctests`, `typed`, `exported`, `declared`: a page's examples, compiled to run as tests or to type-check |
|
|
59
|
+
| `@yaks/testing/choose` | `choose`: which of a run's files run, and each one's key |
|
|
60
|
+
| `@yaks/testing/deps` | `survey`, `key`, `shared`, `proof`, `seal`, `digest`, `named`, `graph`, `remembered`; the pass record: `passed`, `remember`, `forget`, `recall`, `note`, `took`, `tally` |
|
|
61
|
+
| `@yaks/testing/reads` | `observe`, `path`: file reads and computed module loads seen at their boundaries |
|
|
62
|
+
| `@yaks/testing/main` | The Deno runner entry point |
|
|
63
|
+
|
|
64
|
+
## Declaring tests
|
|
65
|
+
|
|
66
|
+
`test(name, body, { tags, skip })` declares a test. `suite(name, body, options)`
|
|
67
|
+
passes `it` and the assertions to its body. Each clause's name starts with the
|
|
68
|
+
suite's name, its tags combine with the suite's tags, and either one's `skip`
|
|
69
|
+
skips the clause. If a suite's body throws while declaring tests, it declares a
|
|
70
|
+
failing test instead.
|
|
71
|
+
|
|
72
|
+
`cleanup(done)` asks for `done` once the running test ends, last asked first,
|
|
73
|
+
inside the test's time: a fixture that opens something closes it there, and
|
|
74
|
+
nothing it left running reaches the next test. A cleanup that throws fails the
|
|
75
|
+
test. Asked outside a test, it is the file's.
|
|
76
|
+
|
|
77
|
+
`afterAll(done)` asks for `done` once the file the runner loaded has run its
|
|
78
|
+
tests, whichever of them asks. A runtime keeps every module it loads and
|
|
79
|
+
everything they hold, so what a file opens for all its tests (a shared kernel,
|
|
80
|
+
say) closes there, rather than living on beside every file loaded after. The
|
|
81
|
+
file's end runs as one more test of it, `<path> ends`, said only when it fails.
|
|
82
|
+
|
|
83
|
+
`kept(done)` asks for `done` once the runtime needs back the memory it holds
|
|
84
|
+
(past `--full`), or else once its files have run, rather than once the file that
|
|
85
|
+
asked ends: a fixture that costs more to make than to keep, such as a kernel,
|
|
86
|
+
serves every file loaded after it until then. It ends as one more test of the
|
|
87
|
+
file that asked last, `<path> releases`, said only when it fails.
|
|
88
|
+
|
|
89
|
+
Outside the runner, declarations register with `Deno.test` when it is available.
|
|
90
|
+
In a runtime without `Deno.test`, declarations need the runner's collection
|
|
91
|
+
mechanism to be executed.
|
|
92
|
+
|
|
93
|
+
## Assertions
|
|
94
|
+
|
|
95
|
+
An **assertion** checks a value and throws when it does not meet the
|
|
96
|
+
expectation. `equal` checks deep equality, `ok` checks truthiness, and `match`
|
|
97
|
+
checks a partial pattern. Each returns the checked value. `throws` awaits a
|
|
98
|
+
function, checks that it throws or rejects, and returns the error. Its optional
|
|
99
|
+
message is a substring or a regular expression.
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import { equal, match, ok, throws } from '@yaks/testing'
|
|
103
|
+
|
|
104
|
+
equal({ values: [1, 2] }, { values: [1, 2] })
|
|
105
|
+
equal(ok([1, 2].find((n) => n == 2)), 2)
|
|
106
|
+
let person = { name: 'Ada', tags: ['a', 'b'], born: new Date(0) }
|
|
107
|
+
equal(match(person, { name: /^A/, tags: ['a'], born: Date }), person)
|
|
108
|
+
let error = await throws(async () => {
|
|
109
|
+
throw new Error('unclosed quote')
|
|
110
|
+
}, /quote/)
|
|
111
|
+
match(error, Error)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
A `match` pattern checks the keys it names and array items at their indices.
|
|
115
|
+
Regular expressions check a value's text; classes check instances. Empty objects
|
|
116
|
+
and arrays require empty values. Other values, including class instances and
|
|
117
|
+
arrow functions, compare by deep equality.
|
|
118
|
+
|
|
119
|
+
A linkedom node inspects as its markup. `assertEquals` from `@std/assert`
|
|
120
|
+
formats a value with `Deno.inspect`, which would otherwise walk the node's
|
|
121
|
+
document; a failure shows the markup and returns at once.
|
|
122
|
+
|
|
123
|
+
## Waiting
|
|
124
|
+
|
|
125
|
+
`tick` yields one macrotask. `until` polls a function until its return value is
|
|
126
|
+
truthy, then returns that value; a rejected or thrown error propagates. It
|
|
127
|
+
accepts `timeout` (default 2000 ms), `poll` (default 5 ms), a `label` for the
|
|
128
|
+
timeout error, and the `clock` it keeps both by: by default the test's own time
|
|
129
|
+
(below) and the runtime's timers, or a test's own (see
|
|
130
|
+
[Controlling time](#controlling-time)). A label function is evaluated when the
|
|
131
|
+
timeout occurs.
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
import { equal, throws, tick, until } from '@yaks/testing'
|
|
135
|
+
|
|
136
|
+
let ready = ''
|
|
137
|
+
setTimeout(() => ready = 'ready')
|
|
138
|
+
await tick()
|
|
139
|
+
equal(await until(() => ready, { label: 'ready' }), 'ready')
|
|
140
|
+
let attempts = 0
|
|
141
|
+
await throws(() =>
|
|
142
|
+
until(() => ++attempts && false, {
|
|
143
|
+
timeout: 0,
|
|
144
|
+
label: () => `${attempts} attempts`,
|
|
145
|
+
}), '1 attempts')
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
A timeout counts the test's **own time**: the wall clock less what the box kept
|
|
149
|
+
the test's runtime, and every process it started, waiting for a CPU. `own(pid)`
|
|
150
|
+
is that clock for a process and every process it started (this one by default),
|
|
151
|
+
read from Linux's /proc; elsewhere it is the wall clock. A wait on something
|
|
152
|
+
that hangs (a server that never answers, a child that stopped) waits for no CPU,
|
|
153
|
+
so its own time keeps the wall clock's pace and the wait still fails; one only
|
|
154
|
+
slowed by a busy box is given the time it would have taken alone. Between two
|
|
155
|
+
looks, the box held the processes at least as long as their most-held thread
|
|
156
|
+
waited, and that is what each look takes off. The first look is 250 ms into a
|
|
157
|
+
wait (`every`) and the span before it counts whole, so a wait that ends sooner
|
|
158
|
+
costs nothing. `waits(pid)` is what a look reads: each thread's wait so far, in
|
|
159
|
+
ms.
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
import { equal, own } from '@yaks/testing'
|
|
163
|
+
|
|
164
|
+
// What a thread has waited at each look, and the wall clock at each reading.
|
|
165
|
+
let looks = [new Map([['main', 0]]), new Map([['main', 30]])]
|
|
166
|
+
let times = [0, 0, 100]
|
|
167
|
+
let now = own(Deno.pid, {
|
|
168
|
+
every: 0,
|
|
169
|
+
look: () => looks.shift()!,
|
|
170
|
+
time: () => times.shift()!,
|
|
171
|
+
})
|
|
172
|
+
equal(now(), 0) // the first look
|
|
173
|
+
equal(now(), 70) // 100 ms passed, 30 of them waiting for a CPU
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Typing in a field
|
|
177
|
+
|
|
178
|
+
`typist(field)` keeps an input's or textarea's caret as a browser does, on a DOM
|
|
179
|
+
that keeps none (linkedom): a value a script puts in moves the caret to the end,
|
|
180
|
+
and `type` goes in at the caret and fires `input` for each character. `at` moves
|
|
181
|
+
the caret or selects, and `compose` and `end` type as an input method does. A
|
|
182
|
+
component that moves the caret when it should not fails here as it would in a
|
|
183
|
+
browser.
|
|
184
|
+
|
|
185
|
+
## Examples beside the code
|
|
186
|
+
|
|
187
|
+
Fenced `ts` blocks in Markdown and doc comments run as tests. The runner also
|
|
188
|
+
accepts `tsx`, `js`, `jsx`, `mjs`, `mts`, `typescript` and `javascript` fences.
|
|
189
|
+
A fence marked `ignore` is skipped. In a module's doc comment, its exports are
|
|
190
|
+
available without imports.
|
|
191
|
+
|
|
192
|
+
A doctest's `->` checks equality, `~>` awaits its input and checks a partial
|
|
193
|
+
pattern, and `throws` checks an error message. A line without an operator is a
|
|
194
|
+
shared statement. A line indented past the first continues that doctest; `// /`
|
|
195
|
+
skips a doctest.
|
|
196
|
+
|
|
197
|
+
This example runs all three doctest checks and a doc comment fence:
|
|
198
|
+
|
|
199
|
+
```ts
|
|
200
|
+
import { equal, match } from '@yaks/testing'
|
|
201
|
+
|
|
202
|
+
let dir = await Deno.makeTempDir({ prefix: 'testing-doctests-' })
|
|
203
|
+
try {
|
|
204
|
+
await Deno.writeTextFile(
|
|
205
|
+
`${dir}/twice.ts`,
|
|
206
|
+
`
|
|
207
|
+
/// let n = 2
|
|
208
|
+
/// twice(n) -> 4
|
|
209
|
+
/// Promise.resolve({ answer: twice(n), extra: true }) ~> { answer: 4 }
|
|
210
|
+
/// JSON.parse('{') throws 'JSON'
|
|
211
|
+
/**
|
|
212
|
+
* \`\`\`ts
|
|
213
|
+
* import { equal } from ${
|
|
214
|
+
JSON.stringify(import.meta.resolve('@yaks/testing'))
|
|
215
|
+
}
|
|
216
|
+
* equal(twice(3), 6)
|
|
217
|
+
* \`\`\`
|
|
218
|
+
*/
|
|
219
|
+
export let twice = (n: number) => n * 2
|
|
220
|
+
`,
|
|
221
|
+
)
|
|
222
|
+
let result = await new Deno.Command(Deno.execPath(), {
|
|
223
|
+
args: [
|
|
224
|
+
'run',
|
|
225
|
+
'-A',
|
|
226
|
+
import.meta.resolve('@yaks/testing/main'),
|
|
227
|
+
'--all',
|
|
228
|
+
dir,
|
|
229
|
+
],
|
|
230
|
+
env: { XDG_CACHE_HOME: `${dir}/cache` },
|
|
231
|
+
stdout: 'piped',
|
|
232
|
+
stderr: 'piped',
|
|
233
|
+
}).output()
|
|
234
|
+
equal(result.code, 0, new TextDecoder().decode(result.stderr))
|
|
235
|
+
match(new TextDecoder().decode(result.stdout), /4 passed.*0 failed/)
|
|
236
|
+
} finally {
|
|
237
|
+
await Deno.remove(dir, { recursive: true })
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Each example is compiled to a temporary module beside its page, preserving
|
|
242
|
+
relative import resolution and line numbers, and removed after loading.
|
|
243
|
+
|
|
244
|
+
## Finding tests and pages
|
|
245
|
+
|
|
246
|
+
`tested` recognizes test module paths. `paged` recognizes module and Markdown
|
|
247
|
+
paths except test modules. `examples` checks source for examples that run.
|
|
248
|
+
`walk` returns sorted, unique files under paths; directory traversal skips
|
|
249
|
+
hidden entries, `vendor`, `node_modules` and `.wrangler`. `find` returns test
|
|
250
|
+
modules and pages with examples that run.
|
|
251
|
+
|
|
252
|
+
```ts
|
|
253
|
+
import { equal } from '@yaks/testing'
|
|
254
|
+
import { examples, find, paged, tested, walk } from '@yaks/testing/find'
|
|
255
|
+
|
|
256
|
+
equal(tested('sum_test.ts'), true)
|
|
257
|
+
equal(paged('README.md'), true)
|
|
258
|
+
let source = `${'`'.repeat(3)}ts\n1 + 1\n${'`'.repeat(3)}`
|
|
259
|
+
equal(examples('README.md', source), true)
|
|
260
|
+
let dir = Deno.makeTempDirSync({ prefix: 'testing-find-' })
|
|
261
|
+
try {
|
|
262
|
+
Deno.writeTextFileSync(`${dir}/sum_test.ts`, '')
|
|
263
|
+
Deno.writeTextFileSync(`${dir}/README.md`, source)
|
|
264
|
+
equal(await walk([dir, dir]), [`${dir}/README.md`, `${dir}/sum_test.ts`])
|
|
265
|
+
equal(await find([dir]), {
|
|
266
|
+
tests: [`${dir}/sum_test.ts`],
|
|
267
|
+
pages: [`${dir}/README.md`],
|
|
268
|
+
})
|
|
269
|
+
} finally {
|
|
270
|
+
Deno.removeSync(dir, { recursive: true })
|
|
271
|
+
}
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## Running
|
|
275
|
+
|
|
276
|
+
```sh
|
|
277
|
+
deno run -A jsr:@yaks/testing/main [--tag=t]... [--platform=p] [--all] \
|
|
278
|
+
[--also=path]... [--keys=file] [--timeout=ms] [--times=dir] [--rest=file] \
|
|
279
|
+
[--part=n] [--verbose] path...
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
A path names a test module, a page, or a directory holding them. Files load one
|
|
283
|
+
at a time; each file's tests run before the next file loads. A file that cannot
|
|
284
|
+
load fails as a test. A test that exceeds `--timeout` (default 50000 ms) of its
|
|
285
|
+
own time (`own`: the runtime's and every process it started) fails and the
|
|
286
|
+
runner continues; the timeout does not cancel its body. A failed test sets exit
|
|
287
|
+
code 1; an unknown flag sets exit code 2.
|
|
288
|
+
|
|
289
|
+
An error nobody caught or a rejection nobody handled fails the test running when
|
|
290
|
+
it surfaces. Each file has its own global `error` and `unhandledrejection`
|
|
291
|
+
events: what it listens for there, by `addEventListener` or `onerror` and
|
|
292
|
+
`onunhandledrejection`, hears each, and one it cancels with `preventDefault()`
|
|
293
|
+
fails no test. A file's listeners end with it.
|
|
294
|
+
|
|
295
|
+
The runner says each test as it runs (`adds ... ok (120µs)`), a failed test's
|
|
296
|
+
errors right after its line, so a runtime that dies before it ends has still
|
|
297
|
+
said them, then a closing report: each failed test's name and file with its
|
|
298
|
+
errors again, then the counts. An error keeps only the stack frames in the
|
|
299
|
+
current directory, named from it, and none of this package's own, and is cut to
|
|
300
|
+
30 lines. `--verbose` says each error whole, names the failures again, and says
|
|
301
|
+
what planning and loading took.
|
|
302
|
+
|
|
303
|
+
`--tag` selects tests carrying every named tag; comma-separated tags are also
|
|
304
|
+
accepted. `--platform` supplies the runtime's tag, so selecting that tag keeps
|
|
305
|
+
all tests in the runtime. `--times` writes what the run took, in milliseconds,
|
|
306
|
+
to `<dir>/<platform>.json` (`tests.json` without a platform, and
|
|
307
|
+
`<platform>-<n>.json` with `--part=n`): the whole run, its planning and loading,
|
|
308
|
+
each file's load, each test that ran with its file, name, wall time (`ms`), CPU
|
|
309
|
+
time (`cpu`) and whether it passed. A test's CPU time is the user and system
|
|
310
|
+
time of the thread it runs on and of the child processes reaped while it ran
|
|
311
|
+
(`threadtime` from @yaks/benchmark). Waiting for timers, I/O or a CPU
|
|
312
|
+
contributes no CPU time. The per-test performance budget uses `cpu`; wall time
|
|
313
|
+
remains diagnostic. Existing budget records are marked `legacy-wall-ceilings`:
|
|
314
|
+
retained upper bounds that `--write` lowers using CPU samples. The report also
|
|
315
|
+
records each file the run remembered as passed, with its proof in the pass
|
|
316
|
+
record (`forget` from `@yaks/testing/deps` takes one back), and how many tests
|
|
317
|
+
it skipped and files it left out as unchanged.
|
|
318
|
+
|
|
319
|
+
A runtime keeps loaded modules and their reachable state until it exits. When
|
|
320
|
+
its resident memory crosses the limit after a file, `--rest` lets it release
|
|
321
|
+
shared fixtures and check again. If it still exceeds the limit, it records the
|
|
322
|
+
remaining files for a fresh runtime. The standalone limit is 1 GiB. The repo
|
|
323
|
+
runner uses 3 GiB and combines each platform's reports in order.
|
|
324
|
+
|
|
325
|
+
The process's other threads are left out because their work is not the test's.
|
|
326
|
+
V8 compiles and collects garbage on background threads whenever it likes, often
|
|
327
|
+
for a module loaded several tests before, and the whole process's CPU would
|
|
328
|
+
charge that to whichever test is running. What the test runs on its own thread,
|
|
329
|
+
the interpreter, the compiling it waits for and the collecting it triggers
|
|
330
|
+
there, counts, so a test reads over only when its own work grew. A test's work
|
|
331
|
+
in a worker or in Deno's blocking I/O threads does not count; a test that does
|
|
332
|
+
its work there is timed by its wall time.
|
|
333
|
+
|
|
334
|
+
A file whose tests all passed is skipped while its dependencies are unchanged.
|
|
335
|
+
Its **key** includes module dependencies resolved by `deno info`, files named
|
|
336
|
+
with a literal `new URL('./fixture.json', import.meta.url)` or a literal path in
|
|
337
|
+
a Deno file read, the runner's unconditional imports, config, lock, Deno version
|
|
338
|
+
and paths supplied by `--also`. A directory named this way is a place, not its
|
|
339
|
+
contents, and a directory's listing leaves out what the runner writes beside a
|
|
340
|
+
page while it runs. The runner also observes Deno file reads: a directory it
|
|
341
|
+
walks (its listing) and a file at a computed path. Computed module loaders use
|
|
342
|
+
`importing` from `@yaks/fp/imports`; their resolved specifiers are retained with
|
|
343
|
+
each module's whole graph, including cached loads. Prefer static imports in
|
|
344
|
+
tests, or supply statically imported modules at an injected loading boundary. A
|
|
345
|
+
pass is kept by its **proof**: the key and what each observed path holds.
|
|
346
|
+
Observation retains unique paths in memory; it produces no permission audit and
|
|
347
|
+
never observes FFI calls. The pass record is
|
|
348
|
+
`$XDG_CACHE_HOME/yak/tests-passed.log`, or `~/.cache/yak/tests-passed.log` when
|
|
349
|
+
`XDG_CACHE_HOME` is unset, a proof a line, shared by checkouts on the machine: a
|
|
350
|
+
run appends its own passes, so runs at once keep each other's. What each file
|
|
351
|
+
read as it last passed is kept beside it in `tests-reads.json`, reading nothing
|
|
352
|
+
included. Each checkout keeps its own stores under `yak/checkouts/` (`stores`
|
|
353
|
+
from `@yaks/testing/kept`), since checkouts differ: what deno says each module
|
|
354
|
+
imports, in `graph.json` by the module's import lines (`importing`) and the
|
|
355
|
+
configs and lock that resolve it (`remembered`), so a survey asks `deno info`
|
|
356
|
+
only of modules whose imports changed since, a new checkout starting from the
|
|
357
|
+
one any checkout under the same deno.json, deno.lock, package.json and pnpm lock
|
|
358
|
+
wrote last (`yak/graphs/`, `graphSeed`); what each file surveyed held, in the
|
|
359
|
+
file facts cache, and what each page's examples are, in `pages.json`
|
|
360
|
+
(`discover`'s `store`), each by the file's inode, size and times (`byStatus`),
|
|
361
|
+
so a file unchanged is not read again. What each file took to load and run in
|
|
362
|
+
`tests-took.json` (`took`, `tally`), which a caller can hand `choose` as a
|
|
363
|
+
file's `cost`. `--all` bypasses the record; a run filtered by tag records no
|
|
364
|
+
passes. `--keys` names a JSON file holding the key of each file given, from a
|
|
365
|
+
caller that chose them already (`choose` from `@yaks/testing/choose`): every
|
|
366
|
+
file given runs.
|
|
367
|
+
|
|
368
|
+
`choose` always keeps changed files, tests importing edited declarations, direct
|
|
369
|
+
consumers of other changes, and tests that read the changed file or list its
|
|
370
|
+
directory. A private helper is part of the declarations that use it. Calling
|
|
371
|
+
another exported declaration adds a step within or across modules. Tests of
|
|
372
|
+
those callers rank after direct consumers, up to `STEPS` steps (`naming` in
|
|
373
|
+
`names.ts`). Other files rank by **distance**, the number of imports from a
|
|
374
|
+
changed module to the file or a recorded read. Distance stops at a module that
|
|
375
|
+
loads more than `WIDE` others. Such a module composes a platform, so nearly
|
|
376
|
+
every change reaches its importers and that path says nothing about them. Given
|
|
377
|
+
each path's package (`owner`), the files of a changed package a distance
|
|
378
|
+
reaches, its README examples among them, come first. The files importing a
|
|
379
|
+
changed package from another, and a changed package's files reached only through
|
|
380
|
+
a wide module, come next. The rest run nearest and cheapest first, followed by
|
|
381
|
+
files with no distance if budget remains. The runner counts deferred files as
|
|
382
|
+
`beyond`.
|
|
383
|
+
|
|
384
|
+
In this repository, `deno task test` chooses what runs before it starts
|
|
385
|
+
anything, then starts one runner runtime for each platform holding a file that
|
|
386
|
+
runs (deno and terminal), each observing its own reads.
|
|
387
|
+
|
|
388
|
+
## Controlling time
|
|
389
|
+
|
|
390
|
+
A **virtual clock** runs scheduled callbacks when a test advances time. Inject
|
|
391
|
+
`clock()`'s `now` and `after` into the code's timer boundary.
|
|
392
|
+
`after(ms, callback)` returns a cancellation function. `advance(ms)` first turns
|
|
393
|
+
the event loop once, so work the caller queued sets its timers, then awaits
|
|
394
|
+
callbacks in chronological order, including callbacks scheduled by callbacks;
|
|
395
|
+
callbacks at the same time run in registration order. `pending()` counts the
|
|
396
|
+
callbacks set that have neither run nor been cancelled. It leaves global timers
|
|
397
|
+
and `Date` unchanged.
|
|
398
|
+
|
|
399
|
+
Code that reads the time or sets a timer takes a clock (@yaks/fp `Clock`, the
|
|
400
|
+
runtime's `system` by default), and a test hands it one of its own. A test never
|
|
401
|
+
replaces the runtime's clock or timers, with @std/testing's `FakeTime`, a stub
|
|
402
|
+
of `setTimeout` or an assignment to `Date.now`: every test file in a run shares
|
|
403
|
+
one runtime, and a faked global counts, moves and swallows timers that other
|
|
404
|
+
files started, so the verdict depends on which files ran first.
|
|
405
|
+
|
|
406
|
+
```ts
|
|
407
|
+
import { clock, equal } from '@yaks/testing'
|
|
408
|
+
|
|
409
|
+
let time = clock(100)
|
|
410
|
+
let expired = false
|
|
411
|
+
time.after(20, () => {
|
|
412
|
+
expired = true
|
|
413
|
+
})
|
|
414
|
+
await time.advance(19)
|
|
415
|
+
equal(expired, false)
|
|
416
|
+
await time.advance(1)
|
|
417
|
+
equal([expired, time.now()], [true, 120])
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
## Limits
|
|
421
|
+
|
|
422
|
+
Assertions and waiting work in runtimes with timers. Without `Deno.test` or the
|
|
423
|
+
runner, declaring tests does not execute them. The runner and discovery
|
|
424
|
+
functions need Deno. The runner uses `deno info` for dependencies and `/proc` to
|
|
425
|
+
identify temporary examples left by ended processes. Native code, child
|
|
426
|
+
processes, Node filesystem APIs and a raw computed `import()` are outside read
|
|
427
|
+
observation. Keep those dependencies static, supply them through a generic
|
|
428
|
+
boundary, or name additional inputs with `--also`.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep equality: `actual` is `expected`, structurally. Text is compared as
|
|
3
|
+
* text, so a branded string (a query `Line`) meets a plain literal.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* equal({ a: [1, 2] }, { a: [1, 2] })
|
|
7
|
+
* ```
|
|
8
|
+
*/ export declare let equal: {
|
|
9
|
+
<T extends string>(actual: T, expected: string, message?: string) : T;
|
|
10
|
+
<T>(actual: T, expected: T, message?: string) : T;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Truthiness: `actual` holds, and comes back.
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* ok([1].find((n) => n == 1)) // 1
|
|
17
|
+
* ```
|
|
18
|
+
*/ export declare let ok: <T>(actual: T, message?: string) => NonNullable<T>;
|
|
19
|
+
/**
|
|
20
|
+
* A partial match: every key `pattern` names holds in `actual`, and every
|
|
21
|
+
* item of a pattern array in the item at its index. A RegExp tests a value's
|
|
22
|
+
* text and a class tests an instance; an empty array or object asks for an
|
|
23
|
+
* empty one, and the rest is equality: an instance's, and an arrow's.
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* match({ id: 7, name: 'Ada', tags: ['a', 'b'] }, { name: /^A/, tags: ['a'] })
|
|
27
|
+
* let twice = (n: number) => n * 2
|
|
28
|
+
* match({ at: new Date(0), of: twice }, { at: Date, of: twice })
|
|
29
|
+
* match({ at: new Date(0) }, { at: new Date(0) })
|
|
30
|
+
* ```
|
|
31
|
+
*/ export declare let match: <T>(actual: T, pattern: unknown, message?: string) => T;
|
|
32
|
+
/**
|
|
33
|
+
* `fn` throws, or rejects, with an error whose message includes `message`
|
|
34
|
+
* (or matches it, a RegExp). The error comes back.
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* await throws(() => JSON.parse('{'), 'JSON')
|
|
38
|
+
* ```
|
|
39
|
+
*/ export declare let throws: (fn: () => unknown, message?: string | RegExp) => Promise<unknown>;
|
|
40
|
+
//# sourceMappingURL=assert.d.ts.map
|