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

Commit

Permalink
Merge pull request #35 from udibo/dev
Browse files Browse the repository at this point in the history
Fix only on multiple tests in different suites
  • Loading branch information
KyleJune authored Apr 3, 2022
2 parents 08f50f4 + f91e624 commit 677ad8e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Test Suite

[![version](https://img.shields.io/badge/release-0.15.0-success)](https://deno.land/x/test_suite@0.15.0)
[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/test_suite@0.15.0/mod.ts)
[![version](https://img.shields.io/badge/release-0.16.0-success)](https://deno.land/x/test_suite@0.16.0)
[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/test_suite@0.16.0/mod.ts)
[![CI](https://github.com/udibo/test_suite/workflows/CI/badge.svg)](https://github.com/udibo/test_suite/actions?query=workflow%3ACI)
[![codecov](https://codecov.io/gh/udibo/test_suite/branch/main/graph/badge.svg?token=EFKGY72AAV)](https://codecov.io/gh/udibo/test_suite)
[![license](https://img.shields.io/github/license/udibo/test_suite)](https://github.com/udibo/test_suite/blob/master/LICENSE)
Expand All @@ -26,12 +26,12 @@ also be imported directly from GitHub using raw content URLs.

```ts
// Import from Deno's third party module registry
import { describe, it } from "https://deno.land/x/test_suite@0.15.0/mod.ts";
import { describe, it } from "https://deno.land/x/test_suite@0.16.0/mod.ts";
// Import from GitHub
import {
describe,
it,
} from "https://raw.githubusercontent.com/udibo/test_suite/0.15.0/mod.ts";
} from "https://raw.githubusercontent.com/udibo/test_suite/0.16.0/mod.ts";
```

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

See
[deno docs](https://doc.deno.land/https/deno.land/x/test_suite@0.15.0/mod.ts)
[deno docs](https://doc.deno.land/https/deno.land/x/test_suite@0.16.0/mod.ts)
for more information.

### Nested test grouping
Expand All @@ -67,13 +67,13 @@ import {
beforeEach,
describe,
it,
} from "https://deno.land/x/test_suite@0.15.0/mod.ts";
} from "https://deno.land/x/test_suite@0.16.0/mod.ts";
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import {
getUser,
resetUsers,
User,
} from "https://deno.land/x/test_suite@0.15.0/examples/user.ts";
} from "https://deno.land/x/test_suite@0.16.0/examples/user.ts";

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

```ts
import { describe, it } from "https://deno.land/x/test_suite@0.15.0/mod.ts";
import { describe, it } from "https://deno.land/x/test_suite@0.16.0/mod.ts";
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import {
getUser,
resetUsers,
User,
} from "https://deno.land/x/test_suite@0.15.0/examples/user.ts";
} from "https://deno.land/x/test_suite@0.16.0/examples/user.ts";

interface UserContext {
user: User;
Expand Down
31 changes: 14 additions & 17 deletions test_suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,8 @@ export class TestSuiteInternal<T> implements TestSuite<T> {
if (!suite.hasOnlyStep) {
for (let i = 0; i < suite.steps.length; i++) {
const step = suite.steps[i]!;
if (step instanceof TestSuiteInternal) {
if (!(step.hasOnlyStep || step.describe.only)) {
suite.steps.splice(i--, 1);
}
} else {
if (!step.only) {
suite.steps.splice(i--, 1);
}
if (!(step instanceof TestSuiteInternal) && !step.only) {
suite.steps.splice(i--, 1);
}
}
suite.hasOnlyStep = true;
Expand Down Expand Up @@ -224,16 +218,11 @@ export class TestSuiteInternal<T> implements TestSuite<T> {
}
}

let omit = false;
if (suite.hasOnlyStep) {
if (step instanceof TestSuiteInternal) {
if (!(step.hasOnlyStep || step.describe.only)) omit = true;
} else {
if (!step.only) omit = true;
}
if (
!(suite.hasOnlyStep && !(step instanceof TestSuiteInternal) && !step.only)
) {
suite.steps.push(step);
}

if (!omit) suite.steps.push(step);
}

/** This is used internally to add hooks to a test suite. */
Expand All @@ -260,7 +249,15 @@ export class TestSuiteInternal<T> implements TestSuite<T> {
context: T,
t: Deno.TestContext,
): Promise<void> {
const hasOnly = suite.hasOnlyStep || suite.describe.only || false;
for (const step of suite.steps) {
if (
hasOnly && step instanceof TestSuiteInternal &&
!(step.hasOnlyStep || step.describe.only || false)
) {
continue;
}

const {
name,
fn,
Expand Down

0 comments on commit 677ad8e

Please sign in to comment.