Skip to content

Commit

Permalink
lsp baseline test that doesnt work
Browse files Browse the repository at this point in the history
  • Loading branch information
DetachHead committed Sep 27, 2024
1 parent 54ee1a1 commit 1153548
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/pyright-internal/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* Configuration for jest tests.
*/

module.exports = {
/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
const config = {
testEnvironment: 'node',
roots: ['<rootDir>/src/tests'],
transform: {
Expand All @@ -19,3 +20,5 @@ module.exports = {
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
setupFiles: ['./src/tests/setupTests.ts'],
};

module.exports = config;
2 changes: 1 addition & 1 deletion packages/pyright-internal/src/baseline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface BaselinedDiagnostic {
range: { startColumn: number; endColumn: number };
}

interface BaselineFile {
export interface BaselineFile {
files: {
[filePath: string]: BaselinedDiagnostic[];
};
Expand Down
68 changes: 68 additions & 0 deletions packages/pyright-internal/src/tests/languageServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import {
runPyrightServer,
waitForDiagnostics,
} from './lsp/languageServerTestUtils';
import { BaselineFile } from '../baseline';
import { DiagnosticRule } from '../common/diagnosticRules';

/** objects from `sendRequest` don't work with assertions and i cant figure out why */
const assertEqual = <T>(actual: T, expected: T) => expect(JSON.parse(JSON.stringify(actual))).toStrictEqual(expected);
Expand Down Expand Up @@ -962,4 +964,70 @@ describe(`Basic language server tests`, () => {
'invalid diagnosticMode: "asdf". valid options are "workspace" or "openFilesOnly"'
);
});
describe('baseline', () => {
test('baselined error not shown', async () => {
const baseline: BaselineFile = {
files: {
'./foo.py': [
{
code: DiagnosticRule.reportAssignmentType,
range: {
startColumn: 11,
endColumn: 13,
},
},
],
},
};
const code = `
// @filename: .basedpyright/baseline.json
//// ${JSON.stringify(baseline)}
////
// @filename: foo.py
//// foo: int = ""
//// asdf
//// [|/*marker*/|]
`;
const settings = [
{
item: {
scopeUri: `file://${normalizeSlashes(DEFAULT_WORKSPACE_ROOT, '/')}`,
section: 'basedpyright.analysis',
},
value: {
diagnosticSeverityOverrides: {
reportAssignmentType: 'error',
reportUndefinedVariable: 'error',
},
},
},
];

const info = await runLanguageServer(
DEFAULT_WORKSPACE_ROOT,
code,
/* callInitialize */ true,
settings,
undefined,
/* supportsBackgroundThread */ false
);

// get the file containing the marker that also contains our task list comments
await openFile(info, 'marker');

// Wait for the diagnostics to publish
const diagnostics = await waitForDiagnostics(info);
const file = diagnostics.find((d) => d.uri.includes('test.py'));
assert(file);

// Make sure the error has a special rule
assert.equal(file.diagnostics[0].code, 'reportUnknownParameterType');

// make sure additional diagnostic severities work
assert.equal(
file.diagnostics.find((diagnostic) => diagnostic.code === 'reportUnusedFunction')?.severity,
DiagnosticSeverity.Hint // TODO: hint? how do we differentiate between unused/unreachable/deprecated?
);
});
});
});

0 comments on commit 1153548

Please sign in to comment.