Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartik Raj committed May 12, 2022
1 parent b1ea20a commit c767c5a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
15 changes: 8 additions & 7 deletions src/test/interpreters/display/progressDisplay.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { createDeferred, Deferred } from '../../../client/common/utils/async';
import { Interpreters } from '../../../client/common/utils/localize';
import { IComponentAdapter } from '../../../client/interpreter/contracts';
import { InterpreterLocatorProgressStatubarHandler } from '../../../client/interpreter/display/progressDisplay';
import { ProgressNotificationEvent, ProgressReportStage } from '../../../client/pythonEnvironments/base/locator';
import { noop } from '../../core';

type ProgressTask<R> = (
Expand All @@ -20,18 +21,18 @@ type ProgressTask<R> = (
) => Thenable<R>;

suite('Interpreters - Display Progress', () => {
let refreshingCallback: (e: void) => unknown | undefined;
let refreshingCallback: (e: ProgressNotificationEvent) => unknown | undefined;
let refreshDeferred: Deferred<void>;
let componentAdapter: IComponentAdapter;
setup(() => {
refreshDeferred = createDeferred<void>();
componentAdapter = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onRefreshStart(listener: (e: void) => any): Disposable {
onProgress(listener: (e: ProgressNotificationEvent) => any): Disposable {
refreshingCallback = listener;
return { dispose: noop };
},
refreshPromise: refreshDeferred.promise,
getRefreshPromise: () => refreshDeferred.promise,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any;
});
Expand All @@ -44,7 +45,7 @@ suite('Interpreters - Display Progress', () => {
when(shell.withProgress(anything(), anything())).thenResolve();

await statusBar.activate();
refreshingCallback(undefined);
refreshingCallback({ stage: ProgressReportStage.discoveryStarted });

const options = capture(shell.withProgress as never).last()[0] as ProgressOptions;
expect(options.title).to.be.equal(`[${Interpreters.discovering}](command:${Commands.Set_Interpreter})`);
Expand All @@ -56,12 +57,12 @@ suite('Interpreters - Display Progress', () => {
when(shell.withProgress(anything(), anything())).thenResolve();

await statusBar.activate();
refreshingCallback(undefined);
refreshingCallback({ stage: ProgressReportStage.discoveryStarted });

let options = capture(shell.withProgress as never).last()[0] as ProgressOptions;
expect(options.title).to.be.equal(`[${Interpreters.discovering}](command:${Commands.Set_Interpreter})`);

refreshingCallback(undefined);
refreshingCallback({ stage: ProgressReportStage.discoveryStarted });

options = capture(shell.withProgress as never).last()[0] as ProgressOptions;
expect(options.title).to.be.equal(`[${Interpreters.refreshing}](command:${Commands.Set_Interpreter})`);
Expand All @@ -73,7 +74,7 @@ suite('Interpreters - Display Progress', () => {
when(shell.withProgress(anything(), anything())).thenResolve();

await statusBar.activate();
refreshingCallback(undefined);
refreshingCallback({ stage: ProgressReportStage.discoveryStarted });

const options = capture(shell.withProgress as never).last()[0] as ProgressOptions;
const callback = capture(shell.withProgress as never).last()[1] as ProgressTask<void>;
Expand Down
12 changes: 9 additions & 3 deletions src/test/proposedApi.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { IInterpreterPathService } from '../client/common/types';
import { IInterpreterService } from '../client/interpreter/contracts';
import { IServiceContainer } from '../client/ioc/types';
import { buildProposedApi } from '../client/proposedApi';
import { IDiscoveryAPI, ProgressNotificationEvent } from '../client/pythonEnvironments/base/locator';
import {
IDiscoveryAPI,
ProgressNotificationEvent,
ProgressReportStage,
} from '../client/pythonEnvironments/base/locator';
import { PythonEnvironment } from '../client/pythonEnvironments/info';
import { PythonEnvKind, PythonEnvSource } from '../client/pythonEnvironments/base/info';
import { Architecture } from '../client/common/utils/platform';
Expand Down Expand Up @@ -389,8 +393,10 @@ suite('Proposed Extension API', () => {

test('getRefreshPromise: common scenario', () => {
const expected = Promise.resolve();
discoverAPI.setup((d) => d.getRefreshPromise()).returns(() => expected);
const actual = proposed.environment.getRefreshPromise();
discoverAPI
.setup((d) => d.getRefreshPromise(typemoq.It.isValue({ stage: ProgressReportStage.allPathsDiscovered })))
.returns(() => expected);
const actual = proposed.environment.getRefreshPromise({ stage: ProgressReportStage.allPathsDiscovered });

// We are comparing instances here, they should be the same instance.
// So '==' is ok here.
Expand Down

0 comments on commit c767c5a

Please sign in to comment.