Gathering detailed insights and metrics for @womorg/ipsam-sint-eaque
Gathering detailed insights and metrics for @womorg/ipsam-sint-eaque
Gathering detailed insights and metrics for @womorg/ipsam-sint-eaque
Gathering detailed insights and metrics for @womorg/ipsam-sint-eaque
npm install @womorg/ipsam-sint-eaque
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
145
Last Day
3
Last Week
37
Last Month
122
Last Year
145
2,120 Commits
1 Watching
1 Branches
1 Contributors
Latest Version
3.10.131
Package Id
@womorg/ipsam-sint-eaque@3.10.131
Unpacked Size
252.12 kB
Size
130.70 kB
File Count
686
NPM Version
10.8.2
Node Version
20.17.0
Publised On
22 Sept 2024
Cumulative downloads
Total Downloads
Last day
-66.7%
3
Compared to previous day
Last week
-40.3%
37
Compared to previous week
Last month
430.4%
122
Compared to previous month
Last year
0%
145
Compared to previous year
36
Dependency-less Test Runner for Node.js
@womorg/ipsam-sint-eaque is a light-weight and a quick alternative to ava, with a similar API.
npm i @womorg/ipsam-sint-eaque -D
your.tests.js:
1const test = require('@womorg/ipsam-sint-eaque') 2const myLib = require('./my-lib') 3 4test('Test our library', t => { 5 t.is(myLib.add(1, 1), 2); 6 t.not(myLib.add(2, 2), 3); 7 t.true(myLib.isPrime(3)); 8 t.false(myLib.isOdd(2)); 9}) 10 11test('Test something async', async t => { 12 let result = await myLib.asyncAdd(1, 1); 13 t.is(result, 2); 14}) 15
node your.tests.js
To run multiple tests and integrate CI testing with your package, you need to change your package.json's test
in the scripts
section to "@womorg/ipsam-sint-eaque"
:
1"scripts": { 2 "test": "@womorg/ipsam-sint-eaque" 3},
Then, to run all your tests: npm run test
All files anywhere in your package's directory (and subdirectories, excluding node_modules
and directories that start with a single _
) that match the following patterns will be run:
test.js
tests.js
*.test.js
*.tests.js
*/test-*.js
*.spec.js
**/test/*.js
**/tests/*.js
**/__tests__/*.js
If your test files are named differently, for instance *.unit-test.js, you can write your test script like this:
1"scripts": { 2 "test": "@womorg/ipsam-sint-eaque *.unit-test.js" 3},
To automatically run tests whenever you modify your files, @womorg/ipsam-sint-eaque has a watch mode. If you desire this functionality, add a new script to your package.json:
1"scripts": { 2 "test": "@womorg/ipsam-sint-eaque", 3 "test:watch": "@womorg/ipsam-sint-eaque --watch" 4},
To start the watch script, run npm run test:watch
.
Like with the test
script, you can watch files other than *.test.js
:
1"test:watch": "@womorg/ipsam-sint-eaque *.foo.js --watch"
@womorg/ipsam-sint-eaque can be easily integrated with coverage tools such as nyc and c8.
To enable coverage with c8, add the following to your package.json:
1"scripts": { 2 // Other scripts 3 "test:coverage": "c8 npm test" 4},
Or to run tests with nyc:
1"scripts": { 2 // Other scripts 3 "test:coverage": "nyc @womorg/ipsam-sint-eaque" 4},
Running test:coverage
will produce something like this:
--------------|---------|----------|---------|---------|-----------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
--------------|---------|----------|---------|---------|-----------------------
All files | 99.2 | 96.63 | 98.57 | 99.2 |
my-lib.js | 97.74 | 95.18 | 98.55 | 97.74 | 20-21,190-191,231-232
test.js | 100 | 100 | 100 | 100 |
--------------|---------|----------|---------|---------|-----------------------
To add special reporters such as LCOV and HTML, check the README pages of the code coverage package.
Note: c8 is recommended, because it uses Node's built-in V8 coverage tools and it is many times faster than nyc.
The callback parameter for test()
wraps many assertion methods (in this case t
):
1test('Test name', t => { 2 // Your assertions 3})
These assertion methods are currently supported:
t.is(actual, expected, message?)
Asserts that actual
is equal to expected
.
t.not(actual, notEpected, message?)
Asserts that actual
is not equal to notEpected
.
t.near(actual, expected, delta, message?)
Asserts that actual
is equal to expected
within the precision of delta
.
t.notNear(actual, expected, delta, message?)
Asserts that actual
is not equal to expected
within the precision of delta
.
t.deepEqual(actual, expected, message?)
Asserts that actual
is deeply equal to expected
. test.ignore
can be used to skip certain properties, i.e.:
1let actual = { a: 3, b: 'ok', c: 7 }
2t.deepEqual(actual, {
3 a: 3,
4 b: 'ok',
5 c: test.ignore
6})
Differences are reported with a minus -
for actual values and plus +
for expected values.
You may also use test.ignoreExtra()
to only assert the given properties in the expected object:
1let actual = { a: 3, b: 'ok', c: 7 }
2t.deepEqual(actual, test.ignoreExtra({
3 b: 'ok',
4}))
t.notDeepEqual(actual, expected, message?)
Asserts that actual
is not deeply equal to expected
.
t.true(value, message?)
Asserts that value
is true.
t.false(value, message?)
Asserts that value
is false.
t.throws(fn, opts?, message?)
Asserts that fn
throws an exception.
1function uhOh() { 2 throw new Error("Uh oh."); 3} 4 5t.throws(_ => { 6 uhOh(); 7})
You can also check for specific types of exception. If the exception does not match it, the test will fail:
1t.throws(_ => { 2 uhOh(); 3}, { instanceOf: TypeError })
t.throwsAsync(fn, opts?, message?)
The asynchronous version of t.throws(). Note the addition of async/await.
1test('Async test', async t => { 2 await t.throwsAsync(async _ => { 3 await uhOhAsync(); 4 }) 5})
You can also check for specific types of exception. If the exception does not match it, the test will fail:
1await t.throws(async _ => { 2 await uhOhAsync(); 3}, { instanceOf: TypeError })
t.notThrows(fn, message?)
Asserts that fn
does not throw an exception.
t.notThrowsAsync(fn, message?)
Asserts that async function or Promise fn
does not throw an exception.
t.log(message, ...arguments?)
Similar to console.log
, but helps you easily find for which test method you've logged information.
t.disableLogging()
Suppresses any calls to console.log
, console.warn
, console.error
, etc. for the current testcase. Note that logging is enabled again automatically after the testcase has completed.
(Available in 1.6.8+) @womorg/ipsam-sint-eaque supports mocking with the t.mock()
method. This method lets you mock a method on an object or library. Mocked methods are restored automatically after each test.
1const test = require('@womorg/ipsam-sint-eaque') 2const Http = require('SomeHttpLibrary') 3 4test('Mocking', async t => { 5 let mockedGet = t.mock(Http, 'get', async _ => { 6 return { statusCode: 200, body: 'Hello World!' } 7 }) 8 9 let result = await Http.get('https://example.com') 10 t.is(result.statusCode, 200) 11 t.is(result.body, 'Hello World!') 12 13 t.is(mockedGet.calls.length, 1) 14})
In the example above, we mock the get
method on the Http
object. The mocked method returns a promise that resolves to a response object. We then assert that the response object has the expected properties. Finally, we assert that the mocked method was called once.
By mocking the get
method here, any other code that imports SomeHttpLibrary
and calls Http.get
will also use the mocked method. This is useful for testing code that uses external libraries.
t.mock()
returns a Mock
object with the following properties:
Mock.restore()
Restores the mocked method back to its original implementation. If you don't call this method, the mocked method will be restored automatically after each test.
Mock.calls
An array of all calls to the mocked method. Each call is an array of arguments passed to the mocked method.
(Available in 1.6.0+) The following hooks are available:
1const test = require('@womorg/ipsam-sint-eaque')
2
3test.before(t => {
4 // Your set-up and assertions
5 // This is only ran once per test file
6})
7
8test.after(t => {
9 // Your tear-down and assertions
10 // This is only ran once per test file
11})
12
13test.beforeEach(t => {
14 // Your set-up and assertions
15 // This is ran before each test
16})
17
18test.afterEach(t => {
19 // Your tear-down and assertions
20 // This is ran after each test
21})
(Available in 1.6.7+) You can skip all tests in a file by calling test.skipFile()
:
1const test = require('@womorg/ipsam-sint-eaque')
2
3test.skipFile('Reason for skipping this file here');
(Available in 1.3.7+) To write @womorg/ipsam-sint-eaque test files TypeScript, you will need to enable source maps in your tsconfig.json
.
1"compilerOptions": { 2 // Can be any other path, but .js files will need to be emitted 3 "outDir": "./dist", 4 "sourceMap": true, 5 "module": "commonjs", 6 // other compiler options 7}
For an optimal development flow, run the following tasks (add them to package.json
scripts first):
tsc --watch
@womorg/ipsam-sint-eaque --watch
Now let's create a file named your.tests.ts:
1import test = require('@womorg/ipsam-sint-eaque') 2import myLib from './my-lib' 3 4test('Should fail', t => { 5 t.is(myLib.add(1, 1), 3) 6})
This will fail with something like the following output:
FAILED: "Should fail"
D:\DEV\YourProject\tests\your.tests.ts:6:10 [SourceMap]
Note the source-mapped location. This will allow you to Ctrl+Click on the location in your IDE to easily jump to the original test file.
Source maps are a way to map the original source code to the generated code. This is useful for debugging and development. Languages or tools that compile to JavaScript, like TypeScript, CoffeeScript, ClojureScript, BabelJS, etc., can generate source maps. We've only covered TypeScript here, but if you're using another language that has a compiler that generates source maps, it should work with @womorg/ipsam-sint-eaque.
(Available in 1.6.1+) @womorg/ipsam-sint-eaque supports reporting test results to a file. The current supported reporters are junit
and tap
. To enable it, add the following to your package.json
:
1{ 2 "@womorg/ipsam-sint-eaque": { 3 "reporter": "junit" 4 } 5}
The junit
reporter will generate a JUnit XML file for each test file in the .@womorg/ipsam-sint-eaque-output/reports
folder. You can then use this file in your CI/CD pipeline to generate reports.
See Config for more information.
The tap
reporter will output the test results in the TAP version 13 format to the console / stdout. Currently, this report is simplified and does not include stack traces.
@womorg/ipsam-sint-eaque can be run from the terminal like npx @womorg/ipsam-sint-eaque tests/test-*.js
with the following supported parameters:
--watch
Runs @womorg/ipsam-sint-eaque in watch mode. See watch mode for more information.
--verbose
Adds verbose logging.
Example: @womorg/ipsam-sint-eaque --verbose
--no-concurrency
Disables concurrency. This will run all tests sequentially.
Example: @womorg/ipsam-sint-eaque --no-concurrency
@womorg/ipsam-sint-eaque will try to check the package.json
from where it was ran from for a section named "@womorg/ipsam-sint-eaque"
.
1{ 2 "@womorg/ipsam-sint-eaque": { 3 "verbose": true, 4 "concurrency": true, 5 "reporter": "", 6 "reporterOptions": { 7 "outputDir": "test-results/" 8 } 9 } 10}
Supported config:
verbose
- If true, enables verbose output. (default = false)
AQA_VERBOSE
environment variable.concurrency
- If false, disables concurrency. (default = true)
AQA_CONCURRENCY
environment variable.reporter
- The reporter to use, can be junit
or tap
. Default = "" (no reporter)
AQA_REPORTER
environment variable.reporterOptions
- Options for the reporter.
outputDir
- The output directory for the reporter. Default = ".@womorg/ipsam-sint-eaque-output/reports"
AQA_REPORTER_OUTPUT_DIR
environment variable.No vulnerabilities found.
No security vulnerabilities found.