Skip to content

Commit c4df9db

Browse files
committed
Extract method for creating Extension context
We'd like to re-use this to test the `exportResultsToGist` method in `export-results.ts`. So let's move it to a shared folder in the `vscode-tests/no-workspace` folder. Since there's no `helper.ts` file in this folder and to avoid any confusion with the `helpers.test.ts` file, I've opted to put this shared method into `index.ts`. Happy to be told there's a better pattern for this as it doesn't feel very nice!
1 parent c384a63 commit c4df9db

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

extensions/ql-vscode/src/vscode-tests/no-workspace/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as sinonChai from 'sinon-chai';
44
import * as chai from 'chai';
55
import * as chaiAsPromised from 'chai-as-promised';
66
import 'chai/register-should';
7+
import { ExtensionContext } from 'vscode';
78

89
import { runTestsInDirectory } from '../index-template';
910

@@ -13,3 +14,19 @@ chai.use(sinonChai);
1314
export function run(): Promise<void> {
1415
return runTestsInDirectory(__dirname);
1516
}
17+
18+
export function createMockExtensionContext(): ExtensionContext {
19+
return {
20+
globalState: {
21+
_state: {
22+
'telemetry-request-viewed': true
23+
} as Record<string, any>,
24+
get(key: string) {
25+
return this._state[key];
26+
},
27+
update(key: string, val: any) {
28+
this._state[key] = val;
29+
}
30+
}
31+
} as any;
32+
}

extensions/ql-vscode/src/vscode-tests/no-workspace/telemetry.test.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { TelemetryListener, telemetryListener as globalTelemetryListener } from
66
import { UserCancellationException } from '../../commandRunner';
77
import { fail } from 'assert';
88
import { ENABLE_TELEMETRY } from '../../config';
9+
import { createMockExtensionContext } from './index';
910

1011
const sandbox = sinon.createSandbox();
1112

@@ -339,22 +340,6 @@ describe('telemetry reporting', function() {
339340
expect(window.showInformationMessage).to.have.been.calledOnce;
340341
});
341342

342-
function createMockExtensionContext(): ExtensionContext {
343-
return {
344-
globalState: {
345-
_state: {
346-
'telemetry-request-viewed': true
347-
} as Record<string, any>,
348-
get(key: string) {
349-
return this._state[key];
350-
},
351-
update(key: string, val: any) {
352-
this._state[key] = val;
353-
}
354-
}
355-
} as any;
356-
}
357-
358343
async function enableTelemetry(section: string, value: boolean | undefined) {
359344
await workspace.getConfiguration(section).update(
360345
'enableTelemetry', value, ConfigurationTarget.Global

0 commit comments

Comments
 (0)