Skip to content

Commit

Permalink
Stub vscode 'Tests' API
Browse files Browse the repository at this point in the history
This enables the possibility to load and start plugins which
depend on the 'Tests' API.
  The 'Tests' functionality will not be operational but the rest of
the functionality offered by the plugin will be.

Signed-off-by: Alvaro Sanchez-Leon <[email protected]>
  • Loading branch information
alvsan09 committed Oct 19, 2022
1 parent 16c88a5 commit 7e753f4
Show file tree
Hide file tree
Showing 4 changed files with 756 additions and 2 deletions.
43 changes: 41 additions & 2 deletions packages/plugin-ext/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ import {
TerminalLink,
InlayHint,
InlayHintKind,
InlayHintLabelPart
InlayHintLabelPart,
TestRunProfileKind,
TestTag,
TestRunRequest,
TestMessage
} from './types-impl';
import { AuthenticationExtImpl } from './authentication-ext';
import { SymbolKind } from '../common/plugin-api-rpc-model';
Expand Down Expand Up @@ -184,6 +188,12 @@ import { ClipboardExt } from './clipboard-ext';
import { WebviewsExtImpl } from './webviews';
import { ExtHostFileSystemEventService } from './file-system-event-service-ext-impl';
import { LabelServiceExtImpl } from '../plugin/label-service';
import {
createRunProfile,
createTestRun,
testItemCollection,
createTestItem
} from './stubs/tests-api';
import { TimelineExtImpl } from './timeline';
import { ThemingExtImpl } from './theming';
import { CommentsExtImpl } from './comments';
Expand Down Expand Up @@ -792,6 +802,30 @@ export function createAPIFactory(
}
};

// Tests API (@stubbed)
// The following implementation is temporarily `@stubbed` and marked as such under `theia.d.ts`
const tests: typeof theia.tests = {
createTestController(
provider,
controllerLabel: string,
refreshHandler?: (
token: theia.CancellationToken
) => Thenable<void> | void
) {
return {
id: provider,
label: controllerLabel,
items: testItemCollection,
refreshHandler,
createRunProfile,
createTestRun,
createTestItem,
dispose: () => undefined,
};
},
};
/* End of Tests API */

const plugins: typeof theia.plugins = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
get all(): theia.Plugin<any>[] {
Expand Down Expand Up @@ -938,6 +972,7 @@ export function createAPIFactory(
debug,
tasks,
scm,
tests,
// Types
StatusBarAlignment: StatusBarAlignment,
Disposable: Disposable,
Expand Down Expand Up @@ -1061,7 +1096,11 @@ export function createAPIFactory(
InputBoxValidationSeverity,
InlayHint,
InlayHintKind,
InlayHintLabelPart
InlayHintLabelPart,
TestRunProfileKind,
TestTag,
TestRunRequest,
TestMessage
};
};
}
Expand Down
96 changes: 96 additions & 0 deletions packages/plugin-ext/src/plugin/stubs/tests-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// *****************************************************************************
// Copyright (C) 2022 Ericsson and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
// *****************************************************************************

/* tslint:disable:typedef */

import { CancellationToken } from '@theia/core/lib/common/cancellation';
import type * as theia from '@theia/plugin';

export const createRunProfile = (
label: string,
kind: theia.TestRunProfileKind,
runHandler: (
request: theia.TestRunRequest,
token: CancellationToken
) => Thenable<void> | void,
isDefault?: boolean,
tag?: theia.TestTag
) => ({
label,
kind,
isDefault: isDefault ?? false,
tag,
runHandler,
configureHandler: undefined,
dispose: () => undefined,
});

export const createTestRun = (
request: theia.TestRunRequest,
name?: string,
persist?: boolean
): theia.TestRun => ({
name,
token: CancellationToken.None,
isPersisted: false,
enqueued: (test: theia.TestItem) => undefined,
started: (test: theia.TestItem) => undefined,
skipped: (test: theia.TestItem) => undefined,
failed: (
test: theia.TestItem,
message: theia.TestMessage | readonly theia.TestMessage[],
duration?: number
) => undefined,
errored: (
test: theia.TestItem,
message: theia.TestMessage | readonly theia.TestMessage[],
duration?: number
) => undefined,
passed: (test: theia.TestItem, duration?: number) => undefined,
appendOutput: (
output: string,
location?: theia.Location,
test?: theia.TestItem
) => undefined,
end: () => undefined,
});

export const testItemCollection = {
add: () => { },
delete: () => { },
forEach: () => { },
*[Symbol.iterator]() { },
get: () => undefined,
replace: () => { },
size: 0,
};

export const createTestItem = (
id: string,
label: string,
uri?: theia.Uri
): theia.TestItem => ({
id,
label,
uri,
children: testItemCollection,
parent: undefined,
tags: [],
canResolveChildren: false,
busy: false,
range: undefined,
error: undefined,
});
36 changes: 36 additions & 0 deletions packages/plugin-ext/src/plugin/types-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2706,6 +2706,42 @@ export class LinkedEditingRanges {
}
}

export enum TestRunProfileKind {
Run = 1,
Debug = 2,
Coverage = 3,
}

@es5ClassCompat
export class TestTag implements theia.TestTag {
constructor(public readonly id: string) { }
}

@es5ClassCompat
export class TestRunRequest implements theia.TestRunRequest {
constructor(
public readonly include: theia.TestItem[] | undefined = undefined,
public readonly exclude: theia.TestItem[] | undefined = undefined,
public readonly profile: theia.TestRunProfile | undefined = undefined,
) { }
}

@es5ClassCompat
export class TestMessage implements theia.TestMessage {
public expectedOutput?: string;
public actualOutput?: string;
public location?: theia.Location;

public static diff(message: string | theia.MarkdownString, expected: string, actual: string): theia.TestMessage {
const msg = new TestMessage(message);
msg.expectedOutput = expected;
msg.actualOutput = actual;
return msg;
}

constructor(public message: string | theia.MarkdownString) { }
}

@es5ClassCompat
export class TimelineItem {
timestamp: number;
Expand Down
Loading

0 comments on commit 7e753f4

Please sign in to comment.