Explore the docs
·
Report Bug
·
Request Feature/Example
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.
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.
- Read the docs
- Look into other examples to learn how to spawn a Helia node in Node.js and in the Browser
- Visit https://dweb-primer.ipfs.io to learn about IPFS and the concepts that underpin it
- Head over to https://proto.school to take interactive tutorials that cover core IPFS APIs
- Check out https://docs.ipfs.io for tips, how-tos and more
- See https://blog.ipfs.io for news and more
- Need help? Please ask 'How do I?' questions on https://discuss.ipfs.io
Make sure you have installed all of the following prerequisites on your development machine:
- Git - Download & Install Git. OSX and Linux machines typically have this already installed.
- Node.js - Download & Install Node.js and the npm package manager.
> npm install
> npm test
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.
- Fork the IPFS Project
- Create your Feature Branch (
git checkout -b feature/amazing-feature
) - Commit your Changes (
git commit -a -m 'feat: add some amazing feature'
) - Push to the Branch (
git push origin feature/amazing-feature
) - Open a Pull Request
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