Skip to content

Commit

Permalink
feat(web-server): serve css files
Browse files Browse the repository at this point in the history
Closes #431
  • Loading branch information
timols committed Jul 2, 2013
1 parent e9a53bd commit 4e30554
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/web-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var proxy = require('./proxy');
var log = require('./logger').create('web server');

var SCRIPT_TAG = '<script type="%s" src="%s"></script>';
var LINK_TAG = '<link type="text/css" href="%s" rel="stylesheet">';


var setNoCacheHeaders = function(response) {
Expand Down Expand Up @@ -113,6 +114,10 @@ var createKarmaSourceHandler = function(promiseContainer, staticFolder, adapterF
}
}

if (/\.css$/.test(file.path)) {
return util.format(LINK_TAG, filePath);
}

return util.format(SCRIPT_TAG, scriptType, filePath);
});

Expand Down
47 changes: 46 additions & 1 deletion test/unit/web-server.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,19 @@ describe 'web-server', ->

karmaSrcHandler new httpMock.ServerRequest('/_karma_/context.html'), response, nextSpy

it 'should serve context.html with replaced link tags', ->
includedFiles [{path: '/first.css', mtime: new Date 12345},
{path: '/second.css', mtime: new Date 67890}]

response.once 'end', ->
expect(nextSpy).not.to.have.been.called
expect(response._content.toString()).to.equal 'CONTEXT\n' +
'<link type="text/css" href="/absolute/first.css?12345" rel="stylesheet">\n' +
'<link type="text/css" href="/absolute/second.css?67890" rel="stylesheet">'
expect(response.statusCode).to.equal 200

karmaSrcHandler new httpMock.ServerRequest('/_karma_/context.html'), response, nextSpy


it 'should serve debug.html with replaced script tags without timestamps', (done) ->
includedFiles [{path: '/first.js', mtime: new Date 12345},
Expand All @@ -204,7 +217,22 @@ describe 'web-server', ->
karmaSrcHandler new httpMock.ServerRequest('/_karma_/debug.html'), response, nextSpy


it 'should serve context.html with /basepath/*, /adapter/*, /absolute/* ', (done) ->
it 'should serve debug.html with replaced link tags without timestamps', (done) ->
includedFiles [{path: '/first.css', mtime: new Date 12345},
{path: '/second.css', mtime: new Date 67890}]

response.once 'end', ->
expect(nextSpy).not.to.have.been.called
expect(response._content.toString()).to.equal 'RUNNER\n' +
'<link type="text/css" href="/absolute/first.css" rel="stylesheet">\n' +
'<link type="text/css" href="/absolute/second.css" rel="stylesheet">'
expect(response.statusCode).to.equal 200
done()

karmaSrcHandler new httpMock.ServerRequest('/_karma_/debug.html'), response, nextSpy


it 'should serve context.html with the correct path for script tags', (done) ->
includedFiles [{path: '/some/abs/a.js', mtime: new Date 12345},
{path: '/base/path/b.js', mtime: new Date 67890},
{path: '/karma/adapter/c.js', mtime: new Date 321}]
Expand All @@ -221,6 +249,23 @@ describe 'web-server', ->
karmaSrcHandler new httpMock.ServerRequest('/_karma_/context.html'), response, nextSpy


it 'should serve context.html with the correct path for link tags', (done) ->
includedFiles [{path: '/some/abs/a.css', mtime: new Date 12345},
{path: '/base/path/b.css', mtime: new Date 67890},
{path: '/karma/adapter/c.css', mtime: new Date 321}]

response.once 'end', ->
expect(nextSpy).not.to.have.been.called
expect(response._content.toString()).to.equal 'CONTEXT\n' +
'<link type="text/css" href="/absolute/some/abs/a.css?12345" rel="stylesheet">\n' +
'<link type="text/css" href="/base/b.css?67890" rel="stylesheet">\n' +
'<link type="text/css" href="/adapter/c.css?321" rel="stylesheet">'
expect(response.statusCode).to.equal 200
done()

karmaSrcHandler new httpMock.ServerRequest('/_karma_/context.html'), response, nextSpy


it 'should not change urls', (done) ->
includedFiles [{path: 'http://some.url.com/whatever', isUrl: true}]

Expand Down

0 comments on commit 4e30554

Please sign in to comment.