Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(testing): improve the docs of @std/testing #5033

Merged
merged 20 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion _tools/check_docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ const ENTRY_POINTS = [
"../semver/mod.ts",
"../streams/mod.ts",
"../text/mod.ts",
"../testing/bdd.ts",
"../testing/mock.ts",
"../testing/snapshot.ts",
"../testing/time.ts",
"../testing/types.ts",
iuioiua marked this conversation as resolved.
Show resolved Hide resolved
"../toml/mod.ts",
"../ulid/mod.ts",
"../url/mod.ts",
Expand All @@ -67,7 +72,8 @@ const ENTRY_POINTS = [
] as const;

const TS_SNIPPET = /```ts[\s\S]*?```/g;
const ASSERTION_IMPORT = /import \{.*\} from "@std\/assert(?:\/.*)?";/gm;
const ASSERTION_IMPORT =
/from "@std\/(assert(\/[a-z-]+)?|testing\/(mock|snapshot|types))"/g;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed import \{.*\} part as this doesn't work if there are line breaks between import and from.

Also added testing\/(mock|snapshot|types) part as these files also include assertion functions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having assertions spread across multiple packages is confusing. What if we moved assertions (only) to @std/assert? WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes @std/assert a huge package. In the current layout, assertions are organized by the category (mock / snapshot / types). This makes more sense to me.

const NEWLINE = "\n";
const diagnostics: DocumentError[] = [];
const snippetPromises: Promise<void>[] = [];
Expand Down
7 changes: 7 additions & 0 deletions testing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This package provides utilities for testing.

- [BDD style testing](https://jsr.io/@std/testing/doc/bdd/~)
- [Test doubles (mocking)](https://jsr.io/@std/testing/doc/mock/~)
- [Faking time and timers](https://jsr.io/@std/testing/doc/time/~)
- [Snapshot testing](https://jsr.io/@std/testing/doc/snapshot/~)
- [Type assertions](https://jsr.io/@std/testing/doc/types/~)
3 changes: 3 additions & 0 deletions testing/_test_suite.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
/** The options for creating a test suite with the describe function. */
export interface DescribeDefinition<T> extends Omit<Deno.TestDefinition, "fn"> {
/** The body of the test suite */
fn?: () => void;
/**
* The `describe` function returns a `TestSuite` representing the group of tests.
Expand Down Expand Up @@ -28,6 +29,7 @@ export interface DescribeDefinition<T> extends Omit<Deno.TestDefinition, "fn"> {

/** The options for creating an individual test case with the it function. */
export interface ItDefinition<T> extends Omit<Deno.TestDefinition, "fn"> {
/** The body of the test case */
fn: (this: T, t: Deno.TestContext) => void | Promise<void>;
/**
* The `describe` function returns a `TestSuite` representing the group of tests.
Expand Down Expand Up @@ -62,6 +64,7 @@ const optionalTestStepDefinitionKeys: (keyof Deno.TestStepDefinition)[] = [
* A group of tests.
*/
export interface TestSuite<T> {
/** The symbol to use for grouping the test suite */
symbol: symbol;
}

Expand Down
Loading