Skip to content
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
2 changes: 1 addition & 1 deletion workspaces/mi/mi-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "WSO2 Integrator: MI",
"description": "An extension which gives a development environment for designing, developing, debugging, and testing integration solutions.",
"icon": "resources/images/wso2-micro-integrator-image.png",
"version": "3.1.5",
"version": "3.1.526032514",
"publisher": "wso2",
"engines": {
"vscode": "^1.100.0"
Expand Down
2 changes: 1 addition & 1 deletion workspaces/mi/mi-extension/src/stateMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ const stateMachine = createMachine<MachineContext>({
},
newProject: {
entry: () => logDebug("State Machine: Entering 'newProject' state"),
initial: "viewLoading",
initial: "viewReady",
states: {
viewLoading: {
entry: () => logDebug("State Machine: Entering 'newProject.viewLoading' state"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
/**
* Copyright (c) 2026, WSO2 LLC. (https://www.wso2.com) All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/**
* E2E Tests for Issue #1371:
* MI Welcome Page opens when accessing VS Code Test Explorer (even for non-MI projects)
*
* These tests verify that when the MI extension activates in a workspace that
* contains no WSO2 MI artefacts (no pom.xml with integration-project type,
* no .project file), the MI Welcome Page webview panel does NOT open
* automatically — specifically not when the user opens the VS Code Test
* Explorer view.
*
* Setup:
* - VS Code is launched with a fresh, empty workspace (no pom.xml → not an MI project).
* - `initTest(true, true)` cleans `newProjectPath` and starts VS Code without
* creating an MI project, giving us a plain non-MI workspace.
*
* Run:
* pnpm run compile-tests && pnpm exec playwright test --grep "Issue #1371"
*/

import { test, expect } from '@playwright/test';
import * as path from 'path';
import * as fs from 'fs';
import { initTest, newProjectPath, page } from './Utils';

export default function createTests() {
test.describe('Issue #1371 — Non-MI Project Activation', {
tag: '@issue1371',
}, async () => {
// `newProject: true` → always start with a clean workspace directory
// `skipProjectCreation: true` → do NOT run createProject(); the workspace
// stays empty (no pom.xml) so the MI extension
// will not detect an MI project.
initTest(true, true, false, undefined, undefined, 'issue1371');

Comment on lines +43 to +52
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Run each activation scenario in a fresh VS Code session.

initTest() installs beforeAll/afterAll, so calling it once here makes both cases share the same workspace and extension instance. That means the second test no longer verifies cold activation on a non-MI Maven workspace, which weakens the regression guard for the exact bug this suite is targeting. Consider isolating each scenario in its own describe/initTest(...) block or otherwise relaunching between tests.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@workspaces/mi/mi-extension/src/test/e2e-playwright-tests/nonMiProjectActivation.spec.ts`
around lines 43 - 52, The test currently calls initTest(...) once inside
test.describe, causing shared beforeAll/afterAll and a single VS Code session;
change the structure so each activation scenario gets its own fresh session by
moving initTest(...) into separate test.describe blocks or by creating two
distinct describe() suites that each call initTest(true, true, false, ...)
independently (referencing createTests(), test.describe, and initTest) so
beforeAll/afterAll run per-scenario and the cold-activation case is exercised in
its own fresh extension/workspace.

// ── Helper: populate a minimal JS project layout ─────────────────────

async function populateNonMiWorkspace(): Promise<void> {
// Write minimal JS project files so that VS Code's built-in Testing
// view controller can register a test provider (making the Testing
// beaker icon reliably appear in the activity bar).
fs.writeFileSync(
path.join(newProjectPath, 'package.json'),
JSON.stringify({ name: 'my-js-app', version: '1.0.0', scripts: { test: 'echo "no tests"' } })
);
fs.writeFileSync(
path.join(newProjectPath, 'index.js'),
'console.log("Hello World");\n'
);
// Explicitly ensure NO pom.xml is present.
const pomPath = path.join(newProjectPath, 'pom.xml');
if (fs.existsSync(pomPath)) {
fs.unlinkSync(pomPath);
}
}

// ── Helper: collect all visible tab titles in the editor area ────────

async function getEditorTabTitles(): Promise<string[]> {
const tabLabels = page.page.locator('.tab-label');
const count = await tabLabels.count();
const titles: string[] = [];
for (let i = 0; i < count; i++) {
const title = await tabLabels.nth(i).textContent();
if (title) {
titles.push(title.trim());
}
}
return titles;
}

// ── Helper: check all webview iframes for MI Welcome content ─────────

async function miWelcomeFoundInWebviews(): Promise<boolean> {
const iframes = page.page.locator('iframe.webview');
const count = await iframes.count();
for (let i = 0; i < count; i++) {
try {
const frame = iframes.nth(i).contentFrame();
if (!frame) {
continue;
}
const welcomeLocator = frame.locator('text=Welcome to WSO2 Integrator: MI');
const welcomeCount = await welcomeLocator.count();
if (welcomeCount > 0) {
return true;
}
} catch {
// Frame might be cross-origin or not yet ready; skip it.
}
}
return false;
}

// ────────────────────────────────────────────────────────────────────

test(
'MI Welcome Page does not appear when Test Explorer is opened on a non-MI project',
async ({}, testInfo) => {
console.log(`>>> Test attempt: ${testInfo.retry + 1}`);

// Ensure the workspace is a plain JS project (no MI artefacts).
await populateNonMiWorkspace();

// ── Step 1: Open the VS Code Test Explorer ───────────────────
// The Testing view is a built-in VS Code container. Clicking its
// activity bar icon fires the implicit `onView:MI.mock-services`
// activation event (because the MI extension registers a view in
// the `test` container via package.json → contributes.views.test).
// This is exactly the trigger described in Issue #1371.
await test.step('Open VS Code Test Explorer via command palette', async () => {
console.log('Opening VS Code Test Explorer');
await page.executePaletteCommand('View: Show Testing');
// Brief wait for the view to render and for any extension
// activation triggered by revealing the Testing container.
await page.page.waitForTimeout(4000);
console.log('Test Explorer command issued; waiting for extension activation to settle');
});

// ── Step 2: Also try clicking the Testing activity bar tab ───
// In addition to the palette command, directly clicking the
// Testing beaker in the activity bar can independently fire the
// `onView` activation event.
await test.step('Click Testing activity bar tab if visible', async () => {
const testingTab = page.page.getByRole('tab', { name: 'Testing' });
const isVisible = await testingTab.isVisible().catch(() => false);
if (isVisible) {
console.log('Testing activity bar tab found; clicking it');
const tabBtn = testingTab.locator('a');
await tabBtn.click({ timeout: 5000 }).catch(() => {
console.log('Tab click timed out; continuing');
});
await page.page.waitForTimeout(3000);
} else {
console.log('Testing activity bar tab not visible in this session; skipping direct click');
}
});

// ── Step 3: Assert — no MI Welcome Page tab in editor area ───
await test.step('Assert no MI Welcome Page tab is visible in the editor', async () => {
const tabTitles = await getEditorTabTitles();
console.log('Editor tab titles found:', tabTitles);

const miWelcomeTabs = tabTitles.filter(t =>
t.includes('WSO2 Integrator: MI') ||
t.includes('Welcome to WSO2') ||
// MACHINE_VIEW.Welcome is 'WSO2 Integrator: MI'
t === 'WSO2 Integrator: MI'
);

expect(miWelcomeTabs).toHaveLength(0);
console.log('PASS: No MI Welcome Page tab found in the editor — Issue #1371 regression guard passed');
});

// ── Step 4: Assert — no MI Welcome content in any webview ────
await test.step('Assert MI Welcome Page content is absent from all webview frames', async () => {
const miWelcomeInWebview = await miWelcomeFoundInWebviews();
expect(miWelcomeInWebview).toBe(false);
console.log('PASS: No MI Welcome Page content found in any webview iframe');
});

// ── Step 5: Assert — MI status context is unknownProject ─────
// As a secondary verification, confirm the Test Explorer sidebar
// does NOT show the MI Mock Services section (which only appears
// when MI.status == 'projectLoaded').
await test.step('Assert MI Mock Services section is not visible in Test Explorer', async () => {
const mockServicesSection = page.page.locator('[aria-label*="Mock Services"]');
const count = await mockServicesSection.count();
expect(count).toBe(0);
console.log('PASS: MI Mock Services section is not visible in Test Explorer (correct for non-MI workspace)');
});
}
);

// ── Negative/edge case: non-MI Maven project ─────────────────────────

test(
'MI Welcome Page does not appear when a non-MI Maven pom.xml is present and Test Explorer opens',
async ({}, testInfo) => {
console.log(`>>> Test attempt: ${testInfo.retry + 1}`);

// Write a plain Maven pom.xml (no MI projectType).
fs.writeFileSync(
path.join(newProjectPath, 'pom.xml'),
'<project><groupId>com.example</groupId><artifactId>plain-maven-app</artifactId></project>'
);

await test.step('Open VS Code Test Explorer', async () => {
await page.executePaletteCommand('View: Show Testing');
await page.page.waitForTimeout(4000);
});

await test.step('Assert no MI Welcome Page tab appears', async () => {
const tabTitles = await getEditorTabTitles();
const miWelcomeTabs = tabTitles.filter(t =>
t.includes('WSO2 Integrator: MI') || t.includes('Welcome to WSO2')
);
expect(miWelcomeTabs).toHaveLength(0);
});

await test.step('Cleanup: remove non-MI pom.xml', async () => {
const pomPath = path.join(newProjectPath, 'pom.xml');
if (fs.existsSync(pomPath)) {
fs.unlinkSync(pomPath);
}
});
}
);
});
}

Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import overviewPageTests from './overviewPageTests/projectSettingPage.spec';
import openEntryPointArtifact from './overviewPageTests/openEntryPointArtifact.spec';
import multiWorkspaceTests from './multiWorkspaceTests/multiWorkspace.spec';
import unitTestSuitTests from './unitTestSuite.spec';
import nonMiProjectActivationTests from './nonMiProjectActivation.spec';
import { page } from './Utils';
const fs = require('fs');
const path = require('path');
Expand Down Expand Up @@ -68,6 +69,7 @@ test.describe(validateMediatorTests);
test.describe(dataMapperMediatorTests);
test.describe(unitTestSuitTests);
test.describe(dbReportMediatorTests);
test.describe(nonMiProjectActivationTests);
test.describe(artifact430Tests);

test.afterAll(async () => {
Expand Down
Loading