From 099cdaf232930378c2bc761dfb729be914eb7ff7 Mon Sep 17 00:00:00 2001 From: Bijin A B Date: Sun, 21 Jun 2026 15:07:12 +0530 Subject: [PATCH] test(preferences): set default preferences values to be overriden by tests with custom preferences (#8321) --- playwright/index.ts | 34 +++++++++++++------ .../init-user-data-existing/preferences.json | 3 +- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/playwright/index.ts b/playwright/index.ts index 938f5d3ed..ddcb48de6 100644 --- a/playwright/index.ts +++ b/playwright/index.ts @@ -1,4 +1,5 @@ import { test as baseTest, BrowserContext, ElectronApplication, Page, TestInfo } from '@playwright/test'; +import { merge } from 'lodash-es'; import * as path from 'path'; import * as os from 'os'; import * as fs from 'fs'; @@ -6,6 +7,25 @@ import { version } from '../packages/bruno-app/package.json'; const electronAppPath = path.join(__dirname, '../packages/bruno-electron'); +const PREFERENCES_FILE = 'preferences.json'; + +/** + * Default preferences for the app - preferences.json file. + * This is overridden by the init-user-data/preferences.json file if it exists. + * + * Uses lodash/merge to merge the default preferences with the init-user-data/preferences.json file. + * - Note: arrays are merged by index, not concatenated. (e.g. lastOpenedCollections, lastOpenedWorkspaces, etc.) + */ +const defaultPreferences = { + preferences: { + onboarding: { + hasLaunchedBefore: true, + hasSeenWelcomeModal: true, + lastSeenVersion: version + } + } +}; + const existsAsync = (filepath: string) => fs.promises.access(filepath).then(() => true).catch(() => false); async function recursiveCopy(src: string, dest: string) { @@ -238,24 +258,18 @@ export const test = baseTest.extend< throw new Error(`\tNo replacement for {{${key}}} in ${path.join(initUserDataPath, file)}`); } }); + if (file === PREFERENCES_FILE) { + content = JSON.stringify(merge({}, defaultPreferences, JSON.parse(content)), null, 2); + } await fs.promises.writeFile(path.join(userDataPath, file), content, 'utf-8'); } } else { // No initUserDataPath provided: create default preferences to skip onboarding // BUT only if preferences.json doesn't already exist - const prefsPath = path.join(userDataPath, 'preferences.json'); + const prefsPath = path.join(userDataPath, PREFERENCES_FILE); const prefsExist = await existsAsync(prefsPath); if (!prefsExist) { - const defaultPreferences = { - preferences: { - onboarding: { - hasLaunchedBefore: true, - hasSeenWelcomeModal: true, - lastSeenVersion: version - } - } - }; await fs.promises.writeFile( prefsPath, JSON.stringify(defaultPreferences, null, 2), diff --git a/tests/changelog/init-user-data-existing/preferences.json b/tests/changelog/init-user-data-existing/preferences.json index daca1aaad..ccb4a1549 100644 --- a/tests/changelog/init-user-data-existing/preferences.json +++ b/tests/changelog/init-user-data-existing/preferences.json @@ -5,7 +5,8 @@ "preferences": { "onboarding": { "hasLaunchedBefore": true, - "hasSeenWelcomeModal": true + "hasSeenWelcomeModal": true, + "lastSeenVersion": null } } }