From 4e305545ddf2726c1fe65c46efd5e7c1045ac041 Mon Sep 17 00:00:00 2001 From: Tim Olshansky Date: Tue, 25 Jun 2013 18:04:35 -0700 Subject: [PATCH] feat(web-server): serve css files Closes #431 --- lib/web-server.js | 5 ++++ test/unit/web-server.spec.coffee | 47 +++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/lib/web-server.js b/lib/web-server.js index aacfe7373..71ec666f6 100644 --- a/lib/web-server.js +++ b/lib/web-server.js @@ -13,6 +13,7 @@ var proxy = require('./proxy'); var log = require('./logger').create('web server'); var SCRIPT_TAG = ''; +var LINK_TAG = ''; var setNoCacheHeaders = function(response) { @@ -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); }); diff --git a/test/unit/web-server.spec.coffee b/test/unit/web-server.spec.coffee index 2c941b3b1..18e49246f 100644 --- a/test/unit/web-server.spec.coffee +++ b/test/unit/web-server.spec.coffee @@ -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' + + '\n' + + '' + 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}, @@ -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' + + '\n' + + '' + 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}] @@ -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' + + '\n' + + '\n' + + '' + 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}]