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 21 forks source link

Not create promise in workspace constructor #112

Closed ailisp closed 2 years ago

ailisp commented 2 years ago

It's an anti pattern because we'll lose the handle to the promise. And if try to await or catch the promise, it's a race condition - promise may already resolved when you try to await for it. In practice, this sometimes causes an "Unhandled Promise" error throwed several seconds after user calls Workspace.init, which is very confusing.

The better way is to make the factory method Workspace.init returns a promise. And in test file's beforeAll block, await Workspace.init.