You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
This should run with no issue when executing truffle test.
Now imagine you need to import a function from somewhere else, like OpenZeppelin's assertRevert testing utility function, one would add these to test/Foo.test.js after having installed OpenZeppelin module (npm install --save openzeppelin-solidity):
importassertRevertfrom'openzeppelin-solidity/test/helpers/assertRevert'// CommonJS alternative, which would fail the same wayconstassertRevert=require('openzeppelin-solidity/test/helpers/assertRevert')// rest of your tests...
Now running truffle test should fail because of unexpected import token (or export (which is in OZ's assertRevert.js file) if you used require). Fine, let us fix that by adding Babel:
Now let us add these at the top of truffle.js (or truffle-config.js in case you are using that one):
require('babel-register')({ignore: /node_modules\/(?!openzeppelin-solidity\/test\/helpers)/})require('babel-polyfill')// rest of truffle config...
And configure Babel through a new .babelrc file:
{
"presets": ["env"]
}
Here we are, we can run truffle test again.
Expected Behavior
Imports should work and test should pass like before.
Actual Results
Imports are indeed fixed and now work properly. However, test fails, telling that this is undefined (within beforeEach section), which is quite of an issue.
I also noticed that this problem only happens for asynchronous tests (like I have written above).
@cgewecke this indeed seems to solve the problem, too bad having to add code-style/linting exceptions for such "should not even be a thing" issues though. Thank you!
Issue
Asynchronous tests break when adding Babel (
babel-register
andbabel-polyfill
) to project (this
is setundefined
in test sections).Steps to Reproduce
A minimal example is attached here: example.tar.gz or example.zip
Init a new project with
truffle init
, create filetest/Foo.test.js
, with this content:This should run with no issue when executing
truffle test
.Now imagine you need to import a function from somewhere else, like OpenZeppelin's
assertRevert
testing utility function, one would add these totest/Foo.test.js
after having installed OpenZeppelin module (npm install --save openzeppelin-solidity
):Now running
truffle test
should fail because of unexpectedimport
token (orexport
(which is in OZ'sassertRevert.js
file) if you usedrequire
). Fine, let us fix that by adding Babel:Now let us add these at the top of
truffle.js
(ortruffle-config.js
in case you are using that one):And configure Babel through a new
.babelrc
file:Here we are, we can run
truffle test
again.Expected Behavior
Imports should work and test should pass like before.
Actual Results
Imports are indeed fixed and now work properly. However, test fails, telling that
this
isundefined
(withinbeforeEach
section), which is quite of an issue.I also noticed that this problem only happens for asynchronous tests (like I have written above).
Environment
1.1.0-1
)truffle version
):Truffle v4.1.11 (core: 4.1.11)
node --version
):v10.1.0
npm --version
):6.0.1
The text was updated successfully, but these errors were encountered: