From 4f81f855bb23b176123cf7ddfdf548a5941988bf Mon Sep 17 00:00:00 2001 From: johnjbarton Date: Mon, 14 Dec 2020 17:19:30 -0800 Subject: [PATCH] fix(middleware): throw script tag errors Include failing path. This is important for module tags which otherwise simply give 404 at the server. Fixes #3572 --- lib/middleware/karma.js | 2 +- test/unit/middleware/karma.spec.js | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/middleware/karma.js b/lib/middleware/karma.js index c48332d12..5c3e924f5 100644 --- a/lib/middleware/karma.js +++ b/lib/middleware/karma.js @@ -193,7 +193,7 @@ function createKarmaMiddleware ( } else { const scriptType = (SCRIPT_TYPE[fileType] || 'text/javascript') const crossOriginAttribute = includeCrossOriginAttribute ? 'crossorigin="anonymous"' : '' - scriptTags.push(``) + scriptTags.push(``) } } diff --git a/test/unit/middleware/karma.spec.js b/test/unit/middleware/karma.spec.js index 16242d09d..9a6a0bdeb 100644 --- a/test/unit/middleware/karma.spec.js +++ b/test/unit/middleware/karma.spec.js @@ -207,7 +207,8 @@ describe('middleware.karma', () => { response.once('end', () => { expect(nextSpy).not.to.have.been.called - expect(response).to.beServedAs(200, 'CONTEXT\n\n') + /* eslint quotes: ["error", "single", { "allowTemplateLiterals": true }] */ + expect(response).to.beServedAs(200, `CONTEXT\n\n`) done() }) @@ -241,7 +242,8 @@ describe('middleware.karma', () => { response.once('end', () => { expect(nextSpy).not.to.have.been.called - expect(response).to.beServedAs(200, 'CONTEXT\n\n') + /* eslint quotes: ["error", "single", { "allowTemplateLiterals": true }] */ + expect(response).to.beServedAs(200, `CONTEXT\n\n`) done() }) @@ -333,7 +335,8 @@ describe('middleware.karma', () => { ]) response.once('end', () => { - expect(response).to.beServedAs(200, 'CONTEXT\n') + /* eslint quotes: ["error", "single", { "allowTemplateLiterals": true }] */ + expect(response).to.beServedAs(200, `CONTEXT\n`) done() }) @@ -366,7 +369,8 @@ describe('middleware.karma', () => { ]) response.once('end', () => { - expect(response).to.beServedAs(200, "window.__karma__.files = {\n '/__proxy__/__karma__/absolute/some/abc/a.js': 'sha_a',\n '/__proxy__/__karma__/base/b.js': 'sha_b',\n '/__proxy__/__karma__/absolute\\\\windows\\\\path\\\\uuu\\\\c.js': 'sha_c'\n};\n") + /* eslint quotes: ["error", "single", { "allowTemplateLiterals": true }] */ + expect(response).to.beServedAs(200, `window.__karma__.files = {\n '/__proxy__/__karma__/absolute/some/abc/a.js': 'sha_a',\n '/__proxy__/__karma__/base/b.js': 'sha_b',\n '/__proxy__/__karma__/absolute\\\\windows\\\\path\\\\uuu\\\\c.js': 'sha_c'\n};\n`) done() }) @@ -376,7 +380,8 @@ describe('middleware.karma', () => { it('should escape quotes in mappings with all served files', (done) => { fsMock._touchFile('/karma/static/context.html', 0, '%MAPPINGS%') servedFiles([ - new MockFile("/some/abc/a'b.js", 'sha_a'), + /* eslint quotes: ["error", "single", { "allowTemplateLiterals": true }] */ + new MockFile(`/some/abc/a'b.js`, 'sha_a'), new MockFile('/base/path/ba.js', 'sha_b') ]) @@ -396,7 +401,8 @@ describe('middleware.karma', () => { response.once('end', () => { expect(nextSpy).not.to.have.been.called - expect(response).to.beServedAs(200, 'DEBUG\n\n') + /* eslint quotes: ["error", "single", { "allowTemplateLiterals": true }] */ + expect(response).to.beServedAs(200, `DEBUG\n\n`) done() })