Skip to content

[CSR-2484] chore: adding node js example #3

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

Merged
merged 1 commit into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8,624 changes: 6,161 additions & 2,463 deletions package-lock.json

Large diffs are not rendered by default.

31 changes: 30 additions & 1 deletion packages/nodejs-test-runner/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
# NodeJS Test Runner + Currents

👷🏾‍♀️ Work in progress
## How to

Follow the steps to reproduce this example:

- Create an account at https://app.currents.dev and obtain Project Id and Record Key
- Get a Record key and Project ID from Currents dashboard
- Run the test

```sh
npm run test
```

- Convert JUnit test results to Currents-compatible format

```sh
npm run convert
```

- Upload the results to Currents

```sh
npx currents upload --key=your-record-key --project-id=currents-project-id
```

## Resources

- 📖 [Currents documentation](https://docs.currents.dev)
- [`Github actions example`](https://github.com/currents-dev/currents-nodejs-github-actions-example)
- [`@currents/cmd`](https://docs.currents.dev/resources/reporters/currents-cmd)
- [`@currents/node-test-reporter`](https://docs.currents.dev/resources/reporters/currents-node-test-reporter)
41 changes: 41 additions & 0 deletions packages/nodejs-test-runner/annotations.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import assert from 'node:assert';
import { describe, test } from 'node:test';

describe('Math Operations', () => {
describe('Addition', () => {
test('should return 4 when adding 2 + 2', () => {
assert.strictEqual(2 + 2, 4);
});

test.skip('should return 0 when adding -2 + 2', () => {
assert.strictEqual(-2 + 2, 0);
});

test.todo('should handle floating point addition');
});

describe.skip('Subtraction', () => {
test('should return 0 when subtracting 2 - 2', () => {
assert.strictEqual(2 - 2, 0);
});

test('should return -4 when subtracting 2 - 6', () => {
assert.strictEqual(2 - 6, -4);
});
});

describe.todo('Multiplication');

describe('Division', () => {
test('should return 2 when dividing 4 / 2', () => {
assert.strictEqual(4 / 2, 2);
});

test('should throw an error when dividing by 0', () => {
assert.throws(() => {
const result = 4 / 0;
if (!isFinite(result)) throw new Error('Division by zero');
}, /Division by zero/);
});
});
});
10 changes: 10 additions & 0 deletions packages/nodejs-test-runner/bailout.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import test from 'node:test';
import assert from 'node:assert';

test('runs fine', () => {
assert.ok(true);
});

test('should trigger bailout', () => {
process.exit(1);
});
8 changes: 8 additions & 0 deletions packages/nodejs-test-runner/edge-cases.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import test from 'node:test';

// Error during declaration (outside test block)
throw new Error('Declaration error');

test('test that never runs', () => {
// Will be skipped due to error above
});
15 changes: 15 additions & 0 deletions packages/nodejs-test-runner/hooks.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import test from 'node:test';
import assert from 'node:assert';

test('hooks demo', async (t) => {
await t.test(
'with setup and teardown',
{
before: () => console.log('before hook'),
after: () => console.log('after hook'),
},
() => {
assert.strictEqual(1, 1);
}
);
});
46 changes: 46 additions & 0 deletions packages/nodejs-test-runner/nesting.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import assert from 'node:assert';
import { describe, test } from 'node:test';

describe('Math Operations', () => {
describe('Addition', () => {
test('should return 5 when adding 2 and 3', () => {
assert.strictEqual(2 + 3, 5);
});

test('should return 0 when adding -1 and 1', () => {
assert.strictEqual(-1 + 1, 0);
});
});

describe('Subtraction', () => {
test('should return 1 when subtracting 3 from 4', () => {
assert.strictEqual(4 - 3, 1);
});

test('should return -2 when subtracting 3 from 1', () => {
assert.strictEqual(1 - 3, -2);
});
});

describe('Multiplication', () => {
test('should return 6 when multiplying 2 and 3', () => {
assert.strictEqual(2 * 3, 6);
});

test('should return 0 when multiplying any number by 0', () => {
assert.strictEqual(5 * 0, 0);
});
});

describe('Division', () => {
test('should return 2 when dividing 6 by 3', () => {
assert.strictEqual(6 / 3, 2);
});

test('should throw an error when dividing by 0', () => {
assert.throws(() => {
const result = 6 / 0;
}, /Infinity/);
});
});
});
10 changes: 8 additions & 2 deletions packages/nodejs-test-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
"version": "1.0.0",
"description": "Integrate NodeJS test runner with Currents",
"main": "index.js",
"scripts": {},
"scripts": {
"test": "node --test --test-reporter @currents/node-test-reporter --test-reporter-destination=./report.xml **.test.mjs || true && echo '✅ Script executed successfully'",
"convert": "npx currents convert --input-format=junit --input-file=./report.xml --framework=node"
},
"license": "MIT",
"dependencies": {}
"devDependencies": {
"@currents/cmd": "^1.8.0",
"@currents/node-test-reporter": "^1.1.0"
}
}
210 changes: 210 additions & 0 deletions packages/nodejs-test-runner/report.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="root" success="false" time="0.199398">
<testsuite name="annotations.test.mjs" timestamp="2025-04-30T19:11:20.916Z" hostname="Yohays-MacBook-Pro.local" success="true" time="0.026113" failures="0" skipped="4">
<testcase name="Math Operations &gt; Addition &gt; should return 4 when adding 2 + 2" time="0.002083"/>
<testcase name="Math Operations &gt; Addition &gt; should return 0 when adding -2 + 2" time="0.00377">
<skipped/>
</testcase>
<testcase name="Math Operations &gt; Addition &gt; should handle floating point addition" time="0.000069">
<skipped type="todo"/>
</testcase>
<testcase name="Math Operations &gt; Subtraction" time="0.000103" testNumber="2">
<skipped/>
</testcase>
<testcase name="Math Operations &gt; Multiplication" time="0.000027" testNumber="3">
<skipped type="todo"/>
</testcase>
<testcase name="Math Operations &gt; Division &gt; should return 2 when dividing 4 / 2" time="0.000157"/>
<testcase name="Math Operations &gt; Division &gt; should throw an error when dividing by 0" time="0.000198"/>
</testsuite>
<testsuite name="bailout.test.mjs" timestamp="2025-04-30T19:11:20.931Z" hostname="Yohays-MacBook-Pro.local" failures="1" skipped="0" time="0.120945">
<testcase name="bailout.test.mjs" time="0.120945">
<failure type="testCodeFailure" message="test failed
{
&quot;code&quot;: &quot;ERR_TEST_FAILURE&quot;,
&quot;failureType&quot;: &quot;testCodeFailure&quot;,
&quot;cause&quot;: &quot;test failed&quot;,
&quot;exitCode&quot;: 1,
&quot;signal&quot;: null
}
"><![CDATA[{
"code": "ERR_TEST_FAILURE",
"failureType": "testCodeFailure",
"cause": "test failed",
"exitCode": 1,
"signal": null
}
]]></failure>
</testcase>
</testsuite>
<testsuite name="edge-cases.test.mjs" timestamp="2025-04-30T19:11:20.931Z" hostname="Yohays-MacBook-Pro.local" failures="1" skipped="0" time="0.105078">
<testcase name="edge-cases.test.mjs" time="0.105078">
<failure type="testCodeFailure" message="test failed
{
&quot;code&quot;: &quot;ERR_TEST_FAILURE&quot;,
&quot;failureType&quot;: &quot;testCodeFailure&quot;,
&quot;cause&quot;: &quot;test failed&quot;,
&quot;exitCode&quot;: 1,
&quot;signal&quot;: null
}
"><![CDATA[{
"code": "ERR_TEST_FAILURE",
"failureType": "testCodeFailure",
"cause": "test failed",
"exitCode": 1,
"signal": null
}
]]></failure>
</testcase>
</testsuite>
<testsuite name="hooks.test.mjs" timestamp="2025-04-30T19:11:20.931Z" hostname="Yohays-MacBook-Pro.local" success="true" time="0.005633" failures="0" skipped="0">
<testcase name="hooks demo" time="0.000754"/>
<testcase name="hooks demo &gt; with setup and teardown" time="0.000437"/>
</testsuite>
<testsuite name="nesting.test.mjs" timestamp="2025-04-30T19:11:20.932Z" hostname="Yohays-MacBook-Pro.local" success="false" time="0.018113" failures="3" skipped="0">
<testcase name="Math Operations &gt; Addition &gt; should return 5 when adding 2 and 3" time="0.000361"/>
<testcase name="Math Operations &gt; Addition &gt; should return 0 when adding -1 and 1" time="0.000183"/>
<testcase name="Math Operations &gt; Subtraction &gt; should return 1 when subtracting 3 from 4" time="0.000199"/>
<testcase name="Math Operations &gt; Subtraction &gt; should return -2 when subtracting 3 from 1" time="0.00005"/>
<testcase name="Math Operations &gt; Multiplication &gt; should return 6 when multiplying 2 and 3" time="0.000211"/>
<testcase name="Math Operations &gt; Multiplication &gt; should return 0 when multiplying any number by 0" time="0.000066"/>
<testcase name="Math Operations &gt; Division &gt; should return 2 when dividing 6 by 3" time="0.000059"/>
<testcase name="Math Operations &gt; Division &gt; should throw an error when dividing by 0" time="0.000566">
<failure type="testCodeFailure" message="Missing expected exception.
{
&quot;code&quot;: &quot;ERR_TEST_FAILURE&quot;,
&quot;failureType&quot;: &quot;testCodeFailure&quot;,
&quot;cause&quot;: {
&quot;generatedMessage&quot;: false,
&quot;code&quot;: &quot;ERR_ASSERTION&quot;,
&quot;expected&quot;: {},
&quot;operator&quot;: &quot;throws&quot;
}
}
"><![CDATA[{
"code": "ERR_TEST_FAILURE",
"failureType": "testCodeFailure",
"cause": {
"generatedMessage": false,
"code": "ERR_ASSERTION",
"expected": {},
"operator": "throws"
}
}
]]></failure>
</testcase>
</testsuite>
<testsuite name="retries.test.mjs" timestamp="2025-04-30T19:11:20.933Z" hostname="Yohays-MacBook-Pro.local" success="true" time="0.004503" failures="0" skipped="0">
<testcase name="retrying flaky test" time="0.000526"/>
</testsuite>
<testsuite name="simple.test.mjs" timestamp="2025-04-30T19:11:20.933Z" hostname="Yohays-MacBook-Pro.local" success="false" time="0.022152" failures="2" skipped="0">
<testcase name="Math operations - addition" time="0.001184"/>
<testcase name="Math operations - subtraction" time="0.000088"/>
<testcase name="Math operations - multiplication" time="0.000051"/>
<testcase name="Math operations - division" time="0.000046"/>
<testcase name="Math operations - division by zero" time="0.000048"/>
<testcase name="Math operations - incorrect addition" time="0.002698">
<failure type="testCodeFailure" message="Expected values to be strictly equal:

4 !== 5

{
&quot;code&quot;: &quot;ERR_TEST_FAILURE&quot;,
&quot;failureType&quot;: &quot;testCodeFailure&quot;,
&quot;cause&quot;: {
&quot;generatedMessage&quot;: true,
&quot;code&quot;: &quot;ERR_ASSERTION&quot;,
&quot;actual&quot;: 4,
&quot;expected&quot;: 5,
&quot;operator&quot;: &quot;strictEqual&quot;
}
}
"><![CDATA[{
"code": "ERR_TEST_FAILURE",
"failureType": "testCodeFailure",
"cause": {
"generatedMessage": true,
"code": "ERR_ASSERTION",
"actual": 4,
"expected": 5,
"operator": "strictEqual"
}
}
]]></failure>
</testcase>
<testcase name="Math operations - incorrect addition &gt; should return 5" time="0.000643">
<failure type="testCodeFailure" message="Expected values to be strictly equal:

4 !== 5

{
&quot;code&quot;: &quot;ERR_TEST_FAILURE&quot;,
&quot;failureType&quot;: &quot;testCodeFailure&quot;,
&quot;cause&quot;: {
&quot;generatedMessage&quot;: true,
&quot;code&quot;: &quot;ERR_ASSERTION&quot;,
&quot;actual&quot;: 4,
&quot;expected&quot;: 5,
&quot;operator&quot;: &quot;strictEqual&quot;
}
}
"><![CDATA[{
"code": "ERR_TEST_FAILURE",
"failureType": "testCodeFailure",
"cause": {
"generatedMessage": true,
"code": "ERR_ASSERTION",
"actual": 4,
"expected": 5,
"operator": "strictEqual"
}
}
]]></failure>
</testcase>
</testsuite>
<testsuite name="subtests.test.mjs" timestamp="2025-04-30T19:11:20.933Z" hostname="Yohays-MacBook-Pro.local" success="true" time="0.028295" failures="0" skipped="2">
<testcase name="Main test with subtests" time="0.00158"/>
<testcase name="Main test with subtests &gt; adds numbers" time="0.000409"/>
<testcase name="Main test with subtests &gt; subtracts numbers" time="0.000057"/>
<testcase name="Table-driven cases" time="0.002473"/>
<testcase name="Table-driven cases &gt; adds 1 + 2 = 3" time="0.00225"/>
<testcase name="Table-driven cases &gt; adds 4 + 5 = 9" time="0.000058"/>
<testcase name="User actions" time="0.001234"/>
<testcase name="User actions &gt; Login" time="0.000809"/>
<testcase name="User actions &gt; Login &gt; with correct credentials" time="0.000185"/>
<testcase name="User actions &gt; Login &gt; with wrong credentials" time="0.000064"/>
<testcase name="User actions &gt; Logout" time="0.000148"/>
<testcase name="Async data fetch" time="0.010975"/>
<testcase name="Async data fetch &gt; simulated fetch" time="0.010856"/>
<testcase name="Options demo" time="0.000293"/>
<testcase name="Options demo &gt; concurrent test" time="0.000047"/>
<testcase name="Options demo &gt; this is skipped" time="0.000025">
<skipped/>
</testcase>
<testcase name="Options demo &gt; this is not a TODO" time="0.000021"/>
<testcase name="Options demo &gt; this is a TODO" time="0.000023">
<skipped type="todo"/>
</testcase>
<testcase name="Setup example" time="0.000121"/>
<testcase name="Setup example &gt; uses sharedValue" time="0.000038"/>
<testcase name="Setup example &gt; still has access" time="0.000025"/>
<testcase name="Early exit example" time="0.000114"/>
<testcase name="Early exit example &gt; initial check" time="0.000031"/>
</testsuite>
<testsuite name="timeout.test.mjs" timestamp="2025-04-30T19:11:20.936Z" hostname="Yohays-MacBook-Pro.local" success="false" time="0.003135" failures="1" skipped="0">
<testcase name="this will timeout" time="0.001632">
<failure type="cancelledByParent" message="Promise resolution is still pending but the event loop has already resolved
{
&quot;code&quot;: &quot;ERR_TEST_FAILURE&quot;,
&quot;failureType&quot;: &quot;cancelledByParent&quot;,
&quot;cause&quot;: &quot;Promise resolution is still pending but the event loop has already resolved&quot;
}
"><![CDATA[{
"code": "ERR_TEST_FAILURE",
"failureType": "cancelledByParent",
"cause": "Promise resolution is still pending but the event loop has already resolved"
}
]]></failure>
</testcase>
</testsuite>
</testsuites>
Loading
Loading