Skip to content
This repository was archived by the owner on Apr 18, 2022. It is now read-only.

Commit 7f8a125

Browse files
committed
Bump version
1 parent 2a32482 commit 7f8a125

File tree

3 files changed

+122
-100
lines changed

3 files changed

+122
-100
lines changed

README.md

Lines changed: 120 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
[![codecov](https://codecov.io/gh/udibo/test_suite/branch/master/graph/badge.svg?token=EFKGY72AAV)](https://codecov.io/gh/udibo/test_suite)
77
[![license](https://img.shields.io/github/license/udibo/test_suite)](https://github.com/udibo/test_suite/blob/master/LICENSE)
88

9-
An extension of Deno's built-in test runner to add setup/teardown hooks and the
10-
ability to organize tests. Includes describe/it functions for creating nested
11-
tests in a format similar to Jasmine, Jest, and Mocha.
9+
An extension of Deno's built-in test runner to add setup/teardown hooks and make
10+
it easier to organize tests in a format similar to Jasmine, Jest, and Mocha.
1211

1312
## Features
1413

1514
- Ability to group tests together into test suites
16-
- Setup/teardown hooks for test suites(beforeAll, afterAll, beforeEach,
15+
- Setup/teardown hooks for test suites (beforeAll, afterAll, beforeEach,
1716
afterEach)
1817
- Tests within a test suite inherit configuration options
1918
- describe/it functions similar to Jasmine, Jest, and Mocha
19+
- shorthand for focusing and ignoring tests
2020

2121
## Installation
2222

@@ -26,21 +26,13 @@ also be imported directly from GitHub using raw content URLs.
2626

2727
```ts
2828
// Import from Deno's third party module registry
29-
import { TestSuite, test } from "https://deno.land/x/test_suite@0.10.0/mod.ts";
29+
import { describe, it } from "https://deno.land/x/test_suite@0.10.0/mod.ts";
3030
// Import from GitHub
31-
import { TestSuite, test } "https://raw.githubusercontent.com/udibo/test_suite/0.10.0/mod.ts";
31+
import { describe, it } "https://raw.githubusercontent.com/udibo/test_suite/0.10.0/mod.ts";
3232
```
3333
3434
## Usage
3535
36-
Below are some examples of how to use TestSuite and test in tests.
37-
38-
See
39-
[deno docs](https://doc.deno.land/https/deno.land/x/test_suite@0.10.0/mod.ts)
40-
for more information.
41-
42-
### TestSuite
43-
4436
When you have a set of tests that are related, you can group them together by
4537
creating a test suite. A test suite can contain other test suites and tests. All
4638
tests within a suite will inherit their options from the suite unless they
@@ -54,85 +46,15 @@ values available to the tests that are defined in the beforeAll function.
5446
The beforeEach and afterEach hook options are similar to beforeAll and afterAll
5547
except they are called before and after each individual test.
5648
57-
The example test below can be found in the example directory.
58-
59-
```ts
60-
import { test, TestSuite } from "https://deno.land/x/test_suite@0.10.0/mod.ts";
61-
import { assertEquals } from "https://deno.land/std@0.125.0/testing/asserts.ts";
62-
import {
63-
getUser,
64-
resetUsers,
65-
User,
66-
} from "https://deno.land/x/test_suite@0.10.0/example/user.ts";
67-
68-
interface UserSuiteContext {
69-
user: User;
70-
}
71-
const userSuite: TestSuite<UserSuiteContext> = new TestSuite({
72-
name: "user",
73-
beforeEach(context: UserSuiteContext) {
74-
context.user = new User("Kyle June");
75-
},
76-
afterEach() {
77-
resetUsers();
78-
},
79-
});
49+
Below are some examples of how to use `describe` and `it` in tests.
8050
81-
test(userSuite, "create", () => {
82-
const user = new User("John Doe");
83-
assertEquals(user.name, "John Doe");
84-
});
85-
86-
const getUserSuite: TestSuite<UserSuiteContext> = new TestSuite({
87-
name: "getUser",
88-
suite: userSuite,
89-
});
90-
91-
test(getUserSuite, "user does not exist", () => {
92-
assertEquals(getUser("John Doe"), undefined);
93-
});
94-
95-
test(getUserSuite, "user exists", (context: UserSuiteContext) => {
96-
assertEquals(getUser("Kyle June"), context.user);
97-
});
98-
99-
test(userSuite, "resetUsers", (context: UserSuiteContext) => {
100-
assertEquals(getUser("Kyle June"), context.user);
101-
resetUsers();
102-
assertEquals(getUser("Kyle June"), undefined);
103-
});
104-
```
105-
106-
If you run the above tests using `deno test`, you will get the following output.
107-
Each test name is prefixed with the suite name.
108-
109-
```sh
110-
$ deno test
111-
running 4 tests
112-
test user create ... ok (4ms)
113-
test user getUser user does not exist ... ok (1ms)
114-
test user getUser user exists ... ok (2ms)
115-
test user resetUsers ... ok (2ms)
116-
117-
test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out (11ms)
118-
```
119-
120-
### describe/it
121-
122-
When you have a set of tests that are related, you can group them together by
123-
creating a test suite with describe. A test suite can contain other test suites
124-
and tests. All tests within a suite will inherit their options from the suite
125-
unless they specifically set them.
126-
127-
The beforeAll and afterAll hook options can be used to do something before and
128-
after all the tests in the suite run. If you would like to set values for all
129-
tests within the suite, you can create a context interface that defines all the
130-
values available to the tests that are defined in the beforeAll function.
51+
See
52+
[deno docs](https://doc.deno.land/https/deno.land/x/test_suite@0.10.0/mod.ts)
53+
for more information.
13154
132-
The beforeEach and afterEach hook options are similar to beforeAll and afterAll
133-
except they are called before and after each individual test.
55+
### Nested test grouping
13456
135-
The example test below can be found in the example directory.
57+
The example below can be found [here](examples/user_nested_test.ts).
13658
13759
```ts
13860
import {
@@ -141,7 +63,7 @@ import {
14163
describe,
14264
it,
14365
} from "https://deno.land/x/test_suite@0.10.0/mod.ts";
144-
import { assertEquals } from "https://deno.land/std@0.125.0/testing/asserts.ts";
66+
import { assertEquals } from "https://deno.land/std@0.126.0/testing/asserts.ts";
14567
import {
14668
getUser,
14769
resetUsers,
@@ -183,19 +105,119 @@ describe("user describe", () => {
183105
```
184106

185107
If you run the above tests using `deno test`, you will get the following output.
186-
Each test name is prefixed with the suite name.
187108

188109
```sh
189110
$ deno test
190-
running 4 tests
191-
test user describe create ... ok (4ms)
192-
test user describe getUser user does not exist ... ok (1ms)
193-
test user describe getUser user exists ... ok (2ms)
194-
test user describe resetUsers ... ok (2ms)
111+
running 1 test from file:///examples/user_nested_test.ts
112+
test user describe ...
113+
test create ... ok (4ms)
114+
test getUser ...
115+
test user does not exist ... ok (4ms)
116+
test user exists ... ok (3ms)
117+
ok (11ms)
118+
test resetUsers ... ok (3ms)
119+
ok (24ms)
120+
121+
test result: ok. 1 passed (5 steps); 0 failed; 0 ignored; 0 measured; 0 filtered out (43ms)
122+
```
123+
124+
### Flat test grouping
125+
126+
The example below can be found [here](examples/user_flat_test.ts).
127+
128+
```ts
129+
import { test, TestSuite } from "https://deno.land/x/test_suite@0.10.0/mod.ts";
130+
import { assertEquals } from "https://deno.land/std@0.126.0/testing/asserts.ts";
131+
import {
132+
getUser,
133+
resetUsers,
134+
User,
135+
} from "https://deno.land/x/test_suite@0.10.0/example/user.ts";
136+
137+
interface UserContext {
138+
user: User;
139+
}
140+
141+
const userSuite = describe({
142+
name: "user",
143+
beforeEach(context: UserContext) {
144+
context.user = new User("Kyle June");
145+
},
146+
afterEach() {
147+
resetUsers();
148+
},
149+
});
150+
151+
it(userSuite, "create", () => {
152+
const user = new User("John Doe");
153+
assertEquals(user.name, "John Doe");
154+
});
195155

196-
test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out (11ms)
156+
interface GetUserContext extends UserContext {
157+
value?: number;
158+
}
159+
160+
const getUserSuite = describe<GetUserContext>({
161+
name: "getUser",
162+
suite: userSuite,
163+
});
164+
165+
it(getUserSuite, "user does not exist", () => {
166+
assertEquals(getUser("John Doe"), undefined);
167+
});
168+
169+
it(getUserSuite, "user exists", (context: UserContext) => {
170+
assertEquals(getUser("Kyle June"), context.user);
171+
});
172+
173+
it(userSuite, "resetUsers", (context: UserContext) => {
174+
assertEquals(getUser("Kyle June"), context.user);
175+
resetUsers();
176+
assertEquals(getUser("Kyle June"), undefined);
177+
});
178+
```
179+
180+
If you run the above tests using `deno test`, you will get the following output.
181+
182+
```sh
183+
$ deno test
184+
running 1 test from file:///examples/user_flat_test.ts
185+
test user ...
186+
test create ... ok (3ms)
187+
test getUser ...
188+
test user does not exist ... ok (2ms)
189+
test user exists ... ok (4ms)
190+
ok (11ms)
191+
test resetUsers ... ok (3ms)
192+
ok (22ms)
193+
194+
test result: ok. 1 passed (5 steps); 0 failed; 0 ignored; 0 measured; 0 filtered out (44ms)
197195
```
198196

197+
### Shorthand for focusing and ignoring tests
198+
199+
To avoid having to change your test function arguments to be able to focus or
200+
ignore tests temporarily, a shorthand has been implemented. This makes it as
201+
easy as typing `.only` and `.ignore` to focus and ignore tests.
202+
203+
- To focus a test case, replace `it` with `it.only`.
204+
- To ignore a test case, replace `it` with `it.ignore`.
205+
- To focus a test suite, replace `describe` with `describe.only`.
206+
- To ignore a test suite, replace `describe` with `describe.ignore`.
207+
208+
### Migrating from earlier versions
209+
210+
The `TestSuite` class has been turned into an internal only class. To create a
211+
test suite, use the `describe` function instead of creating a new instance of
212+
`TestSuite` directly.
213+
214+
The `test` function has been removed. Replace `test` calls with calls to `it`.
215+
216+
The `each` function that was previously available has been temporarily removed
217+
to allow me to switch over to the test step api quicker. I plan on implementing
218+
this later. If you make use of the `each` function for generating test cases, do
219+
not upgrade beyond version 0.9.5.
220+
199221
## License
200222

201223
[MIT](LICENSE)

deps.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { delay } from "https://deno.land/std@0.125.0/async/delay.ts";
1+
export { delay } from "https://deno.land/std@0.126.0/async/delay.ts";
22
export {
33
assert,
44
assertEquals,
@@ -7,6 +7,6 @@ export {
77
assertRejects,
88
assertStrictEquals,
99
assertThrows,
10-
} from "https://deno.land/std@0.125.0/testing/asserts.ts";
10+
} from "https://deno.land/std@0.126.0/testing/asserts.ts";
1111

1212
export { Vector } from "https://deno.land/x/collections@0.11.2/vector.ts";

0 commit comments

Comments
 (0)