Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't run tests for the library #15

Closed
bvqbao opened this issue Jul 6, 2021 · 6 comments
Closed

Can't run tests for the library #15

bvqbao opened this issue Jul 6, 2021 · 6 comments

Comments

@bvqbao
Copy link
Contributor

bvqbao commented Jul 6, 2021

Hi,

I would like to modify the txforge library but I cannot run any test.
Here is the error:

npm run test

> txforge@0.2.5 test /home/baobui/txforge
> mocha "test/**/*.test.js" --require esm


/home/baobui/txforge/test/cast.test.js:1
TypeError: Cannot read property 'OpCode' of undefined
    at Object.<anonymous> (/home/baobui/txforge/test/cast.test.js:8:17)
    at Generator.next (<anonymous>)
    at Object.exports.requireOrImport (/home/baobui/txforge/node_modules/mocha/lib/esm-utils.js:42:12)
    at Object.exports.loadFilesAsync (/home/baobui/txforge/node_modules/mocha/lib/esm-utils.js:55:34)
    at Mocha.loadFilesAsync (/home/baobui/txforge/node_modules/mocha/lib/mocha.js:473:19)
    at singleRun (/home/baobui/txforge/node_modules/mocha/lib/cli/run-helpers.js:125:15)
    at exports.runMocha (/home/baobui/txforge/node_modules/mocha/lib/cli/run-helpers.js:190:10)
    at Object.exports.handler (/home/baobui/txforge/node_modules/mocha/lib/cli/run.js:362:11)
    at /home/baobui/txforge/node_modules/yargs/build/index.cjs:443:71
    at process.runNextTicks [as _tickCallback] (internal/process/task_queues.js:60:5)
    at internal/main/run_main_module.js:17:47
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! txforge@0.2.5 test: `mocha "test/**/*.test.js" --require esm`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the txforge@0.2.5 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/baobui/.npm/_logs/2021-07-06T18_57_31_462Z-debug.log

I tried to run the tests for txforge on both Ubuntu and Windows. Same error!

It seems that there are problems with the bsv library. Is there any special setup that I missed in order to run the tests?

Thanks,

@bvqbao bvqbao changed the title Can't run test for the library Can't run tests for the library Jul 6, 2021
@libitx
Copy link
Owner

libitx commented Jul 6, 2021

Odd, not come across that before. No setup required other than npm install (or yarn install) to ensure the deps are there.
I presume you've done that?

@bvqbao
Copy link
Contributor Author

bvqbao commented Jul 6, 2021

Yes. I have done npm install.

git clone ...
cd txforge
npm install
npm run test

Node version: 14.16.1
Npm version: 6.14.12

@libitx
Copy link
Owner

libitx commented Jul 6, 2021

Can you check in you package-lock file what version of bsv is installed?

In my local repo which works I have version 2.0.4. Try specifying that version in package.json.

tbh I'd be surprised if this is the problem, but it's worth trying to rule it out.

@bvqbao
Copy link
Contributor Author

bvqbao commented Jul 7, 2021

package-lock.json says 2.0.10.

The error here seems to be: import bsv from 'bsv'.
It doesn't work for some reasons, so bsv is undefined.

VSCode has a following notice: "Could not find a declaration file for module 'bsv'. bsv.cjs.js implicitly has an 'any' type".

Update: I have changed the import line to const bsv = require('bsv'), and the error disappears for cast.test.js (other files still have the error). txforge uses import syntax, so I don't think this is a good fix.

@bvqbao
Copy link
Contributor Author

bvqbao commented Jul 7, 2021

Ok. I changed import bsv from 'bsv' to import * as bsv from 'bsv' and it works!
Not sure if you are ok with this change? I will submit a pull request if necessary.

Anyway, the main thing is I want to submit a pull request to fix a bug in p2ms.js.
So if you are ok with the import changes, I will make two pull requests.

@libitx
Copy link
Owner

libitx commented Jul 7, 2021

I guess the bsv maintainers have made a change that has removed the global export. This can only be recent - maybe specifically in 2.0.10.

Please dont do a PR for the bsv import as I want to ask them if it is intentional. They'll probably break all my libraries with this change so I would rather they revert the change.

However, happy to see the PR for any p2ms fixes 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants