Skip to content

Commit

Permalink
Fix test runner events parsing and align with node 20.7.0 (#83)
Browse files Browse the repository at this point in the history
* fix: parse file path from test runner events

* test: align tests to node 20.7.0 and fix build

* fix: make file path parsing safer
  • Loading branch information
msebastianb authored Sep 27, 2023
1 parent 3817b16 commit 41efff7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
20 changes: 19 additions & 1 deletion parse-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
EVENT_TEST_DIAGNOSTIC,
ERROR_CODE_TEST_FAILURE
} from './constants.js'
import { URL, fileURLToPath } from 'node:url'

const durationRegex = /duration_ms\s([\d.]+)/

Expand All @@ -27,6 +28,23 @@ export default async function parseReport(source) {
diagnosticMessage = ''
}

function isFileUrl(urlString) {
try {
const url = new URL(urlString)
return url.protocol === 'file:'
} catch (error) {
return false
}
}

function parseFilePath(fileString) {
if (isFileUrl(fileString)) {
return fileURLToPath(fileString)
} else {
return fileString
}
}

for await (const event of source) {
switch (event.type) {
case EVENT_TEST_START:
Expand All @@ -38,7 +56,7 @@ export default async function parseReport(source) {

testStack.push({
name,
file,
file: parseFilePath(file),
tests: []
})

Expand Down
10 changes: 5 additions & 5 deletions test/resources/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"failure": {
"failureType": "testCodeFailure",
"cause": {
"generatedMessage": false,
"generatedMessage": true,
"code": "ERR_ASSERTION",
"actual": 1,
"expected": 2,
Expand All @@ -58,7 +58,7 @@
"todo": false,
"error": {
"failureType": "subtestsFailed",
"cause": {},
"cause": "1 subtest failed",
"code": "ERR_TEST_FAILURE"
}
}
Expand All @@ -68,7 +68,7 @@
"todo": false,
"error": {
"failureType": "subtestsFailed",
"cause": {},
"cause": "1 subtest failed",
"code": "ERR_TEST_FAILURE"
}
}
Expand All @@ -78,7 +78,7 @@
"todo": false,
"error": {
"failureType": "subtestsFailed",
"cause": {},
"cause": "1 subtest failed",
"code": "ERR_TEST_FAILURE"
}
},
Expand Down Expand Up @@ -108,7 +108,7 @@
"todo": false,
"error": {
"failureType": "testTimeoutFailure",
"cause": {},
"cause": "test timed out after 100ms",
"code": "ERR_TEST_FAILURE"
}
},
Expand Down

0 comments on commit 41efff7

Please sign in to comment.