track-cli 4.0.3 → 4.1.0-rc1
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/esm/_dnt.shims.d.ts +1 -1
- package/esm/_dnt.test_shims.d.ts +20 -0
- package/esm/_dnt.test_shims.js +77 -0
- package/esm/deps/deno.land/std@0.195.0/_util/diff.d.ts +26 -0
- package/esm/deps/deno.land/std@0.195.0/_util/diff.js +311 -0
- package/esm/deps/deno.land/std@0.195.0/assert/_constants.d.ts +1 -0
- package/esm/deps/deno.land/std@0.195.0/assert/_constants.js +2 -0
- package/esm/deps/deno.land/std@0.195.0/assert/_format.d.ts +1 -0
- package/esm/deps/deno.land/std@0.195.0/assert/_format.js +23 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_almost_equals.d.ts +18 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_almost_equals.js +32 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_array_includes.d.ts +14 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_array_includes.js +38 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_equals.d.ts +17 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_equals.js +45 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_exists.d.ts +5 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_exists.js +14 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_false.d.ts +4 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_false.js +7 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_instance_of.d.ts +8 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_instance_of.js +38 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_is_error.d.ts +7 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_is_error.js +26 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_match.d.ts +5 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_match.js +13 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_not_equals.d.ts +14 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_not_equals.js +37 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_not_instance_of.d.ts +5 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_not_instance_of.js +14 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_not_match.d.ts +5 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_not_match.js +14 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_not_strict_equals.d.ts +11 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_not_strict_equals.js +20 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_object_match.d.ts +5 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_object_match.js +78 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_rejects.d.ts +64 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_rejects.js +50 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_strict_equals.d.ts +23 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_strict_equals.js +60 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_string_includes.d.ts +5 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_string_includes.js +13 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_throws.d.ts +54 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_throws.js +44 -0
- package/esm/deps/deno.land/std@0.195.0/assert/equal.d.ts +6 -0
- package/esm/deps/deno.land/std@0.195.0/assert/equal.js +102 -0
- package/esm/deps/deno.land/std@0.195.0/assert/fail.d.ts +4 -0
- package/esm/deps/deno.land/std@0.195.0/assert/fail.js +9 -0
- package/esm/deps/deno.land/std@0.195.0/assert/mod.d.ts +32 -0
- package/esm/deps/deno.land/std@0.195.0/assert/mod.js +33 -0
- package/esm/deps/deno.land/std@0.195.0/assert/unimplemented.d.ts +2 -0
- package/esm/deps/deno.land/std@0.195.0/assert/unimplemented.js +7 -0
- package/esm/deps/deno.land/std@0.195.0/assert/unreachable.d.ts +2 -0
- package/esm/deps/deno.land/std@0.195.0/assert/unreachable.js +6 -0
- package/esm/deps/deno.land/std@0.195.0/testing/_test_suite.d.ts +70 -0
- package/esm/deps/deno.land/std@0.195.0/testing/_test_suite.js +321 -0
- package/esm/deps/deno.land/std@0.195.0/testing/asserts.d.ts +329 -0
- package/esm/deps/deno.land/std@0.195.0/testing/asserts.js +330 -0
- package/esm/deps/deno.land/std@0.195.0/testing/bdd.d.ts +440 -0
- package/esm/deps/deno.land/std@0.195.0/testing/bdd.js +215 -0
- package/esm/deps/deno.land/std@0.195.0/testing/mock.d.ts +110 -0
- package/esm/deps/deno.land/std@0.195.0/testing/mock.js +746 -0
- package/esm/src/action/clone.js +4 -3
- package/esm/src/action/frontend-template-switch.d.ts +1 -0
- package/esm/src/action/frontend-template-switch.js +56 -0
- package/esm/src/action/frontend-template.d.ts +2 -0
- package/esm/src/action/frontend-template.js +12 -0
- package/esm/src/main.js +9 -2
- package/esm/src/meta.d.ts +1 -1
- package/esm/src/meta.js +108 -25
- package/esm/src/orca/client.js +1 -1
- package/esm/src/shared/config.d.ts +1 -0
- package/esm/src/shared/file.d.ts +1 -0
- package/esm/src/shared/file.js +32 -0
- package/esm/src/shared/mod.d.ts +1 -1
- package/esm/src/shared/mod.js +10 -2
- package/esm/src/shared/types.d.ts +15 -0
- package/esm/src/shared/types.js +1 -0
- package/esm/src/track/client.d.ts +4 -1
- package/esm/src/track/test.d.ts +5 -2
- package/esm/src/track/test.js +18 -2
- package/esm/src/track/training.d.ts +4 -1
- package/esm/src/track/training.js +9 -0
- package/esm/test/shared/config_test.d.ts +1 -0
- package/esm/test/shared/config_test.js +57 -0
- package/esm/test/shared/file_test.d.ts +1 -0
- package/esm/test/shared/file_test.js +265 -0
- package/esm/test/shared/mod_test.d.ts +1 -0
- package/esm/test/shared/mod_test.js +353 -0
- package/package.json +2 -1
- package/test_runner.js +186 -0
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
/** A [BDD](https://en.wikipedia.org/wiki/Behavior-driven_development) interface
|
|
2
|
+
* to `Deno.test()` API.
|
|
3
|
+
*
|
|
4
|
+
* With the `bdd.ts` module you can write your tests in a familiar format for
|
|
5
|
+
* grouping tests and adding setup/teardown hooks used by other JavaScript testing
|
|
6
|
+
* frameworks like Jasmine, Jest, and Mocha.
|
|
7
|
+
*
|
|
8
|
+
* The `describe` function creates a block that groups together several related
|
|
9
|
+
* tests. The `it` function registers an individual test case.
|
|
10
|
+
*
|
|
11
|
+
* ## Hooks
|
|
12
|
+
*
|
|
13
|
+
* There are 4 types of hooks available for test suites. A test suite can have
|
|
14
|
+
* multiples of each type of hook, they will be called in the order that they are
|
|
15
|
+
* registered. The `afterEach` and `afterAll` hooks will be called whether or not
|
|
16
|
+
* the test case passes. The *All hooks will be called once for the whole group
|
|
17
|
+
* while the *Each hooks will be called for each individual test case.
|
|
18
|
+
*
|
|
19
|
+
* - `beforeAll`: Runs before all of the tests in the test suite.
|
|
20
|
+
* - `afterAll`: Runs after all of the tests in the test suite finish.
|
|
21
|
+
* - `beforeEach`: Runs before each of the individual test cases in the test suite.
|
|
22
|
+
* - `afterEach`: Runs after each of the individual test cases in the test suite.
|
|
23
|
+
*
|
|
24
|
+
* If a hook is registered at the top level, a global test suite will be registered
|
|
25
|
+
* and all tests will belong to it. Hooks registered at the top level must be
|
|
26
|
+
* registered before any individual test cases or test suites.
|
|
27
|
+
*
|
|
28
|
+
* ## Focusing tests
|
|
29
|
+
*
|
|
30
|
+
* If you would like to run only specific test cases, you can do so by calling
|
|
31
|
+
* `it.only` instead of `it`. If you would like to run only specific test suites,
|
|
32
|
+
* you can do so by calling `describe.only` instead of `describe`.
|
|
33
|
+
*
|
|
34
|
+
* There is one limitation to this when using the flat test grouping style. When
|
|
35
|
+
* `describe` is called without being nested, it registers the test with
|
|
36
|
+
* `Deno.test`. If a child test case or suite is registered with `it.only` or
|
|
37
|
+
* `describe.only`, it will be scoped to the top test suite instead of the file. To
|
|
38
|
+
* make them the only tests that run in the file, you would need to register the
|
|
39
|
+
* top test suite with `describe.only` too.
|
|
40
|
+
*
|
|
41
|
+
* ## Ignoring tests
|
|
42
|
+
*
|
|
43
|
+
* If you would like to not run specific individual test cases, you can do so by
|
|
44
|
+
* calling `it.ignore` instead of `it`. If you would like to not run specific test
|
|
45
|
+
* suites, you can do so by calling `describe.ignore` instead of `describe`.
|
|
46
|
+
*
|
|
47
|
+
* ## Sanitization options
|
|
48
|
+
*
|
|
49
|
+
* Like `Deno.TestDefinition`, the `DescribeDefinition` and `ItDefinition` have
|
|
50
|
+
* sanitization options. They work in the same way.
|
|
51
|
+
*
|
|
52
|
+
* - `sanitizeExit`: Ensure the test case does not prematurely cause the process to
|
|
53
|
+
* exit, for example via a call to Deno.exit. Defaults to true.
|
|
54
|
+
* - `sanitizeOps`: Check that the number of async completed ops after the test is
|
|
55
|
+
* the same as number of dispatched ops. Defaults to true.
|
|
56
|
+
* - `sanitizeResources`: Ensure the test case does not "leak" resources - ie. the
|
|
57
|
+
* resource table after the test has exactly the same contents as before the
|
|
58
|
+
* test. Defaults to true.
|
|
59
|
+
*
|
|
60
|
+
* ## Permissions option
|
|
61
|
+
*
|
|
62
|
+
* Like `Deno.TestDefinition`, the `DescribeDefinition` and `ItDefinition` have a
|
|
63
|
+
* `permissions` option. They specify the permissions that should be used to run an
|
|
64
|
+
* individual test case or test suite. Set this to `"inherit"` to keep the calling
|
|
65
|
+
* thread's permissions. Set this to `"none"` to revoke all permissions.
|
|
66
|
+
*
|
|
67
|
+
* This setting defaults to `"inherit"`.
|
|
68
|
+
*
|
|
69
|
+
* There is currently one limitation to this, you cannot use the permissions option
|
|
70
|
+
* on an individual test case or test suite that belongs to another test suite.
|
|
71
|
+
* That's because internally those tests are registered with `t.step` which does
|
|
72
|
+
* not support the permissions option.
|
|
73
|
+
*
|
|
74
|
+
* ## Comparing to Deno\.test
|
|
75
|
+
*
|
|
76
|
+
* The default way of writing tests is using `Deno.test` and `t.step`. The
|
|
77
|
+
* `describe` and `it` functions have similar call signatures to `Deno.test`,
|
|
78
|
+
* making it easy to switch between the default style and the behavior-driven
|
|
79
|
+
* development style of writing tests. Internally, `describe` and `it` are
|
|
80
|
+
* registering tests with `Deno.test` and `t.step`.
|
|
81
|
+
*
|
|
82
|
+
* Below is an example of a test file using `Deno.test` and `t.step`. In the
|
|
83
|
+
* following sections there are examples of how the same test could be written with
|
|
84
|
+
* `describe` and `it` using nested test grouping, flat test grouping, or a mix of
|
|
85
|
+
* both styles.
|
|
86
|
+
*
|
|
87
|
+
* ```ts
|
|
88
|
+
* // https://deno.land/std@$STD_VERSION/testing/bdd_examples/user_test.ts
|
|
89
|
+
* import {
|
|
90
|
+
* assertEquals,
|
|
91
|
+
* assertStrictEquals,
|
|
92
|
+
* assertThrows,
|
|
93
|
+
* } from "https://deno.land/std@$STD_VERSION/assert/mod.ts";
|
|
94
|
+
* import { User } from "https://deno.land/std@$STD_VERSION/testing/bdd_examples/user.ts";
|
|
95
|
+
*
|
|
96
|
+
* Deno.test("User.users initially empty", () => {
|
|
97
|
+
* assertEquals(User.users.size, 0);
|
|
98
|
+
* });
|
|
99
|
+
*
|
|
100
|
+
* Deno.test("User constructor", () => {
|
|
101
|
+
* try {
|
|
102
|
+
* const user = new User("Kyle");
|
|
103
|
+
* assertEquals(user.name, "Kyle");
|
|
104
|
+
* assertStrictEquals(User.users.get("Kyle"), user);
|
|
105
|
+
* } finally {
|
|
106
|
+
* User.users.clear();
|
|
107
|
+
* }
|
|
108
|
+
* });
|
|
109
|
+
*
|
|
110
|
+
* Deno.test("User age", async (t) => {
|
|
111
|
+
* const user = new User("Kyle");
|
|
112
|
+
*
|
|
113
|
+
* await t.step("getAge", () => {
|
|
114
|
+
* assertThrows(() => user.getAge(), Error, "Age unknown");
|
|
115
|
+
* user.age = 18;
|
|
116
|
+
* assertEquals(user.getAge(), 18);
|
|
117
|
+
* });
|
|
118
|
+
*
|
|
119
|
+
* await t.step("setAge", () => {
|
|
120
|
+
* user.setAge(18);
|
|
121
|
+
* assertEquals(user.getAge(), 18);
|
|
122
|
+
* });
|
|
123
|
+
* });
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* ### Nested test grouping
|
|
127
|
+
*
|
|
128
|
+
* Tests created within the callback of a `describe` function call will belong to
|
|
129
|
+
* the new test suite it creates. The hooks can be created within it or be added to
|
|
130
|
+
* the options argument for describe.
|
|
131
|
+
*
|
|
132
|
+
* ```ts
|
|
133
|
+
* // https://deno.land/std@$STD_VERSION/testing/bdd_examples/user_nested_test.ts
|
|
134
|
+
* import {
|
|
135
|
+
* assertEquals,
|
|
136
|
+
* assertStrictEquals,
|
|
137
|
+
* assertThrows,
|
|
138
|
+
* } from "https://deno.land/std@$STD_VERSION/assert/mod.ts";
|
|
139
|
+
* import {
|
|
140
|
+
* afterEach,
|
|
141
|
+
* beforeEach,
|
|
142
|
+
* describe,
|
|
143
|
+
* it,
|
|
144
|
+
* } from "https://deno.land/std@$STD_VERSION/testing/bdd.ts";
|
|
145
|
+
* import { User } from "https://deno.land/std@$STD_VERSION/testing/bdd_examples/user.ts";
|
|
146
|
+
*
|
|
147
|
+
* describe("User", () => {
|
|
148
|
+
* it("users initially empty", () => {
|
|
149
|
+
* assertEquals(User.users.size, 0);
|
|
150
|
+
* });
|
|
151
|
+
*
|
|
152
|
+
* it("constructor", () => {
|
|
153
|
+
* try {
|
|
154
|
+
* const user = new User("Kyle");
|
|
155
|
+
* assertEquals(user.name, "Kyle");
|
|
156
|
+
* assertStrictEquals(User.users.get("Kyle"), user);
|
|
157
|
+
* } finally {
|
|
158
|
+
* User.users.clear();
|
|
159
|
+
* }
|
|
160
|
+
* });
|
|
161
|
+
*
|
|
162
|
+
* describe("age", () => {
|
|
163
|
+
* let user: User;
|
|
164
|
+
*
|
|
165
|
+
* beforeEach(() => {
|
|
166
|
+
* user = new User("Kyle");
|
|
167
|
+
* });
|
|
168
|
+
*
|
|
169
|
+
* afterEach(() => {
|
|
170
|
+
* User.users.clear();
|
|
171
|
+
* });
|
|
172
|
+
*
|
|
173
|
+
* it("getAge", function () {
|
|
174
|
+
* assertThrows(() => user.getAge(), Error, "Age unknown");
|
|
175
|
+
* user.age = 18;
|
|
176
|
+
* assertEquals(user.getAge(), 18);
|
|
177
|
+
* });
|
|
178
|
+
*
|
|
179
|
+
* it("setAge", function () {
|
|
180
|
+
* user.setAge(18);
|
|
181
|
+
* assertEquals(user.getAge(), 18);
|
|
182
|
+
* });
|
|
183
|
+
* });
|
|
184
|
+
* });
|
|
185
|
+
* ```
|
|
186
|
+
*
|
|
187
|
+
* ### Flat test grouping
|
|
188
|
+
*
|
|
189
|
+
* The `describe` function returns a unique symbol that can be used to reference
|
|
190
|
+
* the test suite for adding tests to it without having to create them within a
|
|
191
|
+
* callback. The gives you the ability to have test grouping without any extra
|
|
192
|
+
* indentation in front of the grouped tests.
|
|
193
|
+
*
|
|
194
|
+
* ```ts
|
|
195
|
+
* // https://deno.land/std@$STD_VERSION/testing/bdd_examples/user_flat_test.ts
|
|
196
|
+
* import {
|
|
197
|
+
* assertEquals,
|
|
198
|
+
* assertStrictEquals,
|
|
199
|
+
* assertThrows,
|
|
200
|
+
* } from "https://deno.land/std@$STD_VERSION/assert/mod.ts";
|
|
201
|
+
* import {
|
|
202
|
+
* describe,
|
|
203
|
+
* it,
|
|
204
|
+
* } from "https://deno.land/std@$STD_VERSION/testing/bdd.ts";
|
|
205
|
+
* import { User } from "https://deno.land/std@$STD_VERSION/testing/bdd_examples/user.ts";
|
|
206
|
+
*
|
|
207
|
+
* const userTests = describe("User");
|
|
208
|
+
*
|
|
209
|
+
* it(userTests, "users initially empty", () => {
|
|
210
|
+
* assertEquals(User.users.size, 0);
|
|
211
|
+
* });
|
|
212
|
+
*
|
|
213
|
+
* it(userTests, "constructor", () => {
|
|
214
|
+
* try {
|
|
215
|
+
* const user = new User("Kyle");
|
|
216
|
+
* assertEquals(user.name, "Kyle");
|
|
217
|
+
* assertStrictEquals(User.users.get("Kyle"), user);
|
|
218
|
+
* } finally {
|
|
219
|
+
* User.users.clear();
|
|
220
|
+
* }
|
|
221
|
+
* });
|
|
222
|
+
*
|
|
223
|
+
* const ageTests = describe({
|
|
224
|
+
* name: "age",
|
|
225
|
+
* suite: userTests,
|
|
226
|
+
* beforeEach(this: { user: User }) {
|
|
227
|
+
* this.user = new User("Kyle");
|
|
228
|
+
* },
|
|
229
|
+
* afterEach() {
|
|
230
|
+
* User.users.clear();
|
|
231
|
+
* },
|
|
232
|
+
* });
|
|
233
|
+
*
|
|
234
|
+
* it(ageTests, "getAge", function () {
|
|
235
|
+
* const { user } = this;
|
|
236
|
+
* assertThrows(() => user.getAge(), Error, "Age unknown");
|
|
237
|
+
* user.age = 18;
|
|
238
|
+
* assertEquals(user.getAge(), 18);
|
|
239
|
+
* });
|
|
240
|
+
*
|
|
241
|
+
* it(ageTests, "setAge", function () {
|
|
242
|
+
* const { user } = this;
|
|
243
|
+
* user.setAge(18);
|
|
244
|
+
* assertEquals(user.getAge(), 18);
|
|
245
|
+
* });
|
|
246
|
+
* ```
|
|
247
|
+
*
|
|
248
|
+
* ### Mixed test grouping
|
|
249
|
+
*
|
|
250
|
+
* Both nested test grouping and flat test grouping can be used together. This can
|
|
251
|
+
* be useful if you'd like to create deep groupings without all the extra
|
|
252
|
+
* indentation in front of each line.
|
|
253
|
+
*
|
|
254
|
+
* ```ts
|
|
255
|
+
* // https://deno.land/std@$STD_VERSION/testing/bdd_examples/user_mixed_test.ts
|
|
256
|
+
* import {
|
|
257
|
+
* assertEquals,
|
|
258
|
+
* assertStrictEquals,
|
|
259
|
+
* assertThrows,
|
|
260
|
+
* } from "https://deno.land/std@$STD_VERSION/assert/mod.ts";
|
|
261
|
+
* import {
|
|
262
|
+
* describe,
|
|
263
|
+
* it,
|
|
264
|
+
* } from "https://deno.land/std@$STD_VERSION/testing/bdd.ts";
|
|
265
|
+
* import { User } from "https://deno.land/std@$STD_VERSION/testing/bdd_examples/user.ts";
|
|
266
|
+
*
|
|
267
|
+
* describe("User", () => {
|
|
268
|
+
* it("users initially empty", () => {
|
|
269
|
+
* assertEquals(User.users.size, 0);
|
|
270
|
+
* });
|
|
271
|
+
*
|
|
272
|
+
* it("constructor", () => {
|
|
273
|
+
* try {
|
|
274
|
+
* const user = new User("Kyle");
|
|
275
|
+
* assertEquals(user.name, "Kyle");
|
|
276
|
+
* assertStrictEquals(User.users.get("Kyle"), user);
|
|
277
|
+
* } finally {
|
|
278
|
+
* User.users.clear();
|
|
279
|
+
* }
|
|
280
|
+
* });
|
|
281
|
+
*
|
|
282
|
+
* const ageTests = describe({
|
|
283
|
+
* name: "age",
|
|
284
|
+
* beforeEach(this: { user: User }) {
|
|
285
|
+
* this.user = new User("Kyle");
|
|
286
|
+
* },
|
|
287
|
+
* afterEach() {
|
|
288
|
+
* User.users.clear();
|
|
289
|
+
* },
|
|
290
|
+
* });
|
|
291
|
+
*
|
|
292
|
+
* it(ageTests, "getAge", function () {
|
|
293
|
+
* const { user } = this;
|
|
294
|
+
* assertThrows(() => user.getAge(), Error, "Age unknown");
|
|
295
|
+
* user.age = 18;
|
|
296
|
+
* assertEquals(user.getAge(), 18);
|
|
297
|
+
* });
|
|
298
|
+
*
|
|
299
|
+
* it(ageTests, "setAge", function () {
|
|
300
|
+
* const { user } = this;
|
|
301
|
+
* user.setAge(18);
|
|
302
|
+
* assertEquals(user.getAge(), 18);
|
|
303
|
+
* });
|
|
304
|
+
* });
|
|
305
|
+
* ```
|
|
306
|
+
*
|
|
307
|
+
* @module
|
|
308
|
+
*/
|
|
309
|
+
import * as dntShim from "../../../../_dnt.test_shims.js";
|
|
310
|
+
import { DescribeDefinition, ItDefinition, TestSuite } from "./_test_suite.js";
|
|
311
|
+
export type { DescribeDefinition, ItDefinition, TestSuite };
|
|
312
|
+
/** The arguments for an ItFunction. */
|
|
313
|
+
export type ItArgs<T> = [options: ItDefinition<T>] | [
|
|
314
|
+
name: string,
|
|
315
|
+
options: Omit<ItDefinition<T>, "name">
|
|
316
|
+
] | [
|
|
317
|
+
name: string,
|
|
318
|
+
fn: (this: T, t: dntShim.Deno.TestContext) => void | Promise<void>
|
|
319
|
+
] | [fn: (this: T, t: dntShim.Deno.TestContext) => void | Promise<void>] | [
|
|
320
|
+
name: string,
|
|
321
|
+
options: Omit<ItDefinition<T>, "fn" | "name">,
|
|
322
|
+
fn: (this: T, t: dntShim.Deno.TestContext) => void | Promise<void>
|
|
323
|
+
] | [
|
|
324
|
+
options: Omit<ItDefinition<T>, "fn">,
|
|
325
|
+
fn: (this: T, t: dntShim.Deno.TestContext) => void | Promise<void>
|
|
326
|
+
] | [
|
|
327
|
+
options: Omit<ItDefinition<T>, "fn" | "name">,
|
|
328
|
+
fn: (this: T, t: dntShim.Deno.TestContext) => void | Promise<void>
|
|
329
|
+
] | [
|
|
330
|
+
suite: TestSuite<T>,
|
|
331
|
+
name: string,
|
|
332
|
+
options: Omit<ItDefinition<T>, "name" | "suite">
|
|
333
|
+
] | [
|
|
334
|
+
suite: TestSuite<T>,
|
|
335
|
+
name: string,
|
|
336
|
+
fn: (this: T, t: dntShim.Deno.TestContext) => void | Promise<void>
|
|
337
|
+
] | [
|
|
338
|
+
suite: TestSuite<T>,
|
|
339
|
+
fn: (this: T, t: dntShim.Deno.TestContext) => void | Promise<void>
|
|
340
|
+
] | [
|
|
341
|
+
suite: TestSuite<T>,
|
|
342
|
+
name: string,
|
|
343
|
+
options: Omit<ItDefinition<T>, "fn" | "name" | "suite">,
|
|
344
|
+
fn: (this: T, t: dntShim.Deno.TestContext) => void | Promise<void>
|
|
345
|
+
] | [
|
|
346
|
+
suite: TestSuite<T>,
|
|
347
|
+
options: Omit<ItDefinition<T>, "fn" | "suite">,
|
|
348
|
+
fn: (this: T, t: dntShim.Deno.TestContext) => void | Promise<void>
|
|
349
|
+
] | [
|
|
350
|
+
suite: TestSuite<T>,
|
|
351
|
+
options: Omit<ItDefinition<T>, "fn" | "name" | "suite">,
|
|
352
|
+
fn: (this: T, t: dntShim.Deno.TestContext) => void | Promise<void>
|
|
353
|
+
];
|
|
354
|
+
/** Registers an individual test case. */
|
|
355
|
+
export interface it {
|
|
356
|
+
<T>(...args: ItArgs<T>): void;
|
|
357
|
+
/** Registers an individual test case with only set to true. */
|
|
358
|
+
only<T>(...args: ItArgs<T>): void;
|
|
359
|
+
/** Registers an individual test case with ignore set to true. */
|
|
360
|
+
ignore<T>(...args: ItArgs<T>): void;
|
|
361
|
+
/**
|
|
362
|
+
* Registers an individual test case with ignore set to true. Alias of
|
|
363
|
+
* `.ignore()`.
|
|
364
|
+
*/
|
|
365
|
+
skip<T>(...args: ItArgs<T>): void;
|
|
366
|
+
}
|
|
367
|
+
/** Registers an individual test case. */
|
|
368
|
+
export declare function it<T>(...args: ItArgs<T>): void;
|
|
369
|
+
export declare namespace it {
|
|
370
|
+
var only: <T>(...args: ItArgs<T>) => void;
|
|
371
|
+
var ignore: <T>(...args: ItArgs<T>) => void;
|
|
372
|
+
var skip: <T>(...args: ItArgs<T>) => void;
|
|
373
|
+
}
|
|
374
|
+
/** Run some shared setup before all of the tests in the suite. */
|
|
375
|
+
export declare function beforeAll<T>(fn: (this: T) => void | Promise<void>): void;
|
|
376
|
+
/** Run some shared teardown after all of the tests in the suite. */
|
|
377
|
+
export declare function afterAll<T>(fn: (this: T) => void | Promise<void>): void;
|
|
378
|
+
/** Run some shared setup before each test in the suite. */
|
|
379
|
+
export declare function beforeEach<T>(fn: (this: T) => void | Promise<void>): void;
|
|
380
|
+
/** Run some shared teardown after each test in the suite. */
|
|
381
|
+
export declare function afterEach<T>(fn: (this: T) => void | Promise<void>): void;
|
|
382
|
+
/** The arguments for a DescribeFunction. */
|
|
383
|
+
export type DescribeArgs<T> = [options: DescribeDefinition<T>] | [name: string] | [
|
|
384
|
+
name: string,
|
|
385
|
+
options: Omit<DescribeDefinition<T>, "name">
|
|
386
|
+
] | [name: string, fn: () => void] | [fn: () => void] | [
|
|
387
|
+
name: string,
|
|
388
|
+
options: Omit<DescribeDefinition<T>, "fn" | "name">,
|
|
389
|
+
fn: () => void
|
|
390
|
+
] | [
|
|
391
|
+
options: Omit<DescribeDefinition<T>, "fn">,
|
|
392
|
+
fn: () => void
|
|
393
|
+
] | [
|
|
394
|
+
options: Omit<DescribeDefinition<T>, "fn" | "name">,
|
|
395
|
+
fn: () => void
|
|
396
|
+
] | [
|
|
397
|
+
suite: TestSuite<T>,
|
|
398
|
+
name: string
|
|
399
|
+
] | [
|
|
400
|
+
suite: TestSuite<T>,
|
|
401
|
+
name: string,
|
|
402
|
+
options: Omit<DescribeDefinition<T>, "name" | "suite">
|
|
403
|
+
] | [
|
|
404
|
+
suite: TestSuite<T>,
|
|
405
|
+
name: string,
|
|
406
|
+
fn: () => void
|
|
407
|
+
] | [
|
|
408
|
+
suite: TestSuite<T>,
|
|
409
|
+
fn: () => void
|
|
410
|
+
] | [
|
|
411
|
+
suite: TestSuite<T>,
|
|
412
|
+
name: string,
|
|
413
|
+
options: Omit<DescribeDefinition<T>, "fn" | "name" | "suite">,
|
|
414
|
+
fn: () => void
|
|
415
|
+
] | [
|
|
416
|
+
suite: TestSuite<T>,
|
|
417
|
+
options: Omit<DescribeDefinition<T>, "fn" | "suite">,
|
|
418
|
+
fn: () => void
|
|
419
|
+
] | [
|
|
420
|
+
suite: TestSuite<T>,
|
|
421
|
+
options: Omit<DescribeDefinition<T>, "fn" | "name" | "suite">,
|
|
422
|
+
fn: () => void
|
|
423
|
+
];
|
|
424
|
+
/** Registers a test suite. */
|
|
425
|
+
export interface describe {
|
|
426
|
+
<T>(...args: DescribeArgs<T>): TestSuite<T>;
|
|
427
|
+
/** Registers a test suite with only set to true. */
|
|
428
|
+
only<T>(...args: DescribeArgs<T>): TestSuite<T>;
|
|
429
|
+
/** Registers a test suite with ignore set to true. */
|
|
430
|
+
ignore<T>(...args: DescribeArgs<T>): TestSuite<T>;
|
|
431
|
+
/** Registers a test suite with ignore set to true. Alias of `.ignore()`. */
|
|
432
|
+
skip<T>(...args: ItArgs<T>): void;
|
|
433
|
+
}
|
|
434
|
+
/** Registers a test suite. */
|
|
435
|
+
export declare function describe<T>(...args: DescribeArgs<T>): TestSuite<T>;
|
|
436
|
+
export declare namespace describe {
|
|
437
|
+
var only: <T>(...args: DescribeArgs<T>) => TestSuite<T>;
|
|
438
|
+
var ignore: <T>(...args: DescribeArgs<T>) => TestSuite<T>;
|
|
439
|
+
var skip: <T>(...args: DescribeArgs<T>) => TestSuite<T>;
|
|
440
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
import { TestSuiteInternal, } from "./_test_suite.js";
|
|
3
|
+
/** Generates an ItDefinition from ItArgs. */
|
|
4
|
+
function itDefinition(...args) {
|
|
5
|
+
let [suiteOptionsOrNameOrFn, optionsOrNameOrFn, optionsOrFn, fn,] = args;
|
|
6
|
+
let suite = undefined;
|
|
7
|
+
let name;
|
|
8
|
+
let options;
|
|
9
|
+
if (typeof suiteOptionsOrNameOrFn === "object" &&
|
|
10
|
+
typeof suiteOptionsOrNameOrFn.symbol === "symbol") {
|
|
11
|
+
suite = suiteOptionsOrNameOrFn;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
fn = optionsOrFn;
|
|
15
|
+
optionsOrFn = optionsOrNameOrFn;
|
|
16
|
+
optionsOrNameOrFn = suiteOptionsOrNameOrFn;
|
|
17
|
+
}
|
|
18
|
+
if (typeof optionsOrNameOrFn === "string") {
|
|
19
|
+
name = optionsOrNameOrFn;
|
|
20
|
+
if (typeof optionsOrFn === "function") {
|
|
21
|
+
fn = optionsOrFn;
|
|
22
|
+
options = {};
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
options = optionsOrFn;
|
|
26
|
+
if (!fn)
|
|
27
|
+
fn = options.fn;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else if (typeof optionsOrNameOrFn === "function") {
|
|
31
|
+
fn = optionsOrNameOrFn;
|
|
32
|
+
name = fn.name;
|
|
33
|
+
options = {};
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
options = optionsOrNameOrFn;
|
|
37
|
+
if (typeof optionsOrFn === "function") {
|
|
38
|
+
fn = optionsOrFn;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
fn = options.fn;
|
|
42
|
+
}
|
|
43
|
+
name = options.name ?? fn.name;
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
suite,
|
|
47
|
+
...options,
|
|
48
|
+
name,
|
|
49
|
+
fn,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** Registers an individual test case. */
|
|
53
|
+
export function it(...args) {
|
|
54
|
+
if (TestSuiteInternal.runningCount > 0) {
|
|
55
|
+
throw new Error("cannot register new test cases after already registered test cases start running");
|
|
56
|
+
}
|
|
57
|
+
const options = itDefinition(...args);
|
|
58
|
+
const { suite } = options;
|
|
59
|
+
const testSuite = suite
|
|
60
|
+
? TestSuiteInternal.suites.get(suite.symbol)
|
|
61
|
+
: TestSuiteInternal.current;
|
|
62
|
+
if (!TestSuiteInternal.started)
|
|
63
|
+
TestSuiteInternal.started = true;
|
|
64
|
+
if (testSuite) {
|
|
65
|
+
TestSuiteInternal.addStep(testSuite, options);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const { name, fn, ignore, only, permissions, sanitizeExit, sanitizeOps, sanitizeResources, } = options;
|
|
69
|
+
TestSuiteInternal.registerTest({
|
|
70
|
+
name,
|
|
71
|
+
ignore,
|
|
72
|
+
only,
|
|
73
|
+
permissions,
|
|
74
|
+
sanitizeExit,
|
|
75
|
+
sanitizeOps,
|
|
76
|
+
sanitizeResources,
|
|
77
|
+
async fn(t) {
|
|
78
|
+
TestSuiteInternal.runningCount++;
|
|
79
|
+
try {
|
|
80
|
+
await fn.call({}, t);
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
TestSuiteInternal.runningCount--;
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
it.only = function itOnly(...args) {
|
|
90
|
+
const options = itDefinition(...args);
|
|
91
|
+
return it({
|
|
92
|
+
...options,
|
|
93
|
+
only: true,
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
it.ignore = function itIgnore(...args) {
|
|
97
|
+
const options = itDefinition(...args);
|
|
98
|
+
return it({
|
|
99
|
+
...options,
|
|
100
|
+
ignore: true,
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
it.skip = it.ignore;
|
|
104
|
+
function addHook(name, fn) {
|
|
105
|
+
if (!TestSuiteInternal.current) {
|
|
106
|
+
if (TestSuiteInternal.started) {
|
|
107
|
+
throw new Error("cannot add global hooks after a global test is registered");
|
|
108
|
+
}
|
|
109
|
+
TestSuiteInternal.current = new TestSuiteInternal({
|
|
110
|
+
name: "global",
|
|
111
|
+
[name]: fn,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
TestSuiteInternal.setHook(TestSuiteInternal.current, name, fn);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/** Run some shared setup before all of the tests in the suite. */
|
|
119
|
+
export function beforeAll(fn) {
|
|
120
|
+
addHook("beforeAll", fn);
|
|
121
|
+
}
|
|
122
|
+
/** Run some shared teardown after all of the tests in the suite. */
|
|
123
|
+
export function afterAll(fn) {
|
|
124
|
+
addHook("afterAll", fn);
|
|
125
|
+
}
|
|
126
|
+
/** Run some shared setup before each test in the suite. */
|
|
127
|
+
export function beforeEach(fn) {
|
|
128
|
+
addHook("beforeEach", fn);
|
|
129
|
+
}
|
|
130
|
+
/** Run some shared teardown after each test in the suite. */
|
|
131
|
+
export function afterEach(fn) {
|
|
132
|
+
addHook("afterEach", fn);
|
|
133
|
+
}
|
|
134
|
+
/** Generates a DescribeDefinition from DescribeArgs. */
|
|
135
|
+
function describeDefinition(...args) {
|
|
136
|
+
let [suiteOptionsOrNameOrFn, optionsOrNameOrFn, optionsOrFn, fn,] = args;
|
|
137
|
+
let suite = undefined;
|
|
138
|
+
let name;
|
|
139
|
+
let options;
|
|
140
|
+
if (typeof suiteOptionsOrNameOrFn === "object" &&
|
|
141
|
+
typeof suiteOptionsOrNameOrFn.symbol === "symbol") {
|
|
142
|
+
suite = suiteOptionsOrNameOrFn;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
fn = optionsOrFn;
|
|
146
|
+
optionsOrFn = optionsOrNameOrFn;
|
|
147
|
+
optionsOrNameOrFn = suiteOptionsOrNameOrFn;
|
|
148
|
+
}
|
|
149
|
+
if (typeof optionsOrNameOrFn === "string") {
|
|
150
|
+
name = optionsOrNameOrFn;
|
|
151
|
+
if (typeof optionsOrFn === "function") {
|
|
152
|
+
fn = optionsOrFn;
|
|
153
|
+
options = {};
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
options = optionsOrFn ?? {};
|
|
157
|
+
if (!fn)
|
|
158
|
+
fn = options.fn;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else if (typeof optionsOrNameOrFn === "function") {
|
|
162
|
+
fn = optionsOrNameOrFn;
|
|
163
|
+
name = fn.name;
|
|
164
|
+
options = {};
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
options = optionsOrNameOrFn ?? {};
|
|
168
|
+
if (typeof optionsOrFn === "function") {
|
|
169
|
+
fn = optionsOrFn;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
fn = options.fn;
|
|
173
|
+
}
|
|
174
|
+
name = options.name ?? fn?.name ?? "";
|
|
175
|
+
}
|
|
176
|
+
if (!suite) {
|
|
177
|
+
suite = options.suite;
|
|
178
|
+
}
|
|
179
|
+
if (!suite && TestSuiteInternal.current) {
|
|
180
|
+
const { symbol } = TestSuiteInternal.current;
|
|
181
|
+
suite = { symbol };
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
...options,
|
|
185
|
+
suite,
|
|
186
|
+
name,
|
|
187
|
+
fn,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/** Registers a test suite. */
|
|
191
|
+
export function describe(...args) {
|
|
192
|
+
if (TestSuiteInternal.runningCount > 0) {
|
|
193
|
+
throw new Error("cannot register new test suites after already registered test cases start running");
|
|
194
|
+
}
|
|
195
|
+
const options = describeDefinition(...args);
|
|
196
|
+
if (!TestSuiteInternal.started)
|
|
197
|
+
TestSuiteInternal.started = true;
|
|
198
|
+
const { symbol } = new TestSuiteInternal(options);
|
|
199
|
+
return { symbol };
|
|
200
|
+
}
|
|
201
|
+
describe.only = function describeOnly(...args) {
|
|
202
|
+
const options = describeDefinition(...args);
|
|
203
|
+
return describe({
|
|
204
|
+
...options,
|
|
205
|
+
only: true,
|
|
206
|
+
});
|
|
207
|
+
};
|
|
208
|
+
describe.ignore = function describeIgnore(...args) {
|
|
209
|
+
const options = describeDefinition(...args);
|
|
210
|
+
return describe({
|
|
211
|
+
...options,
|
|
212
|
+
ignore: true,
|
|
213
|
+
});
|
|
214
|
+
};
|
|
215
|
+
describe.skip = describe.ignore;
|