33 ConfigurationTarget ,
44 workspace ,
55 WorkspaceConfiguration as VSCodeWorkspaceConfiguration ,
6+ Uri ,
67} from "vscode" ;
78import { readFileSync } from "fs-extra" ;
89import { join } from "path" ;
@@ -151,14 +152,40 @@ const packageConfiguration: Record<
151152 const pkg = JSON . parse (
152153 readFileSync ( join ( __dirname , "../../package.json" ) , "utf-8" ) ,
153154 ) ;
154- return pkg . contributes . configuration . properties ;
155+ return {
156+ ...pkg . contributes . configuration . properties ,
157+ // `debug.saveBeforeStart` is a core VS Code setting, but we depend on its value in these tests.
158+ // We'll set it here to the value that we expect.
159+ "debug.saveBeforeStart" : {
160+ default : "nonUntitledEditorsInActiveGroup" ,
161+ } ,
162+ } ;
155163} ) ( ) ;
156164
157165export const vsCodeGetConfiguration = workspace . getConfiguration ;
158166export let vscodeGetConfigurationMock : jest . SpiedFunction <
159167 typeof workspace . getConfiguration
160168> ;
161169
170+ function acceptScope ( scope : ConfigurationScope | null | undefined ) : boolean {
171+ if ( ! scope ) {
172+ return true ;
173+ }
174+
175+ if ( scope instanceof Uri ) {
176+ return false ;
177+ }
178+
179+ // Reject any scope that has a URI property. That covers `WorkspaceFolder`, `TextDocument`, and any
180+ if ( scope . uri !== undefined ) {
181+ return false ;
182+ }
183+
184+ // We're left with only `{ languageId }` scopes. We'll ignore the language, since it doesn't matter
185+ // for our tests.
186+ return true ;
187+ }
188+
162189export const beforeEachAction = async ( ) => {
163190 const defaultConfiguration = new DefaultConfiguration ( packageConfiguration ) ;
164191
@@ -176,7 +203,7 @@ export const beforeEachAction = async () => {
176203 section ?: string ,
177204 scope ?: ConfigurationScope | null ,
178205 ) : VSCodeWorkspaceConfiguration => {
179- if ( scope ) {
206+ if ( ! acceptScope ( scope ) ) {
180207 throw new Error ( "Scope is not supported in tests" ) ;
181208 }
182209
0 commit comments