Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: TomokiMiyauci/unitest
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.0-beta.38
Choose a base ref
...
head repository: TomokiMiyauci/unitest
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.0.0-beta.39
Choose a head ref
  • 4 commits
  • 4 files changed
  • 2 contributors

Commits on Nov 29, 2021

  1. Copy the full SHA
    e185b5f View commit details
  2. docs: update features

    TomokiMiyauci committed Nov 29, 2021
    Copy the full SHA
    b0accf3 View commit details
  3. Copy the full SHA
    12e566a View commit details
  4. chore(release): 1.0.0-beta.39 [skip ci]

    # [1.0.0-beta.39](v1.0.0-beta.38...v1.0.0-beta.39) (2021-11-29)
    
    ### Features
    
    * **test:** accept jest style interface ([e185b5f](e185b5f))
    semantic-release-bot committed Nov 29, 2021
    Copy the full SHA
    72e88c6 View commit details
Showing with 62 additions and 23 deletions.
  1. +7 −0 CHANGELOG.md
  2. +15 −8 README.md
  3. +13 −0 e2e/test_test.ts
  4. +27 −15 test/mod.ts
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# [1.0.0-beta.39](https://github.com/TomokiMiyauci/unitest/compare/v1.0.0-beta.38...v1.0.0-beta.39) (2021-11-29)


### Features

* **test:** accept jest style interface ([e185b5f](https://github.com/TomokiMiyauci/unitest/commit/e185b5ff00c1ad9e10d40fd323fd0b05c93d6acc))

# [1.0.0-beta.38](https://github.com/TomokiMiyauci/unitest/compare/v1.0.0-beta.37...v1.0.0-beta.38) (2021-11-29)


23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -19,26 +19,33 @@ Deno-first **uni**versal **unit** testing framework

## Features

- Like jest but not jest\
- 🦕 Deno-first\
It has been designed with Deno first, and actively uses the Deno Runtime API.

- 🌎 Universal\
It is also compatible to work in browsers and Node.js environments. Use the
compatible `compat` module instead of the Deno Runtime API.

- 🃏 Like jest but not jest\
You can express declarative tests around the symbolic expect in jest. Also,
all matchers are composable and customizable. jest and jest-extended matchers
are provided as presets.

- Universal\
It is designed for use with Deno first and foremost.\
It is also compatible to work in browsers and Node.js environments.

- Compositable\
- :recycle: Compositable\
Unitest is also intended to be used in a browser.\
For this reason, we provide a composable interface to keep the bundle size as
small as possible.

- TypeScript-first\
- 📄 TypeScript-first\
Type-safe tests can be expressed. A type filter restricts the availability of
only those matchers that satisfy the data type under test.\
It also keeps the bundle size small by transferring part of the data type
validation to TypeScript.

- :wolf: Isolated\
Each module is independent, with no dependency on context. This means that
they can be combined with any module.

## Getting Started

Visit <https://unitest.vercel.app/> to get started with Unitest.
@@ -92,5 +99,5 @@ Released under the [MIT](./LICENSE) license
- ~~toReject~~ not pure
- ~~toBeHexadecimal~~ -> toBeHexColor
- [x] Implement interface of custom matcher
- [ ] Implement `it` suite
- [ ] Implement `test` suite
- [ ] ~~Implement `describe` suite~~
13 changes: 13 additions & 0 deletions e2e/test_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2021-Present the Unitest authors. All rights reserved. MIT license.
import { expect, test } from "../mod.ts";

test("should work as jest style", () => {
expect("jest").toBeTruthy();
});

test({
name: "should work Deno.test sytle",
fn: () => {
expect("deno").toBeTruthy();
},
});
42 changes: 27 additions & 15 deletions test/mod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright 2021-Present the Unitest authors. All rights reserved. MIT license.
import { AnyFn } from "../_types.ts";
import { isString } from "../deps.ts";
import { each } from "./each.ts";

type Test<Context extends Record<PropertyKey, unknown>> = {
@@ -20,21 +21,32 @@ function defineTest<T extends Record<string | symbol, AnyFn>>({
return _test as never;
}

function _test<T extends Record<PropertyKey, unknown>>(t: Test<T>) {
const { setup, teardown, fn, ...rest } = t;

Deno.test({
...rest,
fn: (denoContext) => {
const context = setup?.() ?? {} as T;

try {
fn({ ...context, ...denoContext });
} finally {
teardown?.(context);
}
},
});
function _test<T extends Record<PropertyKey, unknown>>(t: Test<T>): void;
function _test(
name: string,
fn: Deno.TestDefinition["fn"],
): void;
function _test<T extends Record<PropertyKey, unknown>>(
t: string | Test<T>,
...args: Deno.TestDefinition["fn"][]
): void {
if (isString(t)) {
Deno.test(t, args[0]);
} else {
const { setup, teardown, fn, ...rest } = t;
Deno.test({
...rest,
fn: (denoContext) => {
const context = setup?.() ?? {} as T;

try {
fn({ ...context, ...denoContext });
} finally {
teardown?.(context);
}
},
});
}
}

const test = defineTest({