Effection Logo
@effection-contrib/test-adapterv0.1.0thefrontside/effection-contrib
JSR BadgeNPM Badge with published versionBundle size badgeDependency count badgeTree shaking support badge
import { } from "@effection-contrib/test-adapter"

Test Adapter

An abstract helper for integrating Effection with testing frameworks.

Typically, you won't use this module directly, but instead you'll use one of the actual testing framework integrations. The following shows how you might integrate it with the @std/bdd module. You would never use it this way, this demonstrates the general pattern of lifecycle.

import { run, sleep } from "effection";
import { createTestAdapter, TestAdapter } from "@effection-contrib/test-adapter";
import { describe, it, beforeEach } from "@std/bdd";


describe("something", () => {
  let adapter: TestAdapter;
  beforeAll(() => {)
    adapter = createTestAdapter("something");
  });
  
  afterAll(() => adapter.destroy())
  
  adapter.addSetup(function*() {
    /* do some setup. equivalent of beforeEach() */
	/* contexts set here will be visible in the test */*
  });
  
  it("does a thing", async () => {
    await adapter.runTest(function*() {
	  /* ... the body of the test */
	});
  });

});

API Reference

interface TestOperation

interface TestAdapter

Properties

parentreadonlyoptional: TestAdapter

The parent of this adapter. All of the setup from this adapter will be run in addition to the setup of this adapter during runTest()

namereadonly: string

The name of this adapter which is mostly useful for debugging purposes

fullnamereadonly: string

A qualified name that contains not only the name of this adapter, but of all its ancestors. E.g. All Tests > File System > write

scopereadonly: Scope

Every test adapter has its own Effection Scope which holds the resources necessary to run this test.

lineagereadonly: Array<TestAdapter>

A list of this test adapter and every adapter that it descends from.

setupsreadonly: TestOperation[]

The setup operations that will be run by this test adapter. It only includes those setups that are associated with this adapter, not those of its ancestors.

Methods

addSetup
(op: TestOperation): void

Add a setup operation to every test that is part of this adapter. In BDD integrations, this is usually called by beforEach()

runTest
(body: TestOperation): Future<void>

Actually run a test. This evaluates all setup operations, and then after those have completed it runs the body of the test itself.

destroy
(): Future<void>

Teardown this test adapter and all of the task and resources that are running inside it. This basically destroys the Effection Scope associated with this adapter.

interface TestAdapterOptions

Properties

nameoptional: string

The name of this test adapter which is handy for debugging. Usually, you'll give this the same name as the current test context. For example, when integrating with BDD, this would be the same as

parentoptional: TestAdapter

The parent test adapter. All of the setup from this adapter will be run in addition to the setup of this adapter during runTest()

function createTestAdapter(): TestAdapter

Create a new test adapter with the given options.

Parameters

Return Type

TestAdapter