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

Issue when running eciesjs from Jest. #494

Closed
goncer opened this issue Nov 3, 2021 · 2 comments
Closed

Issue when running eciesjs from Jest. #494

goncer opened this issue Nov 3, 2021 · 2 comments

Comments

@goncer
Copy link

goncer commented Nov 3, 2021

I am trying to incorporate this lib into my Jest tests, but getting the following error:
Expected private key to be an Uint8Array

Error trace:

 ./node_modules/jest/bin/jest.js ts-node/register test/sequential/test.ts 
 FAIL  test/sequential/test.ts
  test string <-> buffer utils 
    ✕ should generate valid secret (4 ms)

  ● test string <-> buffer utils  › should generate valid secret

    Expected private key to be an Uint8Array

      3 | describe("test string <-> buffer utils ", () => {
      4 |   it("should generate valid secret", () => {
    > 5 |     const key = getValidSecret();
        |                 ^
      6 |   });
      7 | });
      8 |

      at assert (node_modules/secp256k1/lib/index.js:18:20)
      at isUint8Array (node_modules/secp256k1/lib/index.js:22:3)
      at Object.privateKeyVerify (node_modules/secp256k1/lib/index.js:66:7)
      at getValidSecret (node_modules/eciesjs/dist/utils.js:25:35)
      at Object.<anonymous> (test/sequential/test.ts:5:17)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        1.764 s, estimated 2 s

I created this small test that fails,

import { getValidSecret } from "eciesjs/dist/utils";

describe("test string <-> buffer utils ", () => {
  it("should generate valid secret", () => {
    const key = getValidSecret();
  });
});

you can run it with:
./node_modules/jest/bin/jest.js test.ts

Jest version:
"jest": "^26.6.3",

when running with mocha all good :)

./node_modules/mocha/bin/mocha -r ts-node/register test/sequential/test.ts 
  test string <-> buffer utils 
    ✔ should generate valid secret
  1 passing (9ms)

hopefully, you can help me a bit :)
Thanks!

UPDATE:
I think this is somehow reported in a lib dependency project. I'm still wondering why it works in mocha but not in JEST 🙃
cryptocoinjs/secp256k1-node#175

@goncer
Copy link
Author

goncer commented Nov 4, 2021

hey @kigawas ,
I found a way to solve it. The issue is on Jest not exporting some globals.
jestjs/jest#4422
The issue is kindly solved by exporting some globals,
https://github.com/jolocom/jolo-did-method/blob/1302227410d7aa91262e3da9ecafaaa89779b68e/jest.config.js

@goncer goncer closed this as completed Nov 4, 2021
@kigawas
Copy link
Member

kigawas commented Nov 16, 2021

hey @kigawas , I found a way to solve it. The issue is on Jest not exporting some globals. facebook/jest#4422 The issue is kindly solved by exporting some globals, https://github.com/jolocom/jolo-did-method/blob/1302227410d7aa91262e3da9ecafaaa89779b68e/jest.config.js

Thank you for sharing!

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