Skip to content

Commit

Permalink
feat(runner): serve context in JSON format for JS-only environments
Browse files Browse the repository at this point in the history
serve files to load at /context.json
  • Loading branch information
tailsu committed Jun 9, 2015
1 parent 1c233a0 commit 189feff
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/middleware/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ var createKarmaMiddleware = function (filesPromise, serveStaticFile,
' some errors:\\n ' + errorFiles.join('\\n ') + '");')
})
})
} else if (requestUrl === '/context.json') {
return filesPromise.then(function (files) {
common.setNoCacheHeaders(response)
response.writeHead(200)
response.end(JSON.stringify({
files: files.included.map(function (file) {
return filePathToUrlPath(file.path + '?' + file.sha, basePath, urlRoot);
})
}))
})
}

return next()
Expand Down
22 changes: 22 additions & 0 deletions test/unit/middleware/karma.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,28 @@ describe 'middleware.karma', ->

callHandlerWith '/__karma__/context.html'

it 'should serve context.json with the correct paths for all files', (done) ->
includedFiles [
new MockFile('/some/abc/a.css', 'sha1')
new MockFile('/base/path/b.css', 'sha2')
new MockFile('/some/abc/c.html', 'sha3')
new MockFile('/base/path/d.html', 'sha4')
]

response.once 'end', ->
expect(nextSpy).not.to.have.been.called
expect(response).to.beServedAs 200, JSON.stringify {
files: [
'/__karma__/absolute/some/abc/a.css?sha1',
'/__karma__/base/b.css?sha2',
'/__karma__/absolute/some/abc/c.html?sha3',
'/__karma__/base/d.html?sha4'
]
}
done()

callHandlerWith '/__karma__/context.json'


it 'should not change urls', (done) ->
includedFiles [
Expand Down

0 comments on commit 189feff

Please sign in to comment.