Skip to content

Commit 0d24bd9

Browse files
lachiehJonathan Ginsburg
authored and
Jonathan Ginsburg
committedJan 8, 2022
fix(logger): create parent folders if they are missing
Fixes #3734
1 parent b8eafe9 commit 0d24bd9

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
 

‎lib/server.js

+2
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ class Server extends KarmaEventEmitter {
265265
const configLevel = config.browserConsoleLogOptions.level || 'debug'
266266
const configFormat = config.browserConsoleLogOptions.format || '%b %T: %m'
267267
const configPath = config.browserConsoleLogOptions.path
268+
const configPathDir = path.dirname(configPath)
269+
if (!fs.existsSync(configPathDir)) fs.mkdirSync(configPathDir, { recursive: true })
268270
this.log.info(`Writing browser console to file: ${configPath}`)
269271
const browserLogFile = fs.openSync(configPath, 'w+')
270272
const levels = ['log', 'error', 'warn', 'info', 'debug']

‎test/e2e/browser_console.feature

+23
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,29 @@ Feature: Browser Console Configuration
152152
.
153153
Chrome Headless
154154
"""
155+
156+
Scenario: Execute logging path when a folder does not exist
157+
Given a configuration with:
158+
"""
159+
files = ['browser-console/log.js', 'browser-console/test.js'];
160+
browsers = ['ChromeHeadlessNoSandbox'];
161+
plugins = [
162+
'karma-jasmine',
163+
'karma-chrome-launcher'
164+
];
165+
browserConsoleLogOptions = {
166+
path: 'sandbox/nested/folder/console.log',
167+
format: '%t:%T:%m',
168+
level: 'warn'
169+
};
170+
"""
171+
When I start Karma
172+
Then the file at sandbox/nested/folder/console.log contains:
173+
"""
174+
log:LOG:'foo'
175+
warn:WARN:'foobar'
176+
error:ERROR:'barbaz'
177+
"""
155178

156179
Scenario: Execute logging program and disabling terminal
157180
Given a configuration with:

0 commit comments

Comments
 (0)
Please sign in to comment.