Skip to content

Commit

Permalink
feat(web-server): include html files as <link rel="import">
Browse files Browse the repository at this point in the history
  • Loading branch information
Yvonne Yip committed Jan 7, 2014
1 parent e7e4c3e commit 03d7b10
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
9 changes: 7 additions & 2 deletions lib/middleware/karma.js
Expand Up @@ -18,7 +18,8 @@ var common = require('./common');

var VERSION = require('../constants').VERSION;
var SCRIPT_TAG = '<script type="%s" src="%s"></script>';
var LINK_TAG = '<link type="text/css" href="%s" rel="stylesheet">';
var LINK_TAG_CSS = '<link type="text/css" href="%s" rel="stylesheet">';
var LINK_TAG_HTML = '<link href="%s" rel="import">';
var SCRIPT_TYPE = {
'.js': 'text/javascript',
'.dart': 'application/dart'
Expand Down Expand Up @@ -88,7 +89,11 @@ var createKarmaMiddleware = function(filesPromise, serveStaticFile,
}

if (fileExt === '.css') {
return util.format(LINK_TAG, filePath);
return util.format(LINK_TAG_CSS, filePath);
}

if (fileExt === '.html') {
return util.format(LINK_TAG_HTML, filePath);
}

return util.format(SCRIPT_TAG, SCRIPT_TYPE[fileExt] || 'text/javascript', filePath);
Expand Down
17 changes: 13 additions & 4 deletions test/unit/middleware/karma.spec.coffee
Expand Up @@ -122,17 +122,18 @@ describe 'middleware.karma', ->
it 'should serve context.html with replaced link tags', (done) ->
includedFiles [
new MockFile('/first.css', 'sha007')
new MockFile('/second.html', 'sha678')
]

response.once 'end', ->
expect(nextSpy).not.to.have.been.called
expect(response).to.beServedAs 200, 'CONTEXT\n' +
'<link type="text/css" href="/absolute/first.css?sha007" rel="stylesheet">'
'<link type="text/css" href="/absolute/first.css?sha007" rel="stylesheet">\n' +
'<link href="/absolute/second.html?sha678" rel="import">'
done()

callHandlerWith '/__karma__/context.html'


it 'should serve context.html with the correct path for the script tags', (done) ->
includedFiles [
new MockFile('/some/abc/a.js', 'sha')
Expand All @@ -153,13 +154,17 @@ describe 'middleware.karma', ->
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, 'CONTEXT\n' +
'<link type="text/css" href="/absolute/some/abc/a.css?sha1" rel="stylesheet">\n' +
'<link type="text/css" href="/base/b.css?sha2" rel="stylesheet">'
'<link type="text/css" href="/base/b.css?sha2" rel="stylesheet">\n' +
'<link href="/absolute/some/abc/c.html?sha3" rel="import">\n' +
'<link href="/base/d.html?sha4" rel="import">'
done()

callHandlerWith '/__karma__/context.html'
Expand Down Expand Up @@ -231,13 +236,17 @@ describe 'middleware.karma', ->
includedFiles [
new MockFile('/first.css')
new MockFile('/base/path/b.css')
new MockFile('/second.html')
new MockFile('/base/path/d.html')
]

response.once 'end', ->
expect(nextSpy).not.to.have.been.called
expect(response).to.beServedAs 200, 'DEBUG\n' +
'<link type="text/css" href="/absolute/first.css" rel="stylesheet">\n' +
'<link type="text/css" href="/base/b.css" rel="stylesheet">'
'<link type="text/css" href="/base/b.css" rel="stylesheet">\n' +
'<link href="/absolute/second.html" rel="import">\n' +
'<link href="/base/d.html" rel="import">'
done()

callHandlerWith '/__karma__/debug.html'
Expand Down

0 comments on commit 03d7b10

Please sign in to comment.