Skip to content

Commit

Permalink
fix(web-server): Correctly update filesPromise on files updated
Browse files Browse the repository at this point in the history
When the `file_list_modified` event was being emitted, the filesDeferred
was simply being resolved again; this has no effect and subsequent
calls to `filesPromise.then` continued to be resolved with the old
files.

This had the effect that issuing `karma run` did not result in new test
files being served.

This has been fixed by reverting the changes to `web-server.js` made in
fabdbae.
  • Loading branch information
KJTsanaktsidis committed Jul 9, 2015
1 parent 68b5208 commit 32eec8d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/web-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ var fs = require('fs')
var http = require('http')
var path = require('path')
var connect = require('connect')

var helper = require('./helper')
var Promise = require('bluebird')

var common = require('./middleware/common')
var runnerMiddleware = require('./middleware/runner')
Expand Down Expand Up @@ -32,18 +31,18 @@ createCustomHandler.$inject = ['customFileHandlers', 'config.basePath']
var createWebServer = function (injector, emitter) {
var serveStaticFile = common.createServeFile(fs, path.normalize(__dirname + '/../static'))
var serveFile = common.createServeFile(fs)
var filesDeferred = helper.defer()
var filesPromise = new common.PromiseContainer()

emitter.on('file_list_modified', function (files) {
filesDeferred.resolve(files)
filesPromise.set(Promise.resolve(files))
})

// locals for webserver module
// NOTE(vojta): figure out how to do this with DI
injector = injector.createChild([{
serveFile: ['value', serveFile],
serveStaticFile: ['value', serveStaticFile],
filesPromise: ['value', filesDeferred.promise]
filesPromise: ['value', filesPromise]
}])

var proxyMiddlewareInstance = injector.invoke(proxyMiddleware.create)
Expand Down
9 changes: 9 additions & 0 deletions test/unit/web-server.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe 'web-server', ->
base:
path:
'one.js': mocks.fs.file(0, 'js-source')
'new.js': mocks.fs.file(0, 'new-js-source')

# NOTE(vojta): only loading once, to speed things up
# this relies on the fact that none of these tests mutate fs
Expand Down Expand Up @@ -61,6 +62,14 @@ describe 'web-server', ->
.get('/base/one.js')
.expect(200, 'js-source')

it 'should serve updated source files on file_list_modified', () ->
servedFiles new Set([new File '/base/path/one.js'])
servedFiles new Set([new File '/base/path/new.js'])

request(server)
.get('/base/new.js')
.expect(200, 'new-js-source')

it 'should load custom handlers', () ->
servedFiles new Set()

Expand Down

0 comments on commit 32eec8d

Please sign in to comment.