Skip to content

Commit

Permalink
fix: patch karma to allow loading virtual packages
Browse files Browse the repository at this point in the history
  • Loading branch information
snasirca committed Jun 23, 2020
1 parent 41fa9c0 commit 90cce10
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/middleware/karma.js
Expand Up @@ -220,10 +220,10 @@ function createKarmaMiddleware (
}) : []

return data
.replace('%SCRIPTS%', scriptTags.join('\n'))
.replace('%SCRIPTS%', () => scriptTags.join('\n'))
.replace('%CLIENT_CONFIG%', 'window.__karma__.config = ' + JSON.stringify(client) + ';\n')
.replace('%SCRIPT_URL_ARRAY%', 'window.__karma__.scriptUrls = ' + JSON.stringify(scriptUrls) + ';\n')
.replace('%MAPPINGS%', 'window.__karma__.files = {\n' + mappings.join(',\n') + '\n};\n')
.replace('%MAPPINGS%', () => 'window.__karma__.files = {\n' + mappings.join(',\n') + '\n};\n')
.replace('\n%X_UA_COMPATIBLE%', getXUACompatibleMetaElement(request.url))
})
})
Expand Down
29 changes: 29 additions & 0 deletions test/unit/middleware/karma.spec.js
Expand Up @@ -214,6 +214,21 @@ describe('middleware.karma', () => {
callHandlerWith('/__karma__/context.html')
})

it('should serve context.html without using special patterns when replacing script tags', (done) => {
includedFiles([
new MockFile('/.yarn/$$virtual/first.js', 'sha123'),
new MockFile('/.yarn/$$virtual/second.dart', 'sha456')
])

response.once('end', () => {
expect(nextSpy).not.to.have.been.called
expect(response).to.beServedAs(200, 'CONTEXT\n<script type="text/javascript" src="/__proxy__/__karma__/absolute/.yarn/$$virtual/first.js?sha123" crossorigin="anonymous"></script>\n<script type="application/dart" src="/__proxy__/__karma__/absolute/.yarn/$$virtual/second.dart?sha456" crossorigin="anonymous"></script>')
done()
})

callHandlerWith('/__karma__/context.html')
})

it('should serve context.html with replaced link tags', (done) => {
includedFiles([
new MockFile('/first.css', 'sha007'),
Expand Down Expand Up @@ -373,6 +388,20 @@ describe('middleware.karma', () => {
callHandlerWith('/__karma__/context.html')
})

it('should inline mappings without using special patterns', (done) => {
fsMock._touchFile('/karma/static/context.html', 0, '%MAPPINGS%')
servedFiles([
new MockFile('/.yarn/$$virtual/abc/a.js', 'sha_a')
])

response.once('end', () => {
expect(response).to.beServedAs(200, "window.__karma__.files = {\n '/__proxy__/__karma__/absolute/.yarn/$$virtual/abc/a.js': 'sha_a'\n};\n")
done()
})

callHandlerWith('/__karma__/context.html')
})

it('should escape quotes in mappings with all served files', (done) => {
fsMock._touchFile('/karma/static/context.html', 0, '%MAPPINGS%')
servedFiles([
Expand Down

0 comments on commit 90cce10

Please sign in to comment.