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

Commit 67e8e62

Browse files
authored
Merge pull request #28 from udibo/dev
Hide internal TestSuite object
2 parents af5ef32 + 40f61c6 commit 67e8e62

File tree

6 files changed

+115
-118
lines changed

6 files changed

+115
-118
lines changed

README.md

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Test Suite
22

3-
[![version](https://img.shields.io/badge/release-0.10.2-success)](https://deno.land/x/test_suite@0.10.1)
4-
[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/test_suite@0.10.2/mod.ts)
3+
[![version](https://img.shields.io/badge/release-0.11.0-success)](https://deno.land/x/test_suite@0.11.0)
4+
[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/test_suite@0.11.0/mod.ts)
55
[![CI](https://github.com/udibo/test_suite/workflows/CI/badge.svg)](https://github.com/udibo/test_suite/actions?query=workflow%3ACI)
66
[![codecov](https://codecov.io/gh/udibo/test_suite/branch/main/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)
@@ -26,12 +26,12 @@ also be imported directly from GitHub using raw content URLs.
2626

2727
```ts
2828
// Import from Deno's third party module registry
29-
import { describe, it } from "https://deno.land/x/test_suite@0.10.2/mod.ts";
29+
import { describe, it } from "https://deno.land/x/test_suite@0.11.0/mod.ts";
3030
// Import from GitHub
3131
import {
3232
describe,
3333
it,
34-
} from "https://raw.githubusercontent.com/udibo/test_suite/0.10.2/mod.ts";
34+
} from "https://raw.githubusercontent.com/udibo/test_suite/0.11.0/mod.ts";
3535
```
3636

3737
## Usage
@@ -52,7 +52,7 @@ except they are called before and after each individual test.
5252
Below are some examples of how to use `describe` and `it` in tests.
5353

5454
See
55-
[deno docs](https://doc.deno.land/https/deno.land/x/test_suite@0.10.2/mod.ts)
55+
[deno docs](https://doc.deno.land/https/deno.land/x/test_suite@0.11.0/mod.ts)
5656
for more information.
5757

5858
### Nested test grouping
@@ -65,13 +65,13 @@ import {
6565
beforeEach,
6666
describe,
6767
it,
68-
} from "https://deno.land/x/test_suite@0.10.2/mod.ts";
69-
import { assertEquals } from "https://deno.land/std@0.127.0/testing/asserts.ts";
68+
} from "https://deno.land/x/test_suite@0.11.0/mod.ts";
69+
import { assertEquals } from "https://deno.land/std@0.128.0/testing/asserts.ts";
7070
import {
7171
getUser,
7272
resetUsers,
7373
User,
74-
} from "https://deno.land/x/test_suite@0.10.2/examples/user.ts";
74+
} from "https://deno.land/x/test_suite@0.11.0/examples/user.ts";
7575

7676
describe("user describe", () => {
7777
let user: User;
@@ -129,13 +129,13 @@ test result: ok. 1 passed (5 steps); 0 failed; 0 ignored; 0 measured; 0 filtered
129129
The example below can be found [here](examples/user_flat_test.ts).
130130

131131
```ts
132-
import { describe, it } from "https://deno.land/x/test_suite@0.10.2/mod.ts";
133-
import { assertEquals } from "https://deno.land/std@0.127.0/testing/asserts.ts";
132+
import { describe, it } from "https://deno.land/x/test_suite@0.11.0/mod.ts";
133+
import { assertEquals } from "https://deno.land/std@0.128.0/testing/asserts.ts";
134134
import {
135135
getUser,
136136
resetUsers,
137137
User,
138-
} from "https://deno.land/x/test_suite@0.10.2/examples/user.ts";
138+
} from "https://deno.land/x/test_suite@0.11.0/examples/user.ts";
139139

140140
interface UserContext {
141141
user: User;
@@ -156,11 +156,7 @@ it(userSuite, "create", () => {
156156
assertEquals(user.name, "John Doe");
157157
});
158158

159-
interface GetUserContext extends UserContext {
160-
value?: number;
161-
}
162-
163-
const getUserSuite = describe<GetUserContext>({
159+
const getUserSuite = describe({
164160
name: "getUser",
165161
suite: userSuite,
166162
});

describe.ts

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
ItDefinition,
55
TestSuite,
66
} from "./test_suite.ts";
7-
export type { DescribeDefinition, ItDefinition, TestSuite };
7+
export type { DescribeDefinition, ItDefinition };
88

99
/** The arguments for an ItFunction. */
1010
type ItArgs<T> =
@@ -32,32 +32,32 @@ type ItArgs<T> =
3232
fn: (context: T) => void | Promise<void>,
3333
]
3434
| [
35-
suite: TestSuite<T>,
35+
suite: symbol,
3636
name: string,
3737
options: Omit<ItDefinition<T>, "name" | "suite">,
3838
]
3939
| [
40-
suite: TestSuite<T>,
40+
suite: symbol,
4141
name: string,
4242
fn: (context: T) => void | Promise<void>,
4343
]
4444
| [
45-
suite: TestSuite<T>,
45+
suite: symbol,
4646
fn: (context: T) => void | Promise<void>,
4747
]
4848
| [
49-
suite: TestSuite<T>,
49+
suite: symbol,
5050
name: string,
5151
options: Omit<ItDefinition<T>, "fn" | "name" | "suite">,
5252
fn: (context: T) => void | Promise<void>,
5353
]
5454
| [
55-
suite: TestSuite<T>,
55+
suite: symbol,
5656
options: Omit<ItDefinition<T>, "fn" | "suite">,
5757
fn: (context: T) => void | Promise<void>,
5858
]
5959
| [
60-
suite: TestSuite<T>,
60+
suite: symbol,
6161
options: Omit<ItDefinition<T>, "fn" | "name" | "suite">,
6262
fn: (context: T) => void | Promise<void>,
6363
];
@@ -70,14 +70,14 @@ function itDefinition<T>(...args: ItArgs<T>): ItDefinition<T> {
7070
optionsOrFn,
7171
fn,
7272
] = args;
73-
let suite: TestSuite<T> | undefined = undefined;
73+
let suite: symbol | undefined = undefined;
7474
let name: string;
7575
let options:
7676
| ItDefinition<T>
7777
| Omit<ItDefinition<T>, "fn">
7878
| Omit<ItDefinition<T>, "name">
7979
| Omit<ItDefinition<T>, "fn" | "name">;
80-
if (suiteOptionsOrNameOrFn instanceof TestSuite) {
80+
if (typeof suiteOptionsOrNameOrFn === "symbol") {
8181
suite = suiteOptionsOrNameOrFn;
8282
} else {
8383
fn = optionsOrFn as typeof fn;
@@ -134,13 +134,12 @@ export function it<T>(...args: ItArgs<T>): void {
134134
);
135135
}
136136
const options = itDefinition(...args);
137-
let { suite } = options;
138-
139-
suite ??= TestSuite.current as TestSuite<T>;
137+
const { suite } = options;
138+
const testSuite = suite ? TestSuite.suites.get(suite) : TestSuite.current;
140139

141140
if (!TestSuite.started) TestSuite.started = true;
142-
if (suite) {
143-
TestSuite.addStep(suite, options);
141+
if (testSuite) {
142+
TestSuite.addStep(testSuite, options);
144143
} else {
145144
const {
146145
name,
@@ -255,36 +254,36 @@ type DescribeArgs<T> =
255254
fn: () => void,
256255
]
257256
| [
258-
suite: TestSuite<T>,
257+
suite: symbol,
259258
name: string,
260259
]
261260
| [
262-
suite: TestSuite<T>,
261+
suite: symbol,
263262
name: string,
264263
options: Omit<DescribeDefinition<T>, "name" | "suite">,
265264
]
266265
| [
267-
suite: TestSuite<T>,
266+
suite: symbol,
268267
name: string,
269268
fn: () => void,
270269
]
271270
| [
272-
suite: TestSuite<T>,
271+
suite: symbol,
273272
fn: () => void,
274273
]
275274
| [
276-
suite: TestSuite<T>,
275+
suite: symbol,
277276
name: string,
278277
options: Omit<DescribeDefinition<T>, "fn" | "name" | "suite">,
279278
fn: () => void,
280279
]
281280
| [
282-
suite: TestSuite<T>,
281+
suite: symbol,
283282
options: Omit<DescribeDefinition<T>, "fn" | "suite">,
284283
fn: () => void,
285284
]
286285
| [
287-
suite: TestSuite<T>,
286+
suite: symbol,
288287
options: Omit<DescribeDefinition<T>, "fn" | "name" | "suite">,
289288
fn: () => void,
290289
];
@@ -299,14 +298,14 @@ function describeDefinition<T>(
299298
optionsOrFn,
300299
fn,
301300
] = args;
302-
let suite: TestSuite<T> | undefined = undefined;
301+
let suite: symbol | undefined = undefined;
303302
let name: string;
304303
let options:
305304
| DescribeDefinition<T>
306305
| Omit<DescribeDefinition<T>, "fn">
307306
| Omit<DescribeDefinition<T>, "name">
308307
| Omit<DescribeDefinition<T>, "fn" | "name">;
309-
if (suiteOptionsOrNameOrFn instanceof TestSuite) {
308+
if (typeof suiteOptionsOrNameOrFn === "symbol") {
310309
suite = suiteOptionsOrNameOrFn;
311310
} else {
312311
fn = optionsOrFn as typeof fn;
@@ -337,7 +336,7 @@ function describeDefinition<T>(
337336
}
338337

339338
if (!suite) {
340-
suite = options.suite ?? TestSuite.current as TestSuite<T>;
339+
suite = options.suite ?? TestSuite.current?.symbol;
341340
}
342341

343342
return {
@@ -350,32 +349,32 @@ function describeDefinition<T>(
350349

351350
/** Registers a test suite. */
352351
export interface describe {
353-
<T>(...args: DescribeArgs<T>): TestSuite<T>;
352+
<T>(...args: DescribeArgs<T>): symbol;
354353

355354
/** Registers a test suite with only set to true. */
356-
only<T>(...args: DescribeArgs<T>): TestSuite<T>;
355+
only<T>(...args: DescribeArgs<T>): symbol;
357356

358357
/** Registers a test suite with ignore set to true. */
359-
ignore<T>(...args: DescribeArgs<T>): TestSuite<T>;
358+
ignore<T>(...args: DescribeArgs<T>): symbol;
360359
}
361360

362361
/** Registers a test suite. */
363362
export function describe<T>(
364363
...args: DescribeArgs<T>
365-
): TestSuite<T> {
364+
): symbol {
366365
if (TestSuite.running) {
367366
throw new Error(
368367
"cannot register new test suites after already registered test cases start running",
369368
);
370369
}
371370
const options = describeDefinition(...args);
372371
if (!TestSuite.started) TestSuite.started = true;
373-
return new TestSuite(options);
372+
return (new TestSuite(options)).symbol;
374373
}
375374

376375
describe.only = function describeOnly<T>(
377376
...args: DescribeArgs<T>
378-
): TestSuite<T> {
377+
): symbol {
379378
const options = describeDefinition(...args);
380379
return describe({
381380
...options,
@@ -385,7 +384,7 @@ describe.only = function describeOnly<T>(
385384

386385
describe.ignore = function describeIgnore<T>(
387386
...args: DescribeArgs<T>
388-
): TestSuite<T> {
387+
): symbol {
389388
const options = describeDefinition(...args);
390389
return describe({
391390
...options,

0 commit comments

Comments
 (0)