|
| 1 | +// The opened workspace folder is `packages/app`; the fixture's only |
| 2 | +// `rslint.config.*` sits two levels above it. The rslint CLI and its Go server |
| 3 | +// walk up to the filesystem root for a config, so native lint detection must |
| 4 | +// light this folder, and its ancestor watchers must keep that decision fresh. |
| 5 | +import * as vscode from 'vscode'; |
| 6 | +import path from 'node:path'; |
| 7 | +import fs from 'node:fs'; |
| 8 | +import { |
| 9 | + diagnosticRuleIdIncludes, |
| 10 | + waitForRslintDiagnostics as waitForDiagnostics, |
| 11 | +} from '../utils/diagnostics'; |
| 12 | +import { waitForLintStackRegistration } from '../utils/extension'; |
| 13 | + |
| 14 | +function configWithNoDebugger(severity: 'error' | 'off'): string { |
| 15 | + return `export default [ |
| 16 | + { |
| 17 | + files: ['**/*.ts'], |
| 18 | + rules: { |
| 19 | + 'no-debugger': '${severity}', |
| 20 | + }, |
| 21 | + }, |
| 22 | +]; |
| 23 | +`; |
| 24 | +} |
| 25 | + |
| 26 | +suite('rslint config above the workspace folder', function () { |
| 27 | + this.timeout(120000); |
| 28 | + |
| 29 | + const folderPath = (): string => |
| 30 | + vscode.workspace.workspaceFolders![0].uri.fsPath; |
| 31 | + const rootConfigPath = (): string => |
| 32 | + path.join(folderPath(), '..', '..', 'rslint.config.mjs'); |
| 33 | + const nearerConfigPath = (): string => |
| 34 | + path.join(folderPath(), '..', 'rslint.config.mjs'); |
| 35 | + |
| 36 | + async function openIndex(): Promise<vscode.TextDocument> { |
| 37 | + const document = await vscode.workspace.openTextDocument( |
| 38 | + path.join(folderPath(), 'src', 'index.ts'), |
| 39 | + ); |
| 40 | + await vscode.window.showTextDocument(document); |
| 41 | + return document; |
| 42 | + } |
| 43 | + |
| 44 | + const hasNoDebugger = (diagnostics: vscode.Diagnostic[]): boolean => |
| 45 | + diagnostics.some((diagnostic) => |
| 46 | + diagnosticRuleIdIncludes(diagnostic, 'no-debugger'), |
| 47 | + ); |
| 48 | + |
| 49 | + teardown(async () => { |
| 50 | + fs.rmSync(nearerConfigPath(), { force: true }); |
| 51 | + fs.writeFileSync(rootConfigPath(), configWithNoDebugger('error')); |
| 52 | + await waitForLintStackRegistration(true); |
| 53 | + }); |
| 54 | + |
| 55 | + test('lints with the config above the folder and follows its edits', async () => { |
| 56 | + const document = await openIndex(); |
| 57 | + await waitForDiagnostics(document, hasNoDebugger); |
| 58 | + |
| 59 | + fs.writeFileSync(rootConfigPath(), configWithNoDebugger('off')); |
| 60 | + await waitForDiagnostics( |
| 61 | + document, |
| 62 | + (diagnostics) => !hasNoDebugger(diagnostics), |
| 63 | + ); |
| 64 | + |
| 65 | + fs.writeFileSync(rootConfigPath(), configWithNoDebugger('error')); |
| 66 | + await waitForDiagnostics(document, hasNoDebugger); |
| 67 | + }); |
| 68 | + |
| 69 | + // The live runtime keeps its key; the extension's ancestor watchers send |
| 70 | + // configRefresh, as do the Go server's own (`ancestorJSConfigFileWatchers`, |
| 71 | + // registered through the worker) once they are live. |
| 72 | + test('applies a nearer config created above the folder while linting', async () => { |
| 73 | + const document = await openIndex(); |
| 74 | + await waitForDiagnostics(document, hasNoDebugger); |
| 75 | + |
| 76 | + fs.writeFileSync(nearerConfigPath(), configWithNoDebugger('off')); |
| 77 | + await waitForDiagnostics( |
| 78 | + document, |
| 79 | + (diagnostics) => !hasNoDebugger(diagnostics), |
| 80 | + ); |
| 81 | + |
| 82 | + fs.rmSync(nearerConfigPath()); |
| 83 | + await waitForDiagnostics(document, hasNoDebugger); |
| 84 | + }); |
| 85 | + |
| 86 | + test('re-runs detection when the config above the folder is deleted or created', async () => { |
| 87 | + fs.rmSync(rootConfigPath()); |
| 88 | + await waitForLintStackRegistration(false); |
| 89 | + |
| 90 | + fs.writeFileSync(rootConfigPath(), configWithNoDebugger('error')); |
| 91 | + await waitForLintStackRegistration(true); |
| 92 | + const document = await openIndex(); |
| 93 | + await waitForDiagnostics(document, hasNoDebugger); |
| 94 | + }); |
| 95 | +}); |
0 commit comments