Class: TestDK<T>
Class that abstracts over a Cubist project's testing process. In particular, this class makes it possible to (1) create Cubist (or CubistORM) projects with temporary build and deploy directories and (2) start and stop services when running tests.
Example
Using TestDK to test CubistORM projects with
Jest. The cubist build
command generates CubistORM
at build time; this class extends Cubist with
project-specific contracts (see the Overview).
import { TestDK, } from '@cubist-labs/cubist';
import { CubistORM } from '../build/orm';
const testdk = new TestDK<CubistORM>(CubistORM, { tmp_deploy_dir: true });
beforeAll(async () => {
await testdk.startService();
});
afterAll(async () => {
await testdk.stopService();
});
beforeEach(async () => {
await testdk.emptyDeployDir();
});
// get the project under test
const cubist = testdk.cubist;
// .. use cubist to get contracts and contract factories, as usual ...
In this example, we create a new testing CubistORM project whose deploy
directory is set to a new temporary directory. This lets you test your
project without clobbering existing deploy receipts.
We start services---chains and relayer---before all tests, and stop them at the end.
We also empty the deploy
directory before each test.
Type parameters
Name | Type |
---|---|
T | extends Cubist |
Hierarchy
TestDK
Exports
Constructors
Accessors
Methods
Constructors
constructor
• new TestDK<T
>(CubistX
, options?
)
Create new instance of TestDK.
Example
Testing project in fresh deploy directory.
const testdk = new TestDK<CubistORM>(CubistORM, { tmp_deploy_dir: true });
Example
Testing project in fresh build and deploy directory.
const testdk = new TestDK<Cubist>(Cubist, { tmp_build_dir: true, tmp_deploy_dir: true });
beforeAll(async () => {
// build the project
await testdk.build();
// start chains and relayer
await testdk.startService();
});
Example
Testing already-built (and deployed) project.
const testdk = new TestDK<Cubist>(Cubist);
Type parameters
Name | Type |
---|---|
T | extends Cubist <T > |
Parameters
Name | Type | Description |
---|---|---|
CubistX | CubistClassRef <T > | Reference to Cubist class. |
options? | TestDKOptions | - |
Defined in
submodules/cubist-node-sdk/src/test.ts:158
Accessors
config
• get
config(): Config
Get the underlying config.
Returns
Defined in
submodules/cubist-node-sdk/src/test.ts:203
cubist
• get
cubist(): T
Get the cubist project we're testing.
::: warning Whenever you use TestDK, you should always use this accessors to get a reference to the Cubist project. Creating a new Cubist object could have unwanted behavior. Here is an example how things can go wrong: :::
const testdk = new TestDK<CubistORM>(CubistORM, { tmp_deploy_dir: true });
const cubist = testdk.cubist; // this is correct
const bad_cubist = new Cubist(); // this is not what you want; the deploy
// directory for this project is the deploy directory specified in the config
// that is:
assert(cubist.config.build_dir() != bad_cubist.config.build_dir());
Returns
T
Defined in
submodules/cubist-node-sdk/src/test.ts:198
Methods
build
▸ build(): Promise
<void
>
Build project, i.e., run cubist build
Returns
Promise
<void
>
Defined in
submodules/cubist-node-sdk/src/test.ts:287
emptyDeployDir
▸ emptyDeployDir(): Promise
<void
>
Clobber the project deploy directory.
Returns
Promise
<void
>
Defined in
submodules/cubist-node-sdk/src/test.ts:292
startService
▸ startService(service?
): Promise
<void
>
Start particular service (or all)---namely chains and
relayer---with
cubist start
.
Parameters
Name | Type | Description |
---|---|---|
service? | Service | Service to start. |
Returns
Promise
<void
>
Defined in
submodules/cubist-node-sdk/src/test.ts:247
stopService
▸ stopService(service?
): Promise
<void
>
Stop particular service (or all)---namely chains and
relayer---with
cubist start
.
Parameters
Name | Type | Description |
---|---|---|
service? | Service | Service to stop. |
Returns
Promise
<void
>
Defined in
submodules/cubist-node-sdk/src/test.ts:272
stopServiceOnExit
▸ stopServiceOnExit(service?
): void
Stop service(s) on process exit.
Parameters
Name | Type | Description |
---|---|---|
service? | Service | Service to stop. |
Returns
void