Allow languageId: scopes in tests

This commit is contained in:
Dave Bartolomeo
2023-06-21 17:01:13 -04:00
parent de38b1fd20
commit 1da96c5a55
2 changed files with 43 additions and 6 deletions

View File

@@ -1,10 +1,20 @@
---
lockVersion: 1.0.0
dependencies:
codeql-javascript:
version: 0.5.1
codeql/javascript-all:
version: 0.6.3
codeql/javascript-queries:
version: 0.6.3
codeql/regex:
version: 0.0.9
version: 0.0.14
codeql/suite-helpers:
version: 0.5.3
codeql/tutorial:
version: 0.0.6
version: 0.0.11
codeql/typos:
version: 0.0.18
codeql/util:
version: 0.0.11
codeql/yaml:
version: 0.0.3
compiled: false

View File

@@ -3,6 +3,7 @@ import {
ConfigurationTarget,
workspace,
WorkspaceConfiguration as VSCodeWorkspaceConfiguration,
Uri,
} from "vscode";
import { readFileSync } from "fs-extra";
import { join } from "path";
@@ -151,7 +152,14 @@ const packageConfiguration: Record<
const pkg = JSON.parse(
readFileSync(join(__dirname, "../../package.json"), "utf-8"),
);
return pkg.contributes.configuration.properties;
return {
...pkg.contributes.configuration.properties,
// `debug.saveBeforeStart` is a core VS Code setting, but we depend on its value in these tests.
// We'll set it here to the value that we expect.
"debug.saveBeforeStart": {
default: "nonUntitledEditorsInActiveGroup",
},
};
})();
export const vsCodeGetConfiguration = workspace.getConfiguration;
@@ -159,6 +167,25 @@ export let vscodeGetConfigurationMock: jest.SpiedFunction<
typeof workspace.getConfiguration
>;
function acceptScope(scope: ConfigurationScope | null | undefined): boolean {
if (!scope) {
return true;
}
if (scope instanceof Uri) {
return false;
}
// Reject any scope that has a URI property. That covers `WorkspaceFolder`, `TextDocument`, and any
if (scope.uri !== undefined) {
return false;
}
// We're left with only `{ languageId }` scopes. We'll ignore the language, since it doesn't matter
// for our tests.
return true;
}
export const beforeEachAction = async () => {
const defaultConfiguration = new DefaultConfiguration(packageConfiguration);
@@ -176,7 +203,7 @@ export const beforeEachAction = async () => {
section?: string,
scope?: ConfigurationScope | null,
): VSCodeWorkspaceConfiguration => {
if (scope) {
if (!acceptScope(scope)) {
throw new Error("Scope is not supported in tests");
}