Skip to content

Latest commit

 

History

History
 
 

helia-jest

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Helia logo

Test Helia with Jest


Explore the docs · Report Bug · Request Feature/Example

About

Jest is a JavaScript testing framework that transpiles code on the fly to enable a fast-feedback testing cycle for the developer.

It is typically used to test browser code, whereby it injects an artificial DOM implementation into the global scope to enable running the actual tests on Node.js to take advantage of faster startup times at the cost of not always having 100% feature/behavior parity with the actual target platform.

In some circumstances this is helpful but it can also result in hard to debug errors, particularly around resolving modules and loading them.

Some developers also use Jest to test pure Node.js code which the benefit of familiarity but also has the same issues around transpilation.

 FAIL  test/index.spec.js
  ● Test suite failed to run

    Jest encountered an unexpected token

    Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

    Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

    By default "node_modules" folder is ignored by transformers.

Jest transpiles code when it is loaded via the module system. Historically Node.js made it easy to hook into this system via require but with ESM at the time of writing a flag to enable vm-modules needs to be passed to Node.js.

Putting it all together

It's possible to run the Jest test in this module with npm test:

% NODE_OPTIONS=--experimental-vm-modules jest

 PASS  test/index.spec.ts (6.055 s)
  Helia
    libp2p
      ✓ should have a peer id (519 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        6.134 s
Ran all test suites.

That's it! You just successfully ran a suite that can test your Helia application using Jest and ESM.

About The Project

Getting Started

Prerequisites

Make sure you have installed all of the following prerequisites on your development machine:

Installation and Running example

> npm install
> npm test

Documentation

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the IPFS Project
  2. Create your Feature Branch (git checkout -b feature/amazing-feature)
  3. Commit your Changes (git commit -a -m 'feat: add some amazing feature')
  4. Push to the Branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Want to hack on IPFS?

The IPFS implementation in JavaScript needs your help! There are a few things you can do right now to help out:

Read the Code of Conduct and JavaScript Contributing Guidelines.

  • Check out existing issues The issue list has many that are marked as 'help wanted' or 'difficulty:easy' which make great starting points for development, many of which can be tackled with no prior IPFS knowledge
  • Look at the Helia Roadmap This are the high priority items being worked on right now
  • Perform code reviews More eyes will help a. speed the project along b. ensure quality, and c. reduce possible future bugs
  • Add tests. There can never be enough tests