Skip to content

YumeT023/testy

Repository files navigation

Testy 🧨

Utilizing your typical framework, write your test using Typescript decorators.

Test on npm  

What 👽 ? (it is what it is ... and what it isn't...)

It

  • a framework, which does nothing for you but convert your functionally rich file into a more modular format
  • Allows you to write your test with Typescript decorator while using your favorite testing framework
  • ... is a candy for the Java JUnit folks

It isn't

  • a re-implemented testing framework
  • a magical potion that turns your ci 🟢

Features ✨

  • Modular test
  • Decorators
    • Test Class: @TestClass(desc?)
    • Hooks: @BeforeAll, @BeforeEach, @AfterEach, @AfterAll
    • Test Suites: @Test(desc?, skip?, order?)
      • Base decorator
      • skip
      • Order (not really useful)
  • Testing Platform impl
    • Custom platform
    • jest
    • vitest
    • Mocha
    • playwright
    • cypress
    • Jasmine

Usage

The folowing example uses the Jest testing platform

Suppose you have a _function sum(...numbers)_ function in a file named `sum.ts`. You would like it to contain both the `sum` function and its `test`. Here's how you could accomplish that.

src/sum.ts

import {TestClass, Test} from "@yumii.saiko/testy";

export function sum(...numbers: number[]) {
  return numbers.reduce((acc, n) => acc + n, 0);
}

@TestClass({
  desc: "fn Sum()",
})
export class SumTest {
  @Test()
  should_compute_numbers_sum() {
    expect(sum(10, 10)).toEqual(20);
  }

  @Test({
    skip: true,
    desc: "Explicitly skip this for now",
  })
  not_implemented_yet() {}
}

Using the filename pattern that your testing framework might identify, example src/test/*/**/*.spec.ts, create a single file in which all of the Test class registrations should go.

src/test/bootstrap_test.spec.ts

import {defineTests} from "@yumii.saiko/testy";
// There we provided our own impl for jest platform
// Testy will come with a set of platform so you don't need to impl them yourself
import {PlatformJestImpl} from "../lib/testy_platform_jest";
import {SumTest} from "../sum";

defineTests([SumTest], PlatformJestImpl);

Run

npm test

screenshot (jest)

jest_testy

You can find the code for this example in the example folder

About

Write modular test using typescript decorator

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published