Skip to content

Commit

Permalink
Merge 30eeb2f into 35d57e9
Browse files Browse the repository at this point in the history
  • Loading branch information
falsandtru authored May 9, 2020
2 parents 35d57e9 + 30eeb2f commit 70989c2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ const replaceWinPath = (path) => {

exports.normalizeWinPath = process.platform === 'win32' ? replaceWinPath : _.identity

exports.getFileType = (file) => {
return file.type || path.extname(file.path.split(/[?#]/, 1)[0] || '').substring(1)
}

exports.mkdirIfNotExists = (directory, done) => {
// TODO(vojta): handle if it's a file
/* eslint-disable handle-callback-err */
Expand Down
3 changes: 1 addition & 2 deletions lib/middleware/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* - setting propert caching headers
*/

const path = require('path')
const url = require('url')
const helper = require('../helper')

Expand Down Expand Up @@ -164,7 +163,7 @@ function createKarmaMiddleware (
const scriptTags = []
for (const file of files.included) {
let filePath = file.path
const fileType = file.type || path.extname(filePath).substring(1)
const fileType = helper.getFileType(file)

if (helper.isDefined(fileType) && !FILE_TYPES.includes(fileType)) {
log.warn(`Invalid file type (${fileType}), defaulting to js.`)
Expand Down
9 changes: 9 additions & 0 deletions test/unit/helper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,15 @@ describe('helper', () => {
})
})

describe('getFileType', () => {
it('should extract file type', () => {
expect(helper.getFileType({ path: 'a.js' })).to.equal('js')
expect(helper.getFileType({ path: 'a.js#' })).to.equal('js')
expect(helper.getFileType({ path: 'a.js?#' })).to.equal('js')
expect(helper.getFileType({ type: 'js', path: 'a' })).to.equal('js')
})
})

describe('mkdirIfNotExists', () => {
const fsMock = require('mocks').fs
const loadFile = require('mocks').loadFile
Expand Down

0 comments on commit 70989c2

Please sign in to comment.