Skip to content

Commit

Permalink
feat: support vitest v1.0.0-beta.3 (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Oct 27, 2023
1 parent 101a26c commit d2df298
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 58 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -39,7 +39,7 @@
"publint": "^0.2.5",
"typescript": "^5.2.2",
"vite": "^4.5.0",
"vitest": "1.0.0-beta.2"
"vitest": "1.0.0-beta.3"
},
"peerDependencies": {
"vitest": ">=0.18.0"
Expand Down
73 changes: 35 additions & 38 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 32 additions & 19 deletions src/xml.ts
Expand Up @@ -61,25 +61,29 @@ function generateTestCaseElement(test: Test) {
);

if (test.result?.state === 'fail') {
const element =
test.result.error?.name === 'AssertionError' ? 'failure' : 'error';

return join(
start,
'>',
NEWLINE,
indent(3),
`<${element} message="${escapeXML(test.result.error?.message)}">`,
NEWLINE,
indent(4),
`<![CDATA[${escapeXML(test.result.error?.stack)}]]>`,
NEWLINE,
indent(3),
`</${element}>`,
NEWLINE,
indent(2),
'</testCase>',
);
return parseErrors(test)
?.map((error) => {
const element =
error?.name === 'AssertionError' ? 'failure' : 'error';

return join(
start,
'>',
NEWLINE,
indent(3),
`<${element} message="${escapeXML(error?.message)}">`,
NEWLINE,
indent(4),
`<![CDATA[${escapeXML(error?.stack)}]]>`,
NEWLINE,
indent(3),
`</${element}>`,
NEWLINE,
indent(2),
'</testCase>',
);
})
.join(NEWLINE);
}

if (
Expand Down Expand Up @@ -143,3 +147,12 @@ function join(...lines: (string | undefined)[]) {
function indent(level: number) {
return ' '.repeat(level);
}

function parseErrors(test: Test) {
// Vitest v1-beta-02 and 0.x
if (test.result && 'error' in test.result)
return [test.result.error] as NonNullable<Test['result']>['errors'];

// Vitest v1-beta-03
return test.result?.errors;
}

0 comments on commit d2df298

Please sign in to comment.