Skip to content

Commit 7f496b4

Browse files
authored
test(vscode): wait for expected diagnostics in fixAll E2E setups (#25)
Since @rslint/core 0.8.1 (web-infra-dev/rslint#1790), a file created after its project was loaded is served by a type-info-less fallback Program until a watcher event admits it into the configured project, so the first non-empty publish may carry only non-type-aware rules on platforms with slow file watchers (macOS). The fixAll suites create their targets through withTmpFile and asserted on that first non-empty publish, which now fails. Setup waits go through a new waitForDiagnosticsWithMessages helper that waits until the expected diagnostics are present — the terminal assertion is unchanged and holds on both 0.8.0 and 0.8.1. The lint fixture floor moves to ^0.8.1 to match what CI resolves.
1 parent efdcbe8 commit 7f496b4

5 files changed

Lines changed: 66 additions & 13 deletions

File tree

‎packages/vscode/e2e/lint/fixtures/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"description": "Shared install root for the Rslint E2E fixture workspaces. The extension ships no binary: every fixture resolves @rslint/core - including its native Go binary, config-loader and eslint-plugin host - from this one published-npm install. jiti backs the config-file-loader's TypeScript-config fallback.",
66
"dependencies": {
7-
"@rslint/core": "^0.8.0",
7+
"@rslint/core": "^0.8.1",
88
"jiti": "^2.7.0"
99
}
1010
}

‎packages/vscode/e2e/lint/suite/fixall-error.test.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
// Ported verbatim from web-infra-dev/rslint
1+
// Ported from web-infra-dev/rslint (deviation: setup waits go through
2+
// waitForDiagnosticsWithMessages -- see fixall-helpers.ts for why).
23
// `packages/vscode-extension/__tests__/suite/fixall-error.test.ts` (origin/main).
34
import * as assert from 'assert';
45
import * as vscode from 'vscode';
56
import {
6-
waitForDiagnostics,
7+
waitForDiagnosticsWithMessages,
78
waitForContentChange,
89
findFixAllAction,
910
requestFixAll,
@@ -57,7 +58,10 @@ suite('rslint fixAll - error flows', function () {
5758
editor,
5859
"const pVal: string = 'x';\nconst pRes = (pVal as string).trim();\n",
5960
);
60-
const probeDiags = await waitForDiagnostics(doc);
61+
const probeDiags = await waitForDiagnosticsWithMessages(
62+
doc,
63+
'no-unnecessary-type-assertion',
64+
);
6165
assert.ok(
6266
probeDiags.some((d) =>
6367
d.message.includes('no-unnecessary-type-assertion'),

‎packages/vscode/e2e/lint/suite/fixall-helpers.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,29 @@ import { waitForCodeActionRegistryQuiescence } from '../utils/codeActionRegistry
1919
export { saveDocumentOnce } from '../utils/codeActionRegistry';
2020

2121
export const waitForDiagnostics = waitForRslintDiagnostics;
22+
23+
/**
24+
* Wait until the rslint diagnostics for `doc` include every given message
25+
* substring.
26+
*
27+
* Deviation from the upstream suites, which assert on the first non-empty
28+
* publish: since @rslint/core 0.8.1 (web-infra-dev/rslint#1790), a file
29+
* created after its project was loaded is served by a type-info-less fallback
30+
* Program until a watcher event admits it into the configured project, so the
31+
* first non-empty publish may carry only non-type-aware rules on platforms
32+
* with slow file watchers (macOS). Waiting for the expected diagnostics keeps
33+
* the terminal assertion identical without depending on publish batching.
34+
*/
35+
export function waitForDiagnosticsWithMessages(
36+
doc: vscode.TextDocument,
37+
...messages: string[]
38+
): Promise<vscode.Diagnostic[]> {
39+
return waitForRslintDiagnostics(doc, (diagnostics) =>
40+
messages.every((message) =>
41+
diagnostics.some((diagnostic) => diagnostic.message.includes(message)),
42+
),
43+
);
44+
}
2245
export const waitForDiagnosticsCount = waitForRslintDiagnosticsCount;
2346
export const waitForDiagnosticsToChange = waitForRslintDiagnosticsToChange;
2447

‎packages/vscode/e2e/lint/suite/fixall-onsave.test.ts‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
// Ported verbatim from web-infra-dev/rslint
1+
// Ported from web-infra-dev/rslint (deviation: setup waits go through
2+
// waitForDiagnosticsWithMessages -- see fixall-helpers.ts for why).
23
// `packages/vscode-extension/__tests__/suite/fixall-onsave.test.ts` (origin/main).
34
import * as assert from 'assert';
45
import * as vscode from 'vscode';
56
import { getRslintDiagnostics } from '../utils/diagnostics';
67
import { waitForCodeActionRegistryQuiescence } from '../utils/codeActionRegistry';
78
import {
89
waitForDiagnostics,
10+
waitForDiagnosticsWithMessages,
911
waitForDiagnosticsCount,
1012
waitForContentChange,
1113
withOnSaveFixAll,
@@ -38,7 +40,10 @@ suite('rslint fixAll - on-save', function () {
3840
"const gfVal: string = 'x';\nconst gfRes = (gfVal as string).trim();\n",
3941
);
4042

41-
const diags = await waitForDiagnostics(doc);
43+
const diags = await waitForDiagnosticsWithMessages(
44+
doc,
45+
'no-unnecessary-type-assertion',
46+
);
4247
assertHasFixableDiagnostic(diags, 'generic source.fixAll setup');
4348

4449
await saveDocumentOnce(
@@ -69,7 +74,10 @@ suite('rslint fixAll - on-save', function () {
6974
].join('\n');
7075
await replaceAll(editor, fixableContent);
7176

72-
const diags = await waitForDiagnostics(doc);
77+
const diags = await waitForDiagnosticsWithMessages(
78+
doc,
79+
'no-unnecessary-type-assertion',
80+
);
7381
assertHasFixableDiagnostic(diags, 'fixable on-save setup');
7482

7583
await saveDocumentOnce(doc, 'Fixable document should save');
@@ -93,7 +101,10 @@ suite('rslint fixAll - on-save', function () {
93101
editor,
94102
"const probeVal: string = 'x';\nconst probeRes = (probeVal as string).trim();\n",
95103
);
96-
const probeDiags = await waitForDiagnostics(doc);
104+
const probeDiags = await waitForDiagnosticsWithMessages(
105+
doc,
106+
'no-unnecessary-type-assertion',
107+
);
97108
assertHasFixableDiagnostic(probeDiags, 'clean-file probe setup');
98109
await saveDocumentOnce(doc, 'Clean-file probe should save');
99110
await waitForContentChange(
@@ -130,7 +141,10 @@ suite('rslint fixAll - on-save', function () {
130141
editor,
131142
"const probeVal2: string = 'x';\nconst probeRes2 = (probeVal2 as string).trim();\n",
132143
);
133-
const probeDiags = await waitForDiagnostics(doc);
144+
const probeDiags = await waitForDiagnosticsWithMessages(
145+
doc,
146+
'no-unnecessary-type-assertion',
147+
);
134148
assertHasFixableDiagnostic(probeDiags, 'non-fixable probe setup');
135149
await saveDocumentOnce(doc, 'Non-fixable probe should save');
136150
await waitForContentChange(

‎packages/vscode/e2e/lint/suite/fixall.test.ts‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
// Ported verbatim from web-infra-dev/rslint
1+
// Ported from web-infra-dev/rslint (deviation: setup waits go through
2+
// waitForDiagnosticsWithMessages -- see fixall-helpers.ts for why).
23
// `packages/vscode-extension/__tests__/suite/fixall.test.ts` (origin/main).
34
import * as assert from 'assert';
45
import * as vscode from 'vscode';
56
import {
67
waitForDiagnostics,
8+
waitForDiagnosticsWithMessages,
79
waitForDiagnosticsToChange,
810
waitForDiagnosticsCount,
911
openFixture,
@@ -127,7 +129,10 @@ suite('rslint fixAll - code actions', function () {
127129
const fixableContent =
128130
"const frVal: string = 'hello';\nconst frRes = (frVal as string).toUpperCase();\n";
129131
await withTmpFile(fixableContent, async (doc) => {
130-
const initialDiags = await waitForDiagnostics(doc);
132+
const initialDiags = await waitForDiagnosticsWithMessages(
133+
doc,
134+
'no-unnecessary-type-assertion',
135+
);
131136
assert.ok(initialDiags.length > 0, 'Should have initial diagnostics');
132137

133138
const fixableDiags = initialDiags.filter((d) =>
@@ -166,7 +171,11 @@ suite('rslint fixAll - code actions', function () {
166171
'',
167172
].join('\n');
168173
await withTmpFile(mixedContent, async (doc) => {
169-
const initialDiags = await waitForDiagnostics(doc);
174+
const initialDiags = await waitForDiagnosticsWithMessages(
175+
doc,
176+
'no-unnecessary-type-assertion',
177+
'no-unsafe',
178+
);
170179
assert.ok(initialDiags.length > 0, 'Should have diagnostics');
171180

172181
const fixableBefore = initialDiags.filter((d) =>
@@ -248,7 +257,10 @@ suite('rslint fixAll - code actions', function () {
248257
const fixableContent =
249258
"const sfVal: string = 'x';\nconst sfRes = (sfVal as string).trim();\n";
250259
await withTmpFile(fixableContent, async (doc) => {
251-
const initialDiags = await waitForDiagnostics(doc);
260+
const initialDiags = await waitForDiagnosticsWithMessages(
261+
doc,
262+
'no-unnecessary-type-assertion',
263+
);
252264
const fixableCount = initialDiags.filter((d) =>
253265
d.message.includes('no-unnecessary-type-assertion'),
254266
).length;

0 commit comments

Comments
 (0)