@@ -16,6 +16,8 @@ import * as tokenProvider from '../auth/sso/ssoAccessTokenProvider'
1616import * as testUtil from '../test/testUtil'
1717import { DeviceFlowAuthorization } from '../auth/sso/ssoAccessTokenProvider'
1818import { globals } from '../shared'
19+ import { GlobalState } from '../shared/globalState'
20+ import { FakeExtensionContext } from '../test/fakeExtensionContext'
1921
2022// ASSUMPTION: Tests are not run concurrently
2123
@@ -48,6 +50,15 @@ export async function mochaGlobalSetup(extensionId: string) {
4850 if ( getLogger ( ) instanceof ToolkitLogger ) {
4951 ; ( getLogger ( ) as ToolkitLogger ) . logToConsole ( )
5052 }
53+
54+ const fakeContext = await FakeExtensionContext . create ( )
55+ const testFolder = await testUtil . TestFolder . create ( )
56+ fakeContext . globalStorageUri = vscode . Uri . parse ( testFolder . pathFrom ( '.' ) )
57+ fakeContext . extensionPath = globals . context . extensionPath
58+ Object . assign ( globals , {
59+ // eslint-disable-next-line aws-toolkits/no-banned-usages
60+ globalState : new GlobalState ( fakeContext . globalState ) ,
61+ } )
5162 }
5263}
5364
@@ -58,9 +69,12 @@ export async function mochaGlobalTeardown(this: Mocha.Context) {
5869}
5970
6071export const mochaHooks = {
61- beforeEach ( this : Mocha . Context ) {
72+ async beforeEach ( this : Mocha . Context ) {
6273 globals . telemetry . clearRecords ( )
6374 globals . telemetry . logger . clear ( )
75+
76+ // mochaGlobalSetup() set this to a fake, so it's safe to clear it here.
77+ await globals . globalState . clear ( )
6478 } ,
6579 afterEach ( this : Mocha . Context ) {
6680 patchWindow ( )
0 commit comments