This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 657
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(rome_wasm): fix the WASM diagnostic printer (#3349)
* fix(rome_wasm): fix the WASM diagnostic printer and add a snapshot test for it * fix the formatting
- Loading branch information
Showing
4 changed files
with
118 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
npm/js-api/tests/wasm/__snapshots__/diagnosticPrinter.test.mjs.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Vitest Snapshot v1 | ||
|
||
exports[`Rome WebAssembly DiagnosticPrinter > should format content > HTML diagnostic 1`] = ` | ||
"file.js:3:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
<strong><span style=\\"color: Tomato;\\"> </span></strong><strong><span style=\\"color: Tomato;\\">✖</span></strong> <span style=\\"color: Tomato;\\">error message content</span> | ||
<strong>1 │ </strong>const variable = expr(); | ||
<strong>2 │ </strong> | ||
<strong><span style=\\"color: Tomato;\\"> </span></strong><strong><span style=\\"color: Tomato;\\">></span></strong> <strong>3 │ </strong>if(expr()) { | ||
<strong> │ </strong> <strong><span style=\\"color: Tomato;\\">^</span></strong><strong><span style=\\"color: Tomato;\\">^</span></strong><strong><span style=\\"color: Tomato;\\">^</span></strong><strong><span style=\\"color: Tomato;\\">^</span></strong><strong><span style=\\"color: Tomato;\\">^</span></strong><strong><span style=\\"color: Tomato;\\">^</span></strong> | ||
<strong>4 │ </strong> statement(); | ||
<strong>5 │ </strong>} | ||
file.js:4:8 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
<strong><span style=\\"color: Tomato;\\"> </span></strong><strong><span style=\\"color: Tomato;\\">✖</span></strong> <span style=\\"color: Tomato;\\">error message content</span> | ||
<strong>3 │ </strong>if(expr()) { | ||
<strong><span style=\\"color: Tomato;\\"> </span></strong><strong><span style=\\"color: Tomato;\\">></span></strong> <strong>4 │ </strong> statement(); | ||
<strong> │ </strong> <strong><span style=\\"color: Tomato;\\">^</span></strong><strong><span style=\\"color: Tomato;\\">^</span></strong><strong><span style=\\"color: Tomato;\\">^</span></strong><strong><span style=\\"color: Tomato;\\">^</span></strong><strong><span style=\\"color: Tomato;\\">^</span></strong><strong><span style=\\"color: Tomato;\\">^</span></strong><strong><span style=\\"color: Tomato;\\">^</span></strong><strong><span style=\\"color: Tomato;\\">^</span></strong><strong><span style=\\"color: Tomato;\\">^</span></strong> | ||
<strong><span style=\\"color: Tomato;\\"> </span></strong><strong><span style=\\"color: Tomato;\\">></span></strong> <strong>5 │ </strong>} | ||
<strong> │ </strong><strong><span style=\\"color: Tomato;\\">^</span></strong> | ||
" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { DiagnosticPrinter } from "@rometools/wasm-nodejs"; | ||
|
||
describe("Rome WebAssembly DiagnosticPrinter", () => { | ||
it("should format content", async () => { | ||
const SOURCE_CODE = `const variable = expr(); | ||
if(expr()) { | ||
statement(); | ||
}`; | ||
const printer = new DiagnosticPrinter("file.js", SOURCE_CODE); | ||
|
||
printer.print({ | ||
advices: { | ||
advices: [], | ||
}, | ||
category: "parse", | ||
description: "error description content", | ||
location: { | ||
path: { | ||
File: { | ||
PathAndId: { | ||
file_id: 0, | ||
path: "file.js", | ||
}, | ||
}, | ||
}, | ||
source_code: null, | ||
span: [31, 37], | ||
}, | ||
message: [ | ||
{ | ||
content: "error message content", | ||
elements: [], | ||
}, | ||
], | ||
severity: "Error", | ||
source: null, | ||
tags: [], | ||
verbose_advices: { | ||
advices: [], | ||
}, | ||
}); | ||
|
||
printer.print({ | ||
advices: { | ||
advices: [], | ||
}, | ||
category: "parse", | ||
description: "error description content", | ||
location: { | ||
path: { | ||
File: { | ||
PathAndId: { | ||
file_id: 0, | ||
path: "file.js", | ||
}, | ||
}, | ||
}, | ||
source_code: null, | ||
span: [46, 58], | ||
}, | ||
message: [ | ||
{ | ||
content: "error message content", | ||
elements: [], | ||
}, | ||
], | ||
severity: "Error", | ||
source: null, | ||
tags: [], | ||
verbose_advices: { | ||
advices: [], | ||
}, | ||
}); | ||
|
||
const html = printer.finish(); | ||
expect(html).toMatchSnapshot("HTML diagnostic"); | ||
}); | ||
}); |