mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-15 11:51:30 +00:00
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
This commit is contained in:
@@ -1 +1,2 @@
|
||||
BRUNO_INFO_ENDPOINT = http://localhost:8081
|
||||
BRUNO_INFO_ENDPOINT = http://localhost:8081
|
||||
DISABLE_SAMPLE_COLLECTION_IMPORT = false
|
||||
@@ -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);
|
||||
|
||||
@@ -15,9 +15,9 @@ export const test = baseTest.extend<
|
||||
},
|
||||
{
|
||||
createTmpDir: (tag?: string) => Promise<string>;
|
||||
launchElectronApp: (options?: { initUserDataPath?: string; userDataPath?: string }) => Promise<ElectronApplication>;
|
||||
launchElectronApp: (options?: { initUserDataPath?: string; userDataPath?: string; dotEnv?: Record<string, string> }) => Promise<ElectronApplication>;
|
||||
electronApp: ElectronApplication;
|
||||
reuseOrLaunchElectronApp: (options?: { initUserDataPath?: string; userDataPath?: string }) => Promise<ElectronApplication>;
|
||||
reuseOrLaunchElectronApp: (options?: { initUserDataPath?: string; userDataPath?: string; dotEnv?: Record<string, string> }) => Promise<ElectronApplication>;
|
||||
}
|
||||
>({
|
||||
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<string, ElectronApplication> = {};
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user