diff --git a/main.js b/main.js index c738eafee5..c42125a4bb 100644 --- a/main.js +++ b/main.js @@ -120,7 +120,7 @@ const { getTitleBarVisibility, TitleBarVisibility, } = require('./ts/types/Settings'); -const { Environment } = require('./ts/environment'); +const { Environment, isTestEnvironment } = require('./ts/environment'); const { ChallengeMainHandler } = require('./ts/main/challengeMain'); const { NativeThemeNotifier } = require('./ts/main/NativeThemeNotifier'); const { PowerChannel } = require('./ts/main/powerChannel'); @@ -362,13 +362,13 @@ async function createWindow() { minHeight: MIN_HEIGHT, autoHideMenuBar: false, titleBarStyle: - getTitleBarVisibility() === TitleBarVisibility.Hidden + getTitleBarVisibility() === TitleBarVisibility.Hidden && + !isTestEnvironment(config.environment) ? 'hidden' : 'default', - backgroundColor: - config.environment === 'test' || config.environment === 'test-lib' - ? '#ffffff' // Tests should always be rendered on a white background - : '#3a76f0', + backgroundColor: isTestEnvironment(config.environment) + ? '#ffffff' // Tests should always be rendered on a white background + : '#3a76f0', webPreferences: { ...defaultWebPrefs, nodeIntegration: false, @@ -518,8 +518,7 @@ async function createWindow() { }); // If the application is terminating, just do the default if ( - config.environment === 'test' || - config.environment === 'test-lib' || + isTestEnvironment(config.environment) || (mainWindow.readyForShutdown && windowState.shouldQuit()) ) { return; @@ -1478,9 +1477,7 @@ app.on('window-all-closed', () => { // On OS X it is common for applications and their menu bar // to stay active until the user quits explicitly with Cmd + Q const shouldAutoClose = - !OS.isMacOS() || - config.environment === 'test' || - config.environment === 'test-lib'; + !OS.isMacOS() || isTestEnvironment(config.environment); // Only automatically quit if the main window has been created // This is necessary because `window-all-closed` can be triggered by the diff --git a/ts/environment.ts b/ts/environment.ts index 92795de6ae..8a64af4169 100644 --- a/ts/environment.ts +++ b/ts/environment.ts @@ -39,3 +39,6 @@ export const parseEnvironment = makeEnumParser( Environment, Environment.Production ); + +export const isTestEnvironment = (env: Environment): boolean => + env === Environment.Test || env === Environment.TestLib; diff --git a/ts/test-both/environment_test.ts b/ts/test-both/environment_test.ts index 604c47cda0..5fbebefb20 100644 --- a/ts/test-both/environment_test.ts +++ b/ts/test-both/environment_test.ts @@ -3,7 +3,11 @@ import { assert } from 'chai'; -import { parseEnvironment, Environment } from '../environment'; +import { + Environment, + isTestEnvironment, + parseEnvironment, +} from '../environment'; describe('environment utilities', () => { describe('parseEnvironment', () => { @@ -38,4 +42,17 @@ describe('environment utilities', () => { assert.equal(parseEnvironment('test-lib'), Environment.TestLib); }); }); + + describe('isTestEnvironment', () => { + it('returns false for non-test environments', () => { + assert.isFalse(isTestEnvironment(Environment.Development)); + assert.isFalse(isTestEnvironment(Environment.Production)); + assert.isFalse(isTestEnvironment(Environment.Staging)); + }); + + it('returns true for test environments', () => { + assert.isTrue(isTestEnvironment(Environment.Test)); + assert.isTrue(isTestEnvironment(Environment.TestLib)); + }); + }); });