🧪 Announcing PicJS: TypeScript/JavaScript support for PocketIC!

I’m happy to announce PicJS, a canister testing library with TypeScript/JavaScript support for PocketIC!

PicJS allows you to write integration tests for your canisters using your favorite JavaScript test runners and runtimes. If you’d like to try it out, you can:

PocketIC is a canister testing platform that supports deterministic, programmatic canister testing. If you want to learn more about it, you can check out the previous posts from the Testing & Verification team that have put together this wonderful tool:

Writing tests with PicJS is as easy as this:

import { resolve } from 'node:path';
import { Principal } from '@dfinity/principal';
import { PocketIc } from '@hadronous/pic';
import { Actor, idlFactory, _SERVICE } from '../declarations/counter';

const wasmPath = resolve('..', '..', 'counter.wasm');

describe('Counter', () => {
  let pic: PocketIc;
  let actor: Actor<_SERVICE>;

  beforeEach(async () => {
    pic = await PocketIc.create();
    const fixture = await pic.setupCanister<_SERVICE>(
      idlFactory,
      WASM_PATH,
    );
    actor = fixture.actor;
  });

  afterEach(async () => {
    await pic.tearDown();
  });

  it('should increment the counter', async () => {
    const initialCount = await actor.get();

    await actor.inc();
    const countAfterFirstInc = await actor.get();

    await actor.inc();
    const finalCount = await actor.get();

    expect(initialCount).toEqual(0n);
    expect(countAfterFirstInc).toEqual(1n);
    expect(finalCount).toEqual(2n);
  });
});

I’m happy to hear any feedback or answer any questions that you might have.

Disclaimer: I work for DFINITY, but this is not a DFINITY project. I’m posting in my capacity as a part-time community member.

22 Likes

great work! i think this is worth adding to awesome icp (maybe together with pocket ic)

4 Likes

Thank you!

I agree, expect a PR tomorrow :wink:

3 Likes

Version 0.3.0 of PicJS has been released.

The main changes include:

  • Support for PocketIC server version 3.0.0
    • Support for multiple subnets
    • Support for cross-subnet calls
  • Added updateCanisterSettings to allow updating canister settings after creation (controllers etc…)
  • tick now accepts an optional number to tick multiple times in a single call
  • many public methods accept a single object instead of a list of parameters (ex: installCode)
  • Added a multicanister Motoko example with composite query calls and cross subnet update calls

I look forward to seeing how developers continue to improve the quality of their testing infrastructure using PocketIC :rocket:

8 Likes