Browse files

Merge pull request #882 from morethanreal/feat-htmlimports

feat(web-server): include html files as <link rel="import">
  • Loading branch information...
2 parents e6e1da8 + 03d7b10 commit 203a396f8b27d8fbcbbb1ca793dc21e80d98a416 @vojtajina vojtajina committed Jan 30, 2014
Showing with 20 additions and 6 deletions.
  1. +7 −2 lib/middleware/karma.js
  2. +13 −4 test/unit/middleware/karma.spec.coffee
View
9 lib/middleware/karma.js
@@ -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'
@@ -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);
View
17 test/unit/middleware/karma.spec.coffee
@@ -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')
@@ -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'
@@ -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'

0 comments on commit 203a396

Please sign in to comment.