Skip to content

Commit 8e54d53

Browse files
authored
Merge pull request #3 from currents-dev/ynahmany/adding-nodejs-reporter
[CSR-2484] chore: adding node js example
2 parents 366a193 + 310584c commit 8e54d53

13 files changed

+6694
-2466
lines changed

package-lock.json

+6,161-2,463
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/nodejs-test-runner/README.md

+30-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
11
# NodeJS Test Runner + Currents
22

3-
👷🏾‍♀️ Work in progress
3+
## How to
4+
5+
Follow the steps to reproduce this example:
6+
7+
- Create an account at https://app.currents.dev and obtain Project Id and Record Key
8+
- Get a Record key and Project ID from Currents dashboard
9+
- Run the test
10+
11+
```sh
12+
npm run test
13+
```
14+
15+
- Convert JUnit test results to Currents-compatible format
16+
17+
```sh
18+
npm run convert
19+
```
20+
21+
- Upload the results to Currents
22+
23+
```sh
24+
npx currents upload --key=your-record-key --project-id=currents-project-id
25+
```
26+
27+
## Resources
28+
29+
- 📖 [Currents documentation](https://docs.currents.dev)
30+
- [`Github actions example`](https://github.com/currents-dev/currents-nodejs-github-actions-example)
31+
- [`@currents/cmd`](https://docs.currents.dev/resources/reporters/currents-cmd)
32+
- [`@currents/node-test-reporter`](https://docs.currents.dev/resources/reporters/currents-node-test-reporter)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import assert from 'node:assert';
2+
import { describe, test } from 'node:test';
3+
4+
describe('Math Operations', () => {
5+
describe('Addition', () => {
6+
test('should return 4 when adding 2 + 2', () => {
7+
assert.strictEqual(2 + 2, 4);
8+
});
9+
10+
test.skip('should return 0 when adding -2 + 2', () => {
11+
assert.strictEqual(-2 + 2, 0);
12+
});
13+
14+
test.todo('should handle floating point addition');
15+
});
16+
17+
describe.skip('Subtraction', () => {
18+
test('should return 0 when subtracting 2 - 2', () => {
19+
assert.strictEqual(2 - 2, 0);
20+
});
21+
22+
test('should return -4 when subtracting 2 - 6', () => {
23+
assert.strictEqual(2 - 6, -4);
24+
});
25+
});
26+
27+
describe.todo('Multiplication');
28+
29+
describe('Division', () => {
30+
test('should return 2 when dividing 4 / 2', () => {
31+
assert.strictEqual(4 / 2, 2);
32+
});
33+
34+
test('should throw an error when dividing by 0', () => {
35+
assert.throws(() => {
36+
const result = 4 / 0;
37+
if (!isFinite(result)) throw new Error('Division by zero');
38+
}, /Division by zero/);
39+
});
40+
});
41+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import test from 'node:test';
2+
import assert from 'node:assert';
3+
4+
test('runs fine', () => {
5+
assert.ok(true);
6+
});
7+
8+
test('should trigger bailout', () => {
9+
process.exit(1);
10+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import test from 'node:test';
2+
3+
// Error during declaration (outside test block)
4+
throw new Error('Declaration error');
5+
6+
test('test that never runs', () => {
7+
// Will be skipped due to error above
8+
});
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import test from 'node:test';
2+
import assert from 'node:assert';
3+
4+
test('hooks demo', async (t) => {
5+
await t.test(
6+
'with setup and teardown',
7+
{
8+
before: () => console.log('before hook'),
9+
after: () => console.log('after hook'),
10+
},
11+
() => {
12+
assert.strictEqual(1, 1);
13+
}
14+
);
15+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import assert from 'node:assert';
2+
import { describe, test } from 'node:test';
3+
4+
describe('Math Operations', () => {
5+
describe('Addition', () => {
6+
test('should return 5 when adding 2 and 3', () => {
7+
assert.strictEqual(2 + 3, 5);
8+
});
9+
10+
test('should return 0 when adding -1 and 1', () => {
11+
assert.strictEqual(-1 + 1, 0);
12+
});
13+
});
14+
15+
describe('Subtraction', () => {
16+
test('should return 1 when subtracting 3 from 4', () => {
17+
assert.strictEqual(4 - 3, 1);
18+
});
19+
20+
test('should return -2 when subtracting 3 from 1', () => {
21+
assert.strictEqual(1 - 3, -2);
22+
});
23+
});
24+
25+
describe('Multiplication', () => {
26+
test('should return 6 when multiplying 2 and 3', () => {
27+
assert.strictEqual(2 * 3, 6);
28+
});
29+
30+
test('should return 0 when multiplying any number by 0', () => {
31+
assert.strictEqual(5 * 0, 0);
32+
});
33+
});
34+
35+
describe('Division', () => {
36+
test('should return 2 when dividing 6 by 3', () => {
37+
assert.strictEqual(6 / 3, 2);
38+
});
39+
40+
test('should throw an error when dividing by 0', () => {
41+
assert.throws(() => {
42+
const result = 6 / 0;
43+
}, /Infinity/);
44+
});
45+
});
46+
});

packages/nodejs-test-runner/package.json

+8-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
"version": "1.0.0",
44
"description": "Integrate NodeJS test runner with Currents",
55
"main": "index.js",
6-
"scripts": {},
6+
"scripts": {
7+
"test": "node --test --test-reporter @currents/node-test-reporter --test-reporter-destination=./report.xml **.test.mjs || true && echo '✅ Script executed successfully'",
8+
"convert": "npx currents convert --input-format=junit --input-file=./report.xml --framework=node"
9+
},
710
"license": "MIT",
8-
"dependencies": {}
11+
"devDependencies": {
12+
"@currents/cmd": "^1.8.0",
13+
"@currents/node-test-reporter": "^1.1.0"
14+
}
915
}
+210
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuites name="root" success="false" time="0.199398">
3+
<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">
4+
<testcase name="Math Operations &gt; Addition &gt; should return 4 when adding 2 + 2" time="0.002083"/>
5+
<testcase name="Math Operations &gt; Addition &gt; should return 0 when adding -2 + 2" time="0.00377">
6+
<skipped/>
7+
</testcase>
8+
<testcase name="Math Operations &gt; Addition &gt; should handle floating point addition" time="0.000069">
9+
<skipped type="todo"/>
10+
</testcase>
11+
<testcase name="Math Operations &gt; Subtraction" time="0.000103" testNumber="2">
12+
<skipped/>
13+
</testcase>
14+
<testcase name="Math Operations &gt; Multiplication" time="0.000027" testNumber="3">
15+
<skipped type="todo"/>
16+
</testcase>
17+
<testcase name="Math Operations &gt; Division &gt; should return 2 when dividing 4 / 2" time="0.000157"/>
18+
<testcase name="Math Operations &gt; Division &gt; should throw an error when dividing by 0" time="0.000198"/>
19+
</testsuite>
20+
<testsuite name="bailout.test.mjs" timestamp="2025-04-30T19:11:20.931Z" hostname="Yohays-MacBook-Pro.local" failures="1" skipped="0" time="0.120945">
21+
<testcase name="bailout.test.mjs" time="0.120945">
22+
<failure type="testCodeFailure" message="test failed
23+
{
24+
&quot;code&quot;: &quot;ERR_TEST_FAILURE&quot;,
25+
&quot;failureType&quot;: &quot;testCodeFailure&quot;,
26+
&quot;cause&quot;: &quot;test failed&quot;,
27+
&quot;exitCode&quot;: 1,
28+
&quot;signal&quot;: null
29+
}
30+
"><![CDATA[{
31+
"code": "ERR_TEST_FAILURE",
32+
"failureType": "testCodeFailure",
33+
"cause": "test failed",
34+
"exitCode": 1,
35+
"signal": null
36+
}
37+
]]></failure>
38+
</testcase>
39+
</testsuite>
40+
<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">
41+
<testcase name="edge-cases.test.mjs" time="0.105078">
42+
<failure type="testCodeFailure" message="test failed
43+
{
44+
&quot;code&quot;: &quot;ERR_TEST_FAILURE&quot;,
45+
&quot;failureType&quot;: &quot;testCodeFailure&quot;,
46+
&quot;cause&quot;: &quot;test failed&quot;,
47+
&quot;exitCode&quot;: 1,
48+
&quot;signal&quot;: null
49+
}
50+
"><![CDATA[{
51+
"code": "ERR_TEST_FAILURE",
52+
"failureType": "testCodeFailure",
53+
"cause": "test failed",
54+
"exitCode": 1,
55+
"signal": null
56+
}
57+
]]></failure>
58+
</testcase>
59+
</testsuite>
60+
<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">
61+
<testcase name="hooks demo" time="0.000754"/>
62+
<testcase name="hooks demo &gt; with setup and teardown" time="0.000437"/>
63+
</testsuite>
64+
<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">
65+
<testcase name="Math Operations &gt; Addition &gt; should return 5 when adding 2 and 3" time="0.000361"/>
66+
<testcase name="Math Operations &gt; Addition &gt; should return 0 when adding -1 and 1" time="0.000183"/>
67+
<testcase name="Math Operations &gt; Subtraction &gt; should return 1 when subtracting 3 from 4" time="0.000199"/>
68+
<testcase name="Math Operations &gt; Subtraction &gt; should return -2 when subtracting 3 from 1" time="0.00005"/>
69+
<testcase name="Math Operations &gt; Multiplication &gt; should return 6 when multiplying 2 and 3" time="0.000211"/>
70+
<testcase name="Math Operations &gt; Multiplication &gt; should return 0 when multiplying any number by 0" time="0.000066"/>
71+
<testcase name="Math Operations &gt; Division &gt; should return 2 when dividing 6 by 3" time="0.000059"/>
72+
<testcase name="Math Operations &gt; Division &gt; should throw an error when dividing by 0" time="0.000566">
73+
<failure type="testCodeFailure" message="Missing expected exception.
74+
{
75+
&quot;code&quot;: &quot;ERR_TEST_FAILURE&quot;,
76+
&quot;failureType&quot;: &quot;testCodeFailure&quot;,
77+
&quot;cause&quot;: {
78+
&quot;generatedMessage&quot;: false,
79+
&quot;code&quot;: &quot;ERR_ASSERTION&quot;,
80+
&quot;expected&quot;: {},
81+
&quot;operator&quot;: &quot;throws&quot;
82+
}
83+
}
84+
"><![CDATA[{
85+
"code": "ERR_TEST_FAILURE",
86+
"failureType": "testCodeFailure",
87+
"cause": {
88+
"generatedMessage": false,
89+
"code": "ERR_ASSERTION",
90+
"expected": {},
91+
"operator": "throws"
92+
}
93+
}
94+
]]></failure>
95+
</testcase>
96+
</testsuite>
97+
<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">
98+
<testcase name="retrying flaky test" time="0.000526"/>
99+
</testsuite>
100+
<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">
101+
<testcase name="Math operations - addition" time="0.001184"/>
102+
<testcase name="Math operations - subtraction" time="0.000088"/>
103+
<testcase name="Math operations - multiplication" time="0.000051"/>
104+
<testcase name="Math operations - division" time="0.000046"/>
105+
<testcase name="Math operations - division by zero" time="0.000048"/>
106+
<testcase name="Math operations - incorrect addition" time="0.002698">
107+
<failure type="testCodeFailure" message="Expected values to be strictly equal:
108+
109+
4 !== 5
110+
111+
{
112+
&quot;code&quot;: &quot;ERR_TEST_FAILURE&quot;,
113+
&quot;failureType&quot;: &quot;testCodeFailure&quot;,
114+
&quot;cause&quot;: {
115+
&quot;generatedMessage&quot;: true,
116+
&quot;code&quot;: &quot;ERR_ASSERTION&quot;,
117+
&quot;actual&quot;: 4,
118+
&quot;expected&quot;: 5,
119+
&quot;operator&quot;: &quot;strictEqual&quot;
120+
}
121+
}
122+
"><![CDATA[{
123+
"code": "ERR_TEST_FAILURE",
124+
"failureType": "testCodeFailure",
125+
"cause": {
126+
"generatedMessage": true,
127+
"code": "ERR_ASSERTION",
128+
"actual": 4,
129+
"expected": 5,
130+
"operator": "strictEqual"
131+
}
132+
}
133+
]]></failure>
134+
</testcase>
135+
<testcase name="Math operations - incorrect addition &gt; should return 5" time="0.000643">
136+
<failure type="testCodeFailure" message="Expected values to be strictly equal:
137+
138+
4 !== 5
139+
140+
{
141+
&quot;code&quot;: &quot;ERR_TEST_FAILURE&quot;,
142+
&quot;failureType&quot;: &quot;testCodeFailure&quot;,
143+
&quot;cause&quot;: {
144+
&quot;generatedMessage&quot;: true,
145+
&quot;code&quot;: &quot;ERR_ASSERTION&quot;,
146+
&quot;actual&quot;: 4,
147+
&quot;expected&quot;: 5,
148+
&quot;operator&quot;: &quot;strictEqual&quot;
149+
}
150+
}
151+
"><![CDATA[{
152+
"code": "ERR_TEST_FAILURE",
153+
"failureType": "testCodeFailure",
154+
"cause": {
155+
"generatedMessage": true,
156+
"code": "ERR_ASSERTION",
157+
"actual": 4,
158+
"expected": 5,
159+
"operator": "strictEqual"
160+
}
161+
}
162+
]]></failure>
163+
</testcase>
164+
</testsuite>
165+
<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">
166+
<testcase name="Main test with subtests" time="0.00158"/>
167+
<testcase name="Main test with subtests &gt; adds numbers" time="0.000409"/>
168+
<testcase name="Main test with subtests &gt; subtracts numbers" time="0.000057"/>
169+
<testcase name="Table-driven cases" time="0.002473"/>
170+
<testcase name="Table-driven cases &gt; adds 1 + 2 = 3" time="0.00225"/>
171+
<testcase name="Table-driven cases &gt; adds 4 + 5 = 9" time="0.000058"/>
172+
<testcase name="User actions" time="0.001234"/>
173+
<testcase name="User actions &gt; Login" time="0.000809"/>
174+
<testcase name="User actions &gt; Login &gt; with correct credentials" time="0.000185"/>
175+
<testcase name="User actions &gt; Login &gt; with wrong credentials" time="0.000064"/>
176+
<testcase name="User actions &gt; Logout" time="0.000148"/>
177+
<testcase name="Async data fetch" time="0.010975"/>
178+
<testcase name="Async data fetch &gt; simulated fetch" time="0.010856"/>
179+
<testcase name="Options demo" time="0.000293"/>
180+
<testcase name="Options demo &gt; concurrent test" time="0.000047"/>
181+
<testcase name="Options demo &gt; this is skipped" time="0.000025">
182+
<skipped/>
183+
</testcase>
184+
<testcase name="Options demo &gt; this is not a TODO" time="0.000021"/>
185+
<testcase name="Options demo &gt; this is a TODO" time="0.000023">
186+
<skipped type="todo"/>
187+
</testcase>
188+
<testcase name="Setup example" time="0.000121"/>
189+
<testcase name="Setup example &gt; uses sharedValue" time="0.000038"/>
190+
<testcase name="Setup example &gt; still has access" time="0.000025"/>
191+
<testcase name="Early exit example" time="0.000114"/>
192+
<testcase name="Early exit example &gt; initial check" time="0.000031"/>
193+
</testsuite>
194+
<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">
195+
<testcase name="this will timeout" time="0.001632">
196+
<failure type="cancelledByParent" message="Promise resolution is still pending but the event loop has already resolved
197+
{
198+
&quot;code&quot;: &quot;ERR_TEST_FAILURE&quot;,
199+
&quot;failureType&quot;: &quot;cancelledByParent&quot;,
200+
&quot;cause&quot;: &quot;Promise resolution is still pending but the event loop has already resolved&quot;
201+
}
202+
"><![CDATA[{
203+
"code": "ERR_TEST_FAILURE",
204+
"failureType": "cancelledByParent",
205+
"cause": "Promise resolution is still pending but the event loop has already resolved"
206+
}
207+
]]></failure>
208+
</testcase>
209+
</testsuite>
210+
</testsuites>

0 commit comments

Comments
 (0)