@magic/test
Getting Started
Be in a nodejs project.
Install
npm i --save-dev --save-exact @magic/testCreate a Test File
Create a test file in the test/ directory. The filename is used in test output, and the path should mirror your source structure:
// test/yourFileToTest.jsexport default [{ fn: () => true, expect: true, info: 'true is true' },{ fn: () => 1 + 1, expect: 2, info: 'basic math' },]
Note: the test function is called automatically. expect: true is optional.
Add npm Scripts
Add test scripts to your package.json:
{"scripts": {"test": "t -p","coverage": "t"}}
t -p runs tests in production mode (no coverage, faster). t runs with coverage.
Run Tests
npm testExample Output
### Testing package: @magic/testRan 2 tests. Passed 2/2 100%
Faster output from a bigger project:
### Testing package: @artificialmuseum/engineRan 90307 tests in 274.5ms. Passed 90307/90307 100%
Next Steps
- Writing Tests - hooks, promises, types, multiple tests
- Utility Functions - deep, fs, curry, log, vals, env, http, mock, has
- Svelte Testing - mount components, interact, assert
- CLI & Usage - flags, sharding, performance tips
- Test Isolation - prevent state leakage between tests
- Error Codes - programmatic error handling