Skip to content

Commit c2c20dc

Browse files
authored
Merge pull request #18 from garikbesson/fix-js-tests
Fix JS tests
2 parents 121a724 + ab560f4 commit c2c20dc

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

contract-ts/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
"test": "$npm_execpath build && ava -- ./build/contract.wasm"
99
},
1010
"dependencies": {
11-
"near-cli": "^4.0.8",
11+
"near-cli": "^4.0.10",
1212
"near-sdk-js": "1.0.0"
1313
},
1414
"devDependencies": {
1515
"@ava/typescript": "^4.1.0",
1616
"ava": "^6.1.2",
1717
"near-workspaces": "^3.5.0",
18-
"ts-morph": "^21.0.1",
18+
"ts-morph": "^22.0.0",
1919
"ts-node": "^10.9.2",
2020
"tsimp": "^2.0.11",
21-
"typescript": "^5.3.3"
21+
"typescript": "^5.4.2"
2222
}
23-
}
23+
}

contract-ts/sandbox-ts/main.ava.ts

+10-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
import { setDefaultResultOrder } from 'dns'; setDefaultResultOrder('ipv4first'); // temp fix for node > v17
2-
31
import { Worker, NearAccount } from 'near-workspaces';
42
import anyTest, { TestFn } from 'ava';
5-
import * as path from 'path';
3+
import { setDefaultResultOrder } from 'dns'; setDefaultResultOrder('ipv4first'); // temp fix for node >v17
64

75
// Global context
8-
let worker: Worker;
9-
let accounts: Record<string, NearAccount>;
10-
11-
const test = anyTest as TestFn<{}>;
6+
const test = anyTest as TestFn<{ worker: Worker, accounts: Record<string, NearAccount> }>;
127

13-
test.before(async (t) => {
14-
// Init the worker and start a Sandbox server
15-
worker = await Worker.init();
8+
test.beforeEach(async (t) => {
9+
// Create sandbox, accounts, deploy contracts, etc.
10+
const worker = t.context.worker = await Worker.init();
1611

1712
// Deploy contract
1813
const root = worker.rootAccount;
@@ -22,24 +17,24 @@ test.before(async (t) => {
2217
await contract.deploy(process.argv[2]);
2318

2419
// Save state for test runs, it is unique for each test
25-
accounts = { root, contract };
20+
t.context.accounts = { root, contract };
2621
});
2722

28-
test.after.always(async (t) => {
23+
test.afterEach.always(async (t) => {
2924
// Stop Sandbox server
30-
await worker.tearDown().catch((error) => {
25+
await t.context.worker.tearDown().catch((error) => {
3126
console.log('Failed to stop the Sandbox:', error);
3227
});
3328
});
3429

3530
test('by default the user has no points', async (t) => {
36-
const { root, contract } = accounts;
31+
const { root, contract } = t.context.accounts;
3732
const points: number = await contract.view('points_of', { player: root.accountId });
3833
t.is(points, 0);
3934
});
4035

4136
test('the points are correctly computed', async (t) => {
42-
const { root, contract } = accounts;
37+
const { root, contract } = t.context.accounts;
4338

4439
let counter: {[key:string]:number} = { 'heads': 0, 'tails': 0 }
4540
let expected_points = 0;

0 commit comments

Comments
 (0)