Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full integration with test pane #67

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "commonjs",
"displayName": "SweetPad (iOS/Swift development)",
"description": "Develop Swift/iOS projects in VS Code",
"version": "0.1.41",
"version": "0.1.42-beta",
"publisher": "sweetpad",
"icon": "images/logo.png",
"license": "MIT",
Expand Down Expand Up @@ -285,11 +285,6 @@
"title": "SweetPad: Clean",
"icon": "$(clear-all)"
},
{
"command": "sweetpad.build.test",
"title": "SweetPad: Test",
"icon": "$(beaker)"
},
{
"command": "sweetpad.build.resolveDependencies",
"title": "SweetPad: Resolve dependencies",
Expand All @@ -310,6 +305,11 @@
"title": "SweetPad: Select testing target",
"icon": "$(file-code)"
},
{
"command": "sweetpad.testing.test",
"title": "SweetPad: Test",
"icon": "$(beaker)"
},
{
"command": "sweetpad.testing.buildForTesting",
"title": "SweetPad: Build for testing (without running tests)",
Expand Down
37 changes: 0 additions & 37 deletions src/build/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,43 +522,6 @@ export async function cleanCommand(execution: CommandExecution, item?: BuildTree
});
}

export async function testCommand(execution: CommandExecution, item?: BuildTreeItem) {
const xcworkspace = await askXcodeWorkspacePath(execution.context);
const scheme =
item?.scheme ??
(await askSchemeForBuild(execution.context, { title: "Select scheme to test", xcworkspace: xcworkspace }));
const configuration = await askConfiguration(execution.context, { xcworkspace: xcworkspace });

const buildSettings = await getBuildSettings({
scheme: scheme,
configuration: configuration,
sdk: undefined,
xcworkspace: xcworkspace,
});

const destination = await askDestinationToRunOn(execution.context, buildSettings);
const destinationRaw = getXcodeBuildDestinationString({ destination: destination });

const sdk = destination.platform;

await runTask(execution.context, {
name: "Test",
problemMatchers: DEFAULT_BUILD_PROBLEM_MATCHERS,
callback: async (terminal) => {
await buildApp(execution.context, terminal, {
scheme: scheme,
sdk: sdk,
configuration: configuration,
shouldBuild: false,
shouldClean: false,
shouldTest: true,
xcworkspace: xcworkspace,
destinationRaw: destinationRaw,
});
},
});
}

export async function resolveDependencies(context: ExtensionContext, options: { scheme: string; xcworkspace: string }) {
await runTask(context, {
name: "Resolve Dependencies",
Expand Down
6 changes: 3 additions & 3 deletions src/common/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ type WorkspaceStateKey = keyof WorkspaceTypes;
type SessionStateKey = "NONE_KEY";

export class ExtensionContext {
private _context: vscode.ExtensionContext;
private readonly _context: vscode.ExtensionContext;
public destinationsManager: DestinationsManager;
public toolsManager: ToolsManager;
public buildManager: BuildManager;
public testingManager: TestingManager;
private _sessionState: Map<SessionStateKey, unknown> = new Map();
private readonly _sessionState: Map<SessionStateKey, unknown> = new Map();

constructor(options: {
context: vscode.ExtensionContext;
Expand Down Expand Up @@ -75,7 +75,7 @@ export class ExtensionContext {
/**
* State local to the running instance of the extension. It is not persisted across sessions.
*/
updateSessionState(key: SessionStateKey, value: unknown | undefined) {
updateSessionState(key: SessionStateKey, value?: unknown) {
this._sessionState.set(key, value);
}

Expand Down
9 changes: 6 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import {
resolveDependenciesCommand,
runCommand,
selectXcodeSchemeForBuildCommand,
testCommand,
selectXcodeWorkspaceCommand,
} from "./build/commands.js";
import { selectXcodeWorkspaceCommand } from "./build/commands.js";
import { BuildManager } from "./build/manager.js";
import { XcodeBuildTaskProvider } from "./build/provider.js";
import { DefaultSchemeStatusBar } from "./build/status-bar.js";
Expand Down Expand Up @@ -47,6 +46,7 @@ import {
selectTestingTargetCommand,
selectXcodeSchemeForTestingCommand,
testWithoutBuildingCommand,
testBuildingCommand
} from "./testing/commands.js";
import { TestingManager } from "./testing/manager.js";
import { installToolCommand, openDocumentationCommand } from "./tools/commands.js";
Expand Down Expand Up @@ -93,6 +93,9 @@ export function activate(context: vscode.ExtensionContext) {
destinationsManager.context = _context;
testingManager.context = _context;

// Load initial data after setting the context 🚀
testingManager.loadTestsFromDefaultScheme();

// Trees 🎄
const buildTreeProvider = new BuildTreeProvider({
context: _context,
Expand Down Expand Up @@ -130,7 +133,6 @@ export function activate(context: vscode.ExtensionContext) {
d(command("sweetpad.build.run", runCommand));
d(command("sweetpad.build.build", buildCommand));
d(command("sweetpad.build.clean", cleanCommand));
d(command("sweetpad.build.test", testCommand));
d(command("sweetpad.build.resolveDependencies", resolveDependenciesCommand));
d(command("sweetpad.build.removeBundleDir", removeBundleDirCommand));
d(command("sweetpad.build.genereateBuildServerConfig", generateBuildServerConfigCommand));
Expand All @@ -139,6 +141,7 @@ export function activate(context: vscode.ExtensionContext) {
d(command("sweetpad.build.setDefaultScheme", selectXcodeSchemeForBuildCommand));

// Testing
d(command("sweetpad.testing.test", testBuildingCommand));
d(command("sweetpad.testing.buildForTesting", buildForTestingCommand));
d(command("sweetpad.testing.testWithoutBuilding", testWithoutBuildingCommand));
d(command("sweetpad.testing.selectTarget", selectTestingTargetCommand));
Expand Down
15 changes: 14 additions & 1 deletion src/testing/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,25 @@ export async function buildForTestingCommand(execution: CommandExecution): Promi
return await execution.context.testingManager.buildForTestingCommand();
}

export async function testBuildingCommand(
execution: CommandExecution,
...items: vscode.TestItem[]
): Promise<void> {
const actualItems = items.length ? items : [...execution.context.testingManager.controller.items].map(([, item]) => item);
const request = new vscode.TestRunRequest(actualItems, [], undefined, undefined);
const tokenSource = new vscode.CancellationTokenSource();

execution.context.testingManager.buildAndRunTests(request, tokenSource.token);
}

export async function testWithoutBuildingCommand(
execution: CommandExecution,
...items: vscode.TestItem[]
): Promise<void> {
const request = new vscode.TestRunRequest(items, [], undefined, undefined);
const actualItems = items.length ? items : [...execution.context.testingManager.controller.items].map(([, item]) => item);
const request = new vscode.TestRunRequest(actualItems, [], undefined, undefined);
const tokenSource = new vscode.CancellationTokenSource();

execution.context.testingManager.runTestsWithoutBuilding(request, tokenSource.token);
}

Expand Down
Loading