Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't start test in Jest #2

Open
ilbertt opened this issue Jul 24, 2023 · 2 comments
Open

Can't start test in Jest #2

ilbertt opened this issue Jul 24, 2023 · 2 comments

Comments

@ilbertt
Copy link

ilbertt commented Jul 24, 2023

I'm trying to use LightIC with Jest.

I wrote this simple test:

import { Actor } from "@dfinity/agent";
import { Principal } from "@dfinity/principal";
import { TestContext } from "lightic";

const context = new TestContext();
let actor: Actor;

describe("Canister", () => {
  beforeAll(async () => {
    // @ts-ignore
    const canister = await context.deploy('./.dfx/local/canisters/backend/backend.wasm');
    console.log(canister)

    const caller = Principal.anonymous();

    // @ts-ignore
    actor = Actor.createActor(canister.getIdlBuilder(), {
      // @ts-ignore
      agent: context.getAgent(caller),
      canisterId: canister.get_id()
    })
  });

  it("is true", () => {
    console.log(actor);
    expect(true).toBe(true);
  });
});

Run it simply with:

npx jest

But I got this error:

FAIL  tests/integration/canister.test.ts
  Canister
    ✕ is true (1 ms)

  ● Canister › is true

    TypeError: WebAssembly.Module.customSections(): Argument 0 must be a WebAssembly.Module

      at WasmCanister.get_candid (node_modules/lightic/src/wasm_canister.ts:270:42)
      at async WasmCanister.install_module_candid (node_modules/lightic/src/wasm_canister.ts:116:20)
      at async ReplicaContext.install_canister (node_modules/lightic/src/replica_context.ts:198:5)
      at async TestContext.deploy (node_modules/lightic/src/test_context.ts:49:20)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        2.083 s

The ./.dfx/local/canisters/backend/backend.wasm file exists.

(Note that I also had to use @ts-ignore, which I think is due to different versions of the @dfinity/* packages)

Context:

  • node: v16.14.1
  • lightic: 0.3.1
  • jest: 29.6.1
  • @dfinity/*: 0.15.1
  • dfx: 0.14.1
@ilbertt ilbertt changed the title Can't run Jest test Can't start test in Jest Jul 24, 2023
@stopak
Copy link
Contributor

stopak commented Jul 25, 2023

It looks like an issue with wasm file. I will check and try to fix this

@ilbertt
Copy link
Author

ilbertt commented Jul 25, 2023

I forgot to mention the dfx version:

  • dfx: 0.14.1

which can probably help.

I've also added to my first issue comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants