From fb2ca8937efd9e1515cfb3595e25fc27525a6be4 Mon Sep 17 00:00:00 2001 From: Sanjai Kumar <161328623+sanjaikumar-bruno@users.noreply.github.com> Date: Wed, 17 Sep 2025 13:57:10 +0530 Subject: [PATCH] feat: add environment variable DISABLE_SAMPLE_COLLECTION_IMPORT to control sample collection import behavior (#5567) * feat: add environment variable DISABLE_SAMPLE_COLLECTION_IMPORT to control sample collection import behavior --- packages/bruno-electron/.env.sample | 3 ++- packages/bruno-electron/src/app/onboarding.js | 19 +++++++++++-------- playwright/index.ts | 14 ++++++++------ tests/onboarding/sample-collection.spec.ts | 19 +++++++++++++------ 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/packages/bruno-electron/.env.sample b/packages/bruno-electron/.env.sample index b75f94661..b2d42d055 100644 --- a/packages/bruno-electron/.env.sample +++ b/packages/bruno-electron/.env.sample @@ -1 +1,2 @@ -BRUNO_INFO_ENDPOINT = http://localhost:8081 \ No newline at end of file +BRUNO_INFO_ENDPOINT = http://localhost:8081 +DISABLE_SAMPLE_COLLECTION_IMPORT = false \ No newline at end of file diff --git a/packages/bruno-electron/src/app/onboarding.js b/packages/bruno-electron/src/app/onboarding.js index 082d465f1..05ebe4d4b 100644 --- a/packages/bruno-electron/src/app/onboarding.js +++ b/packages/bruno-electron/src/app/onboarding.js @@ -76,16 +76,19 @@ async function onboardUser(mainWindow, lastOpenedCollections) { return; } - // Onboarding was added later; - // if a collection already exists, user is old → skip onboarding - const collections = await lastOpenedCollections.getAll(); - if (collections.length > 0) { - preferencesUtil.markAsLaunched(); - return; + if (process.env.DISABLE_SAMPLE_COLLECTION_IMPORT !== 'true') { + // Onboarding was added later; + // if a collection already exists, user is old → skip onboarding + const collections = await lastOpenedCollections.getAll(); + if (collections.length > 0) { + preferencesUtil.markAsLaunched(); + return; + } + + const collectionLocation = getDefaultCollectionLocation(); + await importSampleCollection(collectionLocation, mainWindow, lastOpenedCollections); } - const collectionLocation = getDefaultCollectionLocation(); - await importSampleCollection(collectionLocation, mainWindow, lastOpenedCollections); preferencesUtil.markAsLaunched(); } catch (error) { console.error('Failed to handle onboarding:', error); diff --git a/playwright/index.ts b/playwright/index.ts index bca567793..8b476ac55 100644 --- a/playwright/index.ts +++ b/playwright/index.ts @@ -15,9 +15,9 @@ export const test = baseTest.extend< }, { createTmpDir: (tag?: string) => Promise; - launchElectronApp: (options?: { initUserDataPath?: string; userDataPath?: string }) => Promise; + launchElectronApp: (options?: { initUserDataPath?: string; userDataPath?: string; dotEnv?: Record }) => Promise; electronApp: ElectronApplication; - reuseOrLaunchElectronApp: (options?: { initUserDataPath?: string; userDataPath?: string }) => Promise; + reuseOrLaunchElectronApp: (options?: { initUserDataPath?: string; userDataPath?: string; dotEnv?: Record }) => Promise; } >({ createTmpDir: [ @@ -38,7 +38,7 @@ export const test = baseTest.extend< launchElectronApp: [ async ({ playwright, createTmpDir }, use, workerInfo) => { const apps: ElectronApplication[] = []; - await use(async ({ initUserDataPath, userDataPath: providedUserDataPath } = {}) => { + await use(async ({ initUserDataPath, userDataPath: providedUserDataPath, dotEnv = {} } = {}) => { const userDataPath = providedUserDataPath || (await createTmpDir('electron-userdata')); // Ensure dir exists when caller supplies their own path @@ -68,7 +68,9 @@ export const test = baseTest.extend< args: [electronAppPath], env: { ...process.env, - ELECTRON_USER_DATA_PATH: userDataPath + ELECTRON_USER_DATA_PATH: userDataPath, + DISABLE_SAMPLE_COLLECTION_IMPORT: 'true', + ...dotEnv } }); @@ -148,12 +150,12 @@ export const test = baseTest.extend< reuseOrLaunchElectronApp: [ async ({ launchElectronApp }, use, testInfo) => { const apps: Record = {}; - await use(async ({ initUserDataPath, userDataPath } = {}) => { + await use(async ({ initUserDataPath, userDataPath, dotEnv = {} } = {}) => { const key = userDataPath || initUserDataPath; if (key && apps[key]) { return apps[key]; } - const app = await launchElectronApp({ initUserDataPath, userDataPath }); + const app = await launchElectronApp({ initUserDataPath, userDataPath, dotEnv }); if (key) { apps[key] = app; } diff --git a/tests/onboarding/sample-collection.spec.ts b/tests/onboarding/sample-collection.spec.ts index 9473ebff2..a229676a4 100644 --- a/tests/onboarding/sample-collection.spec.ts +++ b/tests/onboarding/sample-collection.spec.ts @@ -1,10 +1,16 @@ +import path from 'path'; import { test, expect, errors } from '../../playwright'; +const env = { + DISABLE_SAMPLE_COLLECTION_IMPORT: 'false' +}; + test.describe('Onboarding', () => { test('should create sample collection on first launch', async ({ launchElectronApp, createTmpDir }) => { + // Use a fresh app instance to avoid contamination from previous tests const userDataPath = await createTmpDir('onboarding-fresh'); - const app = await launchElectronApp({ userDataPath }); + const app = await launchElectronApp({ userDataPath, dotEnv: env }); const page = await app.firstWindow(); // Verify sample collection appears in sidebar @@ -32,7 +38,7 @@ test.describe('Onboarding', () => { test('should not create duplicate collections on subsequent launches', async ({ launchElectronApp, createTmpDir }) => { // Use a fresh app instance to avoid contamination from previous tests const userDataPath = await createTmpDir('duplicate-collections'); - const app = await launchElectronApp({ userDataPath }); + const app = await launchElectronApp({ userDataPath, dotEnv: env }); const page = await app.firstWindow(); // First launch - verify sample collection is created @@ -55,7 +61,7 @@ test.describe('Onboarding', () => { await app.close(); // Restart app - should not create sample collection again - const newApp = await launchElectronApp({ userDataPath }); + const newApp = await launchElectronApp({ userDataPath, dotEnv: env }); const newPage = await newApp.firstWindow(); // Verify only one sample collection exists @@ -77,7 +83,7 @@ test.describe('Onboarding', () => { test('should not recreate sample collection after user deletes it', async ({ launchElectronApp, reuseOrLaunchElectronApp, createTmpDir }) => { const userDataPath = await createTmpDir('first-launch'); - const app = await launchElectronApp({ userDataPath }); + const app = await launchElectronApp({ userDataPath, dotEnv: env }); const page = await app.firstWindow(); // First launch - sample collection should be created @@ -101,7 +107,7 @@ test.describe('Onboarding', () => { await expect(sampleCollection).not.toBeVisible(); // Restart app - sample collection should NOT be recreated - const newApp = await reuseOrLaunchElectronApp({ userDataPath }); + const newApp = await reuseOrLaunchElectronApp({ userDataPath, dotEnv: env }); const newPage = await newApp.firstWindow(); // Wait for the app to be loaded / onboarding to be completed @@ -119,7 +125,8 @@ test.describe('Onboarding', () => { // This test simulates old users who already have a collection opened const brunoTestbench = page.locator('#sidebar-collection-name').getByText('bruno-testbench'); await expect(brunoTestbench).toBeVisible(); - + + // Verify no sample collection was created since user already has collections const sampleCollection = page.locator('#sidebar-collection-name').getByText('Sample API Collection'); await expect(sampleCollection).not.toBeVisible(); });