Skip to content

Commit fec972f

Browse files
authoredJan 12, 2021
fix(middleware): catch errors when loading a module (#3605)
Fix #3572 Co-authored-by: https://github.com/jehon
1 parent 3fca456 commit fec972f

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed
 

‎lib/middleware/karma.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,11 @@ function createKarmaMiddleware (
191191
} else {
192192
const scriptType = (SCRIPT_TYPE[fileType] || 'text/javascript')
193193
const crossOriginAttribute = includeCrossOriginAttribute ? 'crossorigin="anonymous"' : ''
194-
scriptTags.push(`<script type="${scriptType}" src="${filePath}" ${crossOriginAttribute}></script>`)
194+
if (fileType === 'module') {
195+
scriptTags.push(`<script onerror="throw 'Error loading ${filePath}'" type="${scriptType}" src="${filePath}" ${crossOriginAttribute}></script>`)
196+
} else {
197+
scriptTags.push(`<script type="${scriptType}" src="${filePath}" ${crossOriginAttribute}></script>`)
198+
}
195199
}
196200
}
197201

‎test/e2e/error.feature

+16
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,19 @@ Feature: Error Display
4040
"""
4141
SyntaxError: Unexpected token '}'
4242
"""
43+
44+
Scenario: Missing module Error in a test file
45+
Given a configuration with:
46+
"""
47+
files = [{pattern: 'error/import-something-from-somewhere.js', type: 'module'}];
48+
browsers = ['ChromeHeadlessNoSandbox'];
49+
plugins = [
50+
'karma-jasmine',
51+
'karma-chrome-launcher'
52+
];
53+
"""
54+
When I start Karma
55+
Then it fails with:
56+
"""
57+
Uncaught Error loading error/import-something-from-somewhere.js
58+
"""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { something } from './somewhere.js'
2+
console.log(something)

0 commit comments

Comments
 (0)
Please sign in to comment.