import * as fs from 'fs' ; import * as vscode from 'vscode' ; import sinon = require ( 'sinon' ) ; export function stubConfig ( config ) { return sinon . stub ( vscode . workspace , 'getConfiguration' ) . withArgs ( 'remoteX11' ) . returns ( new StubConfiguration ( config ) ) ; } export function stubRemoteName ( name ) { return sinon . stub ( vscode . env , 'remoteName' ) . get ( ( ) => name ) ; } export class StubConfiguration implements vscode . WorkspaceConfiguration { constructor ( private config ) { } get < T > ( section ) ; get < T > ( section , defaultValue ) ; get ( section , defaultValue ? ) { return this . config [ section ] ?? defaultValue ; } has ( section ) { return section in this . config ; } inspect ( _section ) { throw new Error ( 'Method not implemented.' ) ; } update ( _section , _value , _configurationTarget ? , _overrideInLanguage ? ) { throw new Error ( 'Method not implemented.' ) ; } } export function stubWslVersion ( version ) { const stub = sinon . stub ( fs . promises , 'access' ) . withArgs ( '/run/WSL' ) ; if ( version === 1 ) { stub . rejects ( ) ; } else { stub . resolves ( ) ; } return stub ; } /**
 * Stubs fs.promises.readFile to return given text.
 */ export function stubFile ( path , options , text ) { return sinon . stub ( fs . promises , 'readFile' ) . withArgs ( path , options ) . resolves ( text ) ; }