Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify lib/middleware/karma.js #3871

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions lib/middleware/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ const stripHost = require('./strip_host').stripHost
const common = require('./common')

const VERSION = require('../constants').VERSION
const SCRIPT_TYPE = {
js: 'text/javascript',
module: 'module'
}
const FILE_TYPES = [
'css',
'html',
Expand Down Expand Up @@ -185,17 +181,16 @@ function createKarmaMiddleware (
const integrityAttribute = file.integrity ? ` integrity="${file.integrity}"` : ''
const crossOriginAttribute = includeCrossOriginAttribute ? ' crossorigin="anonymous"' : ''
if (fileType === 'css') {
scriptTags.push(`<link type="text/css" href="${filePath}" rel="stylesheet"${integrityAttribute}${crossOriginAttribute}>`)
scriptTags.push(`<link href="${filePath}" rel="stylesheet"${integrityAttribute}${crossOriginAttribute}>`)
} else if (fileType === 'dom') {
scriptTags.push(file.content)
} else if (fileType === 'html') {
scriptTags.push(`<link href="${filePath}" rel="import"${integrityAttribute}${crossOriginAttribute}>`)
} else {
const scriptType = (SCRIPT_TYPE[fileType] || 'text/javascript')
if (fileType === 'module') {
scriptTags.push(`<script onerror="throw 'Error loading ${filePath}'" type="${scriptType}" src="${filePath}"${integrityAttribute}${crossOriginAttribute}></script>`)
scriptTags.push(`<script onerror="throw 'Error loading ${filePath}'" type="module" src="${filePath}"${integrityAttribute}${crossOriginAttribute}></script>`)
} else {
scriptTags.push(`<script type="${scriptType}" src="${filePath}"${integrityAttribute}${crossOriginAttribute}></script>`)
scriptTags.push(`<script src="${filePath}"${integrityAttribute}${crossOriginAttribute}></script>`)
}
}
}
Expand Down
Loading