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] Jest testing: Crypto module not found #100

Closed
Mskalba opened this issue Jul 10, 2021 · 2 comments
Closed

[ISSUE] Jest testing: Crypto module not found #100

Mskalba opened this issue Jul 10, 2021 · 2 comments

Comments

@Mskalba
Copy link

Mskalba commented Jul 10, 2021

Reproduction steps:

  1. Boilerplate new CRA project and check basic rendering test

npx create-react-app dep-check --template typescript
cd dep-check
npm i
npm run test

All works fine.

  1. Add terra.js dependency

npm i --save @terra-money/terra.js

  1. Modify App.tsx with first example from terra.js Readme
`import React, {useState} from 'react';
import './App.css';
import { LCDClient, Coin } from '@terra-money/terra.js';

const terra = new LCDClient({
  URL: 'https://tequila-lcd.terra.dev',
  chainID: 'tequila-0004',
});
const App = () => {
  const [coins, setCoins] = useState('');
  const offerCoin = new Coin('uusd', '1000000');
  terra.market.swapRate(offerCoin, 'ukrw').then(c => {
    setCoins(`${offerCoin.toString()} can be swapped for ${c.toString()}`);
  });
  return (
      <div>
        {coins}
      </div>
  );
};

export default App;`
  1. Run again basic test:

npm run test

It fails:

 FAIL  src/App.test.tsx
  ● Test suite failed to run

    Crypto module not found
    
      at node_modules/jscrypto/SHA256.js:1:5962
      at Object.9054 (node_modules/jscrypto/SHA256.js:1:6223)
      at r (node_modules/jscrypto/SHA256.js:1:6324)
      at Object.3354 (node_modules/jscrypto/SHA256.js:1:491)
      at r (node_modules/jscrypto/SHA256.js:1:6324)
      at Object.7211 (node_modules/jscrypto/SHA256.js:1:2275)
      at r (node_modules/jscrypto/SHA256.js:1:6324)
      at Object.1868 (node_modules/jscrypto/SHA256.js:1:3145)
      at r (node_modules/jscrypto/SHA256.js:1:6324)
      at node_modules/jscrypto/SHA256.js:1:6935
      at node_modules/jscrypto/SHA256.js:1:8672
      at node_modules/jscrypto/SHA256.js:1:8677
      at node_modules/jscrypto/SHA256.js:1:173
      at Object.<anonymous> (node_modules/jscrypto/SHA256.js:1:366)
      at Object.<anonymous> (node_modules/@terra-money/terra.js/src/core/oracle/msgs/MsgExchangeRateVote.ts:1:1)
      at Object.<anonymous> (node_modules/@terra-money/terra.js/src/core/oracle/msgs/index.ts:9:1)
      at Object.<anonymous> (node_modules/@terra-money/terra.js/src/core/Msg.ts:17:1)
      at Object.<anonymous> (node_modules/@terra-money/terra.js/src/core/index.ts:5:1)
      at Object.<anonymous> (node_modules/@terra-money/terra.js/src/index.ts:1:1)
      at Object.<anonymous> (src/App.tsx:4:1)
      at Object.<anonymous> (src/App.test.tsx:3:1)

Is there anyway to disable that module on test level or something? I know that you introduced jscrypto instead of crypto-js, but it seems like this package is a little bit problematic as well.

Will appreciate any possible solutions.

@Mskalba Mskalba changed the title Jest testing: Crypto module not found [ISSUE] Jest testing: Crypto module not found Jul 10, 2021
@iamssen
Copy link
Contributor

iamssen commented Jul 10, 2021

https://github.com/Anchor-Protocol/anchor-web-app/blob/feature/beth/app/src/setupTests.ts

This is a temporary solution.

@Mskalba
Copy link
Author

Mskalba commented Jul 10, 2021

Ok, thanks. It can be closed I think for now.

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