1
- import { setDefaultResultOrder } from 'dns' ; setDefaultResultOrder ( 'ipv4first' ) ; // temp fix for node > v17
2
-
3
1
import { Worker , NearAccount } from 'near-workspaces' ;
4
2
import anyTest , { TestFn } from 'ava' ;
5
- import * as path from 'path' ;
3
+ import { setDefaultResultOrder } from 'dns' ; setDefaultResultOrder ( 'ipv4first' ) ; // temp fix for node >v17
6
4
7
5
// 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 > } > ;
12
7
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 ( ) ;
16
11
17
12
// Deploy contract
18
13
const root = worker . rootAccount ;
@@ -22,24 +17,24 @@ test.before(async (t) => {
22
17
await contract . deploy ( process . argv [ 2 ] ) ;
23
18
24
19
// Save state for test runs, it is unique for each test
25
- accounts = { root, contract } ;
20
+ t . context . accounts = { root, contract } ;
26
21
} ) ;
27
22
28
- test . after . always ( async ( t ) => {
23
+ test . afterEach . always ( async ( t ) => {
29
24
// Stop Sandbox server
30
- await worker . tearDown ( ) . catch ( ( error ) => {
25
+ await t . context . worker . tearDown ( ) . catch ( ( error ) => {
31
26
console . log ( 'Failed to stop the Sandbox:' , error ) ;
32
27
} ) ;
33
28
} ) ;
34
29
35
30
test ( 'by default the user has no points' , async ( t ) => {
36
- const { root, contract } = accounts ;
31
+ const { root, contract } = t . context . accounts ;
37
32
const points : number = await contract . view ( 'points_of' , { player : root . accountId } ) ;
38
33
t . is ( points , 0 ) ;
39
34
} ) ;
40
35
41
36
test ( 'the points are correctly computed' , async ( t ) => {
42
- const { root, contract } = accounts ;
37
+ const { root, contract } = t . context . accounts ;
43
38
44
39
let counter : { [ key :string ] :number } = { 'heads' : 0 , 'tails' : 0 }
45
40
let expected_points = 0 ;
0 commit comments