near / near-workspaces-js

Write tests once, run them both on NEAR TestNet and a controlled NEAR Sandbox local environment
https://near.github.io/near-workspaces-js/
GNU General Public License v3.0
42 stars 22 forks source link

fix: make instance fns passable #15

Closed chadoh closed 3 years ago

chadoh commented 3 years ago

This now works:

async function testSomething(run) {
  await run(async ({ … }) => {
    // test code goes here
  })
}

const runner = await Runner.create(async ({ runtime }) => { … })

await testSomething(runner.run)

Previously, the run function in the context of testSomething would not have this defined, and confusing errors would be thrown like:

    const runtime = await runtime_1.Runtime.create(this.config);
                                                        ^

TypeError: Cannot read property 'config' of undefined
chadoh commented 3 years ago

We can come back to this if someone complains about this broken edge case. I don't want to complicate our main test file, which is currently used as much for teaching good practices as it is for actually testing. This way of testing is not a good practice!

So until someone complains, our recommendation is to pass the whole runner around, rather than just runner.run.