mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-22 12:15:38 +00:00
test(preferences): set default preferences values to be overriden by tests with custom preferences (#8321)
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
"preferences": {
|
||||
"onboarding": {
|
||||
"hasLaunchedBefore": true,
|
||||
"hasSeenWelcomeModal": true
|
||||
"hasSeenWelcomeModal": true,
|
||||
"lastSeenVersion": null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user