Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vscode/e2e/lint/fixtures/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"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.",
"dependencies": {
"@rslint/core": "^0.8.0",
"@rslint/core": "^0.8.1",
"jiti": "^2.7.0"
}
}
10 changes: 7 additions & 3 deletions packages/vscode/e2e/lint/suite/fixall-error.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Ported verbatim from web-infra-dev/rslint
// Ported from web-infra-dev/rslint (deviation: setup waits go through
// waitForDiagnosticsWithMessages -- see fixall-helpers.ts for why).
// `packages/vscode-extension/__tests__/suite/fixall-error.test.ts` (origin/main).
import * as assert from 'assert';
import * as vscode from 'vscode';
import {
waitForDiagnostics,
waitForDiagnosticsWithMessages,
waitForContentChange,
findFixAllAction,
requestFixAll,
Expand Down Expand Up @@ -57,7 +58,10 @@ suite('rslint fixAll - error flows', function () {
editor,
"const pVal: string = 'x';\nconst pRes = (pVal as string).trim();\n",
);
const probeDiags = await waitForDiagnostics(doc);
const probeDiags = await waitForDiagnosticsWithMessages(
doc,
'no-unnecessary-type-assertion',
);
assert.ok(
probeDiags.some((d) =>
d.message.includes('no-unnecessary-type-assertion'),
Expand Down
23 changes: 23 additions & 0 deletions packages/vscode/e2e/lint/suite/fixall-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,29 @@ import { waitForCodeActionRegistryQuiescence } from '../utils/codeActionRegistry
export { saveDocumentOnce } from '../utils/codeActionRegistry';

export const waitForDiagnostics = waitForRslintDiagnostics;

/**
* Wait until the rslint diagnostics for `doc` include every given message
* substring.
*
* Deviation from the upstream suites, which assert on the first non-empty
* publish: 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). Waiting for the expected diagnostics keeps
* the terminal assertion identical without depending on publish batching.
*/
export function waitForDiagnosticsWithMessages(
doc: vscode.TextDocument,
...messages: string[]
): Promise<vscode.Diagnostic[]> {
return waitForRslintDiagnostics(doc, (diagnostics) =>
messages.every((message) =>
diagnostics.some((diagnostic) => diagnostic.message.includes(message)),
),
);
}
export const waitForDiagnosticsCount = waitForRslintDiagnosticsCount;
export const waitForDiagnosticsToChange = waitForRslintDiagnosticsToChange;

Expand Down
24 changes: 19 additions & 5 deletions packages/vscode/e2e/lint/suite/fixall-onsave.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Ported verbatim from web-infra-dev/rslint
// Ported from web-infra-dev/rslint (deviation: setup waits go through
// waitForDiagnosticsWithMessages -- see fixall-helpers.ts for why).
// `packages/vscode-extension/__tests__/suite/fixall-onsave.test.ts` (origin/main).
import * as assert from 'assert';
import * as vscode from 'vscode';
import { getRslintDiagnostics } from '../utils/diagnostics';
import { waitForCodeActionRegistryQuiescence } from '../utils/codeActionRegistry';
import {
waitForDiagnostics,
waitForDiagnosticsWithMessages,
waitForDiagnosticsCount,
waitForContentChange,
withOnSaveFixAll,
Expand Down Expand Up @@ -38,7 +40,10 @@ suite('rslint fixAll - on-save', function () {
"const gfVal: string = 'x';\nconst gfRes = (gfVal as string).trim();\n",
);

const diags = await waitForDiagnostics(doc);
const diags = await waitForDiagnosticsWithMessages(
doc,
'no-unnecessary-type-assertion',
);
assertHasFixableDiagnostic(diags, 'generic source.fixAll setup');

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

const diags = await waitForDiagnostics(doc);
const diags = await waitForDiagnosticsWithMessages(
doc,
'no-unnecessary-type-assertion',
);
assertHasFixableDiagnostic(diags, 'fixable on-save setup');

await saveDocumentOnce(doc, 'Fixable document should save');
Expand All @@ -93,7 +101,10 @@ suite('rslint fixAll - on-save', function () {
editor,
"const probeVal: string = 'x';\nconst probeRes = (probeVal as string).trim();\n",
);
const probeDiags = await waitForDiagnostics(doc);
const probeDiags = await waitForDiagnosticsWithMessages(
doc,
'no-unnecessary-type-assertion',
);
assertHasFixableDiagnostic(probeDiags, 'clean-file probe setup');
await saveDocumentOnce(doc, 'Clean-file probe should save');
await waitForContentChange(
Expand Down Expand Up @@ -130,7 +141,10 @@ suite('rslint fixAll - on-save', function () {
editor,
"const probeVal2: string = 'x';\nconst probeRes2 = (probeVal2 as string).trim();\n",
);
const probeDiags = await waitForDiagnostics(doc);
const probeDiags = await waitForDiagnosticsWithMessages(
doc,
'no-unnecessary-type-assertion',
);
assertHasFixableDiagnostic(probeDiags, 'non-fixable probe setup');
await saveDocumentOnce(doc, 'Non-fixable probe should save');
await waitForContentChange(
Expand Down
20 changes: 16 additions & 4 deletions packages/vscode/e2e/lint/suite/fixall.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Ported verbatim from web-infra-dev/rslint
// Ported from web-infra-dev/rslint (deviation: setup waits go through
// waitForDiagnosticsWithMessages -- see fixall-helpers.ts for why).
// `packages/vscode-extension/__tests__/suite/fixall.test.ts` (origin/main).
import * as assert from 'assert';
import * as vscode from 'vscode';
import {
waitForDiagnostics,
waitForDiagnosticsWithMessages,
waitForDiagnosticsToChange,
waitForDiagnosticsCount,
openFixture,
Expand Down Expand Up @@ -127,7 +129,10 @@ suite('rslint fixAll - code actions', function () {
const fixableContent =
"const frVal: string = 'hello';\nconst frRes = (frVal as string).toUpperCase();\n";
await withTmpFile(fixableContent, async (doc) => {
const initialDiags = await waitForDiagnostics(doc);
const initialDiags = await waitForDiagnosticsWithMessages(
doc,
'no-unnecessary-type-assertion',
);
assert.ok(initialDiags.length > 0, 'Should have initial diagnostics');

const fixableDiags = initialDiags.filter((d) =>
Expand Down Expand Up @@ -166,7 +171,11 @@ suite('rslint fixAll - code actions', function () {
'',
].join('\n');
await withTmpFile(mixedContent, async (doc) => {
const initialDiags = await waitForDiagnostics(doc);
const initialDiags = await waitForDiagnosticsWithMessages(
doc,
'no-unnecessary-type-assertion',
'no-unsafe',
);
assert.ok(initialDiags.length > 0, 'Should have diagnostics');

const fixableBefore = initialDiags.filter((d) =>
Expand Down Expand Up @@ -248,7 +257,10 @@ suite('rslint fixAll - code actions', function () {
const fixableContent =
"const sfVal: string = 'x';\nconst sfRes = (sfVal as string).trim();\n";
await withTmpFile(fixableContent, async (doc) => {
const initialDiags = await waitForDiagnostics(doc);
const initialDiags = await waitForDiagnosticsWithMessages(
doc,
'no-unnecessary-type-assertion',
);
const fixableCount = initialDiags.filter((d) =>
d.message.includes('no-unnecessary-type-assertion'),
).length;
Expand Down