From 616b0a5bf1721793e69063f87332245e2aa13319 Mon Sep 17 00:00:00 2001 From: Lachlan Heywood Date: Thu, 23 Dec 2021 00:02:27 -0500 Subject: [PATCH] fix(logger): create parent folders if they are missing Fixes #3734 --- lib/server.js | 2 ++ test/e2e/browser_console.feature | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/server.js b/lib/server.js index cec1ecd0b..dc2314cdf 100644 --- a/lib/server.js +++ b/lib/server.js @@ -265,6 +265,8 @@ class Server extends KarmaEventEmitter { const configLevel = config.browserConsoleLogOptions.level || 'debug' const configFormat = config.browserConsoleLogOptions.format || '%b %T: %m' const configPath = config.browserConsoleLogOptions.path + const configPathDir = path.dirname(configPath) + if (!fs.existsSync(configPathDir)) fs.mkdirSync(configPathDir, { recursive: true }) this.log.info(`Writing browser console to file: ${configPath}`) const browserLogFile = fs.openSync(configPath, 'w+') const levels = ['log', 'error', 'warn', 'info', 'debug'] diff --git a/test/e2e/browser_console.feature b/test/e2e/browser_console.feature index a83c43e54..5db133a6a 100644 --- a/test/e2e/browser_console.feature +++ b/test/e2e/browser_console.feature @@ -152,6 +152,29 @@ Feature: Browser Console Configuration . Chrome Headless """ + + Scenario: Execute logging path when a folder does not exist + Given a configuration with: + """ + files = ['browser-console/log.js', 'browser-console/test.js']; + browsers = ['ChromeHeadlessNoSandbox']; + plugins = [ + 'karma-jasmine', + 'karma-chrome-launcher' + ]; + browserConsoleLogOptions = { + path: 'sandbox/nested/folder/console.log', + format: '%t:%T:%m', + level: 'warn' + }; + """ + When I start Karma + Then the file at sandbox/nested/folder/console.log contains: + """ + log:LOG:'foo' + warn:WARN:'foobar' + error:ERROR:'barbaz' + """ Scenario: Execute logging program and disabling terminal Given a configuration with: