test(preferences): set default preferences values to be overriden by tests with custom preferences (#8321)

This commit is contained in:
Bijin A B
2026-06-21 15:07:12 +05:30
committed by GitHub
parent 34a61ebe28
commit 099cdaf232
2 changed files with 26 additions and 11 deletions

View File

@@ -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),

View File

@@ -5,7 +5,8 @@
"preferences": {
"onboarding": {
"hasLaunchedBefore": true,
"hasSeenWelcomeModal": true
"hasSeenWelcomeModal": true,
"lastSeenVersion": null
}
}
}