Skip to content

Commit 9a99fa3

Browse files
committed
solana: define __dirname in ESM anchor tests
multi_instance.test.ts and upgrade_authority_decoupling.test.ts used the CommonJS __dirname global, which is undefined under jest's ESM mode, so both suites failed to load with ReferenceError. This was masked while the SDK build (Setup SDK step) was failing earlier in the job. Derive it from import.meta.url, mirroring anchor.test.ts.
1 parent 211d667 commit 9a99fa3

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

solana/tests/anchor/multi_instance.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ import {
3030
} from "../../ts/sdk/index.js";
3131
import { NTT } from "../../ts/index.js";
3232
import { TestHelper, TestMint, assert, signSendWait } from "./utils/helpers.js";
33+
import { fileURLToPath } from "url";
3334

3435
registerDefinitionsNtt();
3536
registerSolanaNtt();
3637

38+
// Native ESM (jest useESM) has no __dirname; derive it from import.meta.url.
39+
const __dirname = fileURLToPath(new URL(".", import.meta.url));
3740
const SOLANA_ROOT_DIR = `${__dirname}/../../`;
3841
const VERSION: IdlVersion = "4.0.0";
3942
const TOKEN_PROGRAM = spl.TOKEN_2022_PROGRAM_ID;

solana/tests/anchor/upgrade_authority_decoupling.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@ import {
2626
BPF_LOADER_UPGRADEABLE_PROGRAM_ID,
2727
programDataAddress,
2828
} from "../../ts/lib/utils.js";
29+
import { fileURLToPath } from "url";
2930

3031
registerDefinitionsNtt();
3132
registerSolanaNtt();
3233

34+
// Native ESM (jest useESM) has no __dirname; derive it from import.meta.url.
35+
const __dirname = fileURLToPath(new URL(".", import.meta.url));
3336
const SOLANA_ROOT_DIR = `${__dirname}/../../`;
3437
const VERSION: IdlVersion = "4.0.0";
3538
const TOKEN_PROGRAM = spl.TOKEN_2022_PROGRAM_ID;

0 commit comments

Comments
 (0)