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!
This commit is contained in:
@@ -4,6 +4,7 @@ import * as sinonChai from 'sinon-chai';
|
|||||||
import * as chai from 'chai';
|
import * as chai from 'chai';
|
||||||
import * as chaiAsPromised from 'chai-as-promised';
|
import * as chaiAsPromised from 'chai-as-promised';
|
||||||
import 'chai/register-should';
|
import 'chai/register-should';
|
||||||
|
import { ExtensionContext } from 'vscode';
|
||||||
|
|
||||||
import { runTestsInDirectory } from '../index-template';
|
import { runTestsInDirectory } from '../index-template';
|
||||||
|
|
||||||
@@ -13,3 +14,19 @@ chai.use(sinonChai);
|
|||||||
export function run(): Promise<void> {
|
export function run(): Promise<void> {
|
||||||
return runTestsInDirectory(__dirname);
|
return runTestsInDirectory(__dirname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createMockExtensionContext(): ExtensionContext {
|
||||||
|
return {
|
||||||
|
globalState: {
|
||||||
|
_state: {
|
||||||
|
'telemetry-request-viewed': true
|
||||||
|
} as Record<string, any>,
|
||||||
|
get(key: string) {
|
||||||
|
return this._state[key];
|
||||||
|
},
|
||||||
|
update(key: string, val: any) {
|
||||||
|
this._state[key] = val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} as any;
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { TelemetryListener, telemetryListener as globalTelemetryListener } from
|
|||||||
import { UserCancellationException } from '../../commandRunner';
|
import { UserCancellationException } from '../../commandRunner';
|
||||||
import { fail } from 'assert';
|
import { fail } from 'assert';
|
||||||
import { ENABLE_TELEMETRY } from '../../config';
|
import { ENABLE_TELEMETRY } from '../../config';
|
||||||
|
import { createMockExtensionContext } from './index';
|
||||||
|
|
||||||
const sandbox = sinon.createSandbox();
|
const sandbox = sinon.createSandbox();
|
||||||
|
|
||||||
@@ -339,22 +340,6 @@ describe('telemetry reporting', function() {
|
|||||||
expect(window.showInformationMessage).to.have.been.calledOnce;
|
expect(window.showInformationMessage).to.have.been.calledOnce;
|
||||||
});
|
});
|
||||||
|
|
||||||
function createMockExtensionContext(): ExtensionContext {
|
|
||||||
return {
|
|
||||||
globalState: {
|
|
||||||
_state: {
|
|
||||||
'telemetry-request-viewed': true
|
|
||||||
} as Record<string, any>,
|
|
||||||
get(key: string) {
|
|
||||||
return this._state[key];
|
|
||||||
},
|
|
||||||
update(key: string, val: any) {
|
|
||||||
this._state[key] = val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} as any;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function enableTelemetry(section: string, value: boolean | undefined) {
|
async function enableTelemetry(section: string, value: boolean | undefined) {
|
||||||
await workspace.getConfiguration(section).update(
|
await workspace.getConfiguration(section).update(
|
||||||
'enableTelemetry', value, ConfigurationTarget.Global
|
'enableTelemetry', value, ConfigurationTarget.Global
|
||||||
|
|||||||
Reference in New Issue
Block a user