Skip to content

Commit

Permalink
Merge 8810007 into 8997b74
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjbarton authored Dec 23, 2020
2 parents 8997b74 + 8810007 commit 0868013
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
17 changes: 8 additions & 9 deletions lib/middleware/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ function getXUACompatibleUrl (url) {
return ''
}

function reportFileTypeError (fileType, path) {
log.error(`Invalid file type (${fileType}) for ${path}.\n` +
' Specify a valid type in the configuration file.\n' +
' See http://karma-runner.github.io/latest/config/files.html')
}

function createKarmaMiddleware (
filesPromise,
serveStaticFile,
Expand Down Expand Up @@ -163,15 +169,8 @@ function createKarmaMiddleware (
const fileType = file.type || file.detectType()

if (!FILE_TYPES.includes(fileType)) {
if (file.type == null) {
log.warn(
'Unable to determine file type from the file extension, defaulting to js.\n' +
` To silence the warning specify a valid type for ${file.originalPath} in the configuration file.\n` +
' See http://karma-runner.github.io/latest/config/files.html'
)
} else {
log.warn(`Invalid file type (${file.type || 'empty string'}), defaulting to js.`)
}
reportFileTypeError(fileType.length ? fileType : '<empty>', file.originalPath)
continue
}

if (!file.isUrl) {
Expand Down
4 changes: 1 addition & 3 deletions test/e2e/helpful-logs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,5 @@ Feature: Helpful warning and errors
When I start Karma
Then the stdout matches RegExp:
"""
WARN \[middleware:karma\]: Unable to determine file type from the file extension, defaulting to js.
To silence the warning specify a valid type for .+modules/minus.mjs in the configuration file.
See http://karma-runner.github.io/latest/config/files.html
ERROR \[middleware:karma\]: Invalid file type \(mjs\) for .+modules/minus.mjs\.
"""
4 changes: 2 additions & 2 deletions test/unit/middleware/karma.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,11 @@ describe('middleware.karma', () => {

it('should not change urls', (done) => {
includedFiles([
new Url('http://some.url.com/whatever')
new Url('http://some.url.com/whatever.js')
])

response.once('end', () => {
expect(response).to.beServedAs(200, 'CONTEXT\n<script type="text/javascript" src="http://some.url.com/whatever" crossorigin="anonymous"></script>')
expect(response).to.beServedAs(200, 'CONTEXT\n<script type="text/javascript" src="http://some.url.com/whatever.js" crossorigin="anonymous"></script>')
done()
})

Expand Down

0 comments on commit 0868013

Please sign in to comment.