-
Notifications
You must be signed in to change notification settings - Fork 79
Fix MI Welcome Page auto-opening when Test Explorer opened on non-MI project (#1371) #1960
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
Open
SasinduDilshara
wants to merge
2
commits into
main
Choose a base branch
from
fix/issue-1371
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
228 changes: 228 additions & 0 deletions
228
workspaces/mi/mi-extension/src/test/e2e-playwright-tests/nonMiProjectActivation.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'); | ||
|
|
||
| // ── 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); | ||
| } | ||
| }); | ||
| } | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Run each activation scenario in a fresh VS Code session.
initTest()installsbeforeAll/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 owndescribe/initTest(...)block or otherwise relaunching between tests.🤖 Prompt for AI Agents