From a5bb2e0764c222fd482fbd0c17443d946a0ca15b Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Fri, 9 Apr 2021 18:45:44 +0200 Subject: [PATCH] fix(component testing): default config values (#15902) Co-authored-by: Jessica Sachs --- packages/server-ct/src/project-ct.ts | 19 ++++--------------- packages/server/lib/config.js | 2 ++ 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/packages/server-ct/src/project-ct.ts b/packages/server-ct/src/project-ct.ts index fdbe12b0adc0..3c10c331b387 100644 --- a/packages/server-ct/src/project-ct.ts +++ b/packages/server-ct/src/project-ct.ts @@ -2,12 +2,11 @@ import Debug from 'debug' import config from '@packages/server/lib/config' import plugins from '@packages/server/lib/plugins' import devServer from '@packages/server/lib/plugins/dev-server' -import { ProjectBase } from '@packages/server/lib/project-base' +import { Cfg, ProjectBase } from '@packages/server/lib/project-base' import settings from '@packages/server/lib/util/settings' import specsUtil from '@packages/server/lib/util/specs' import { ServerCt } from './server-ct' import { SpecsStore } from './specs-store' -import { options } from '@packages/server/lib/config_options' export * from '@packages/server/lib/project-base' @@ -24,22 +23,12 @@ export class ProjectCt extends ProjectBase { * 2. otherwise, use 500/500 by default. */ addComponentTestingUniqueDefaults (cfg: Record) { - const defaultViewport = options.reduce>((acc, curr) => { - if (curr.name === 'viewportHeight') { - return { ...acc, viewportHeight: curr.defaultValue as number } - } - - if (curr.name === 'viewportWidth') { - return { ...acc, viewportWidth: curr.defaultValue as number } - } - - return acc - }, {}) + const rawJson = cfg.rawJson as Cfg return { ...cfg, - viewportHeight: cfg.viewportHeight !== defaultViewport.viewportHeight ? cfg.viewportHeight : 500, - viewportWidth: cfg.viewportWidth !== defaultViewport.viewportWidth ? cfg.viewportWidth : 500, + viewportHeight: rawJson.viewportHeight ?? 500, + viewportWidth: rawJson.viewportWidth ?? 500, } } diff --git a/packages/server/lib/config.js b/packages/server/lib/config.js index e996da02d0b4..c15fa6ef67ef 100644 --- a/packages/server/lib/config.js +++ b/packages/server/lib/config.js @@ -241,6 +241,8 @@ module.exports = { mergeDefaults (config = {}, options = {}) { const resolved = {} + config.rawJson = _.cloneDeep(config) + _.extend(config, _.pick(options, 'configFile', 'morgan', 'isTextTerminal', 'socketId', 'report', 'browsers')) debug('merged config with options, got %o', config)