Skip to content

Commit

Permalink
fix(logger): create parent folders if they are missing
Browse files Browse the repository at this point in the history
Fixes #3734
  • Loading branch information
lachieh authored and Jonathan Ginsburg committed Jan 8, 2022
1 parent b8eafe9 commit 0d24bd9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/server.js
Expand Up @@ -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']
Expand Down
23 changes: 23 additions & 0 deletions test/e2e/browser_console.feature
Expand Up @@ -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:
Expand Down

0 comments on commit 0d24bd9

Please sign in to comment.