From 7d457570677bea90747a6436d40db954734876df Mon Sep 17 00:00:00 2001 From: johnjbarton Date: Wed, 23 Dec 2020 16:32:23 -0800 Subject: [PATCH] fix(middleware): catch errors when loading a module Fix #3572 Co-authored-by: https://github.com/jehon --- lib/middleware/karma.js | 6 +++++- test/e2e/error.feature | 16 ++++++++++++++++ .../error/import-something-from-somewhere.js | 2 ++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/e2e/support/error/import-something-from-somewhere.js diff --git a/lib/middleware/karma.js b/lib/middleware/karma.js index 4e27d4a52..3a34b4e58 100644 --- a/lib/middleware/karma.js +++ b/lib/middleware/karma.js @@ -191,7 +191,11 @@ function createKarmaMiddleware ( } else { const scriptType = (SCRIPT_TYPE[fileType] || 'text/javascript') const crossOriginAttribute = includeCrossOriginAttribute ? 'crossorigin="anonymous"' : '' - scriptTags.push(``) + if (fileType === 'module') { + scriptTags.push(``) + } else { + scriptTags.push(``) + } } } diff --git a/test/e2e/error.feature b/test/e2e/error.feature index 0b327110e..09236959a 100644 --- a/test/e2e/error.feature +++ b/test/e2e/error.feature @@ -40,3 +40,19 @@ Feature: Error Display """ SyntaxError: Unexpected token '}' """ + +Scenario: Missing module Error in a test file + Given a configuration with: + """ + files = [{pattern: 'error/import-something-from-somewhere.js', type: 'module'}]; + browsers = ['ChromeHeadlessNoSandbox']; + plugins = [ + 'karma-jasmine', + 'karma-chrome-launcher' + ]; + """ + When I start Karma + Then it fails with: + """ + Uncaught Error loading error/import-something-from-somewhere.js + """ diff --git a/test/e2e/support/error/import-something-from-somewhere.js b/test/e2e/support/error/import-something-from-somewhere.js new file mode 100644 index 000000000..1a56d4654 --- /dev/null +++ b/test/e2e/support/error/import-something-from-somewhere.js @@ -0,0 +1,2 @@ +import { something } from './somewhere.js' +console.log(something)