Skip to content

Commit

Permalink
fix(middleware): add file type to absolute urls
Browse files Browse the repository at this point in the history
  • Loading branch information
josh18 authored and dignifiedquire committed Feb 19, 2018
1 parent fca048b commit bd1f799
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ Pattern.prototype.compare = function (other) {
return helper.mmComparePatternWeights(this.weight, other.weight)
}

var UrlPattern = function (url) {
Pattern.call(this, url, false, true, false, false)
var UrlPattern = function (url, type) {
Pattern.call(this, url, false, true, false, false, type)
}

var createPatternObject = function (pattern) {
Expand All @@ -62,7 +62,7 @@ var createPatternObject = function (pattern) {
if (helper.isObject(pattern)) {
if (pattern.pattern && helper.isString(pattern.pattern)) {
return helper.isUrlAbsolute(pattern.pattern)
? new UrlPattern(pattern.pattern)
? new UrlPattern(pattern.pattern, pattern.type)
: new Pattern(
pattern.pattern,
pattern.served,
Expand Down
3 changes: 2 additions & 1 deletion lib/file-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,10 @@ List.prototype._refresh = function () {

var promise = Promise.map(this._patterns, function (patternObject) {
var pattern = patternObject.pattern
var type = patternObject.type

if (helper.isUrlAbsolute(pattern)) {
buckets.set(pattern, new Set([new Url(pattern)]))
buckets.set(pattern, new Set([new Url(pattern, type)]))
return Promise.resolve()
}

Expand Down
3 changes: 2 additions & 1 deletion lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
//
// Url object used for tracking files in `file-list.js`

var Url = function (path) {
var Url = function (path, type) {
this.path = path
this.type = type
this.isUrl = true
}

Expand Down
6 changes: 4 additions & 2 deletions test/unit/middleware/karma.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,14 @@ describe('middleware.karma', () => {
new MockFile('/first.css', 'sha007'),
new MockFile('/second.html', 'sha678'),
new MockFile('/third', 'sha111', 'css'),
new MockFile('/fourth', 'sha222', 'html')
new MockFile('/fourth', 'sha222', 'html'),
new Url('http://some.url.com/fifth', 'css'),
new Url('http://some.url.com/sixth', 'html')
])

response.once('end', () => {
expect(nextSpy).not.to.have.been.called
expect(response).to.beServedAs(200, 'CONTEXT\n<link type="text/css" href="/__proxy__/__karma__/absolute/first.css?sha007" rel="stylesheet">\n<link href="/__proxy__/__karma__/absolute/second.html?sha678" rel="import">\n<link type="text/css" href="/__proxy__/__karma__/absolute/third?sha111" rel="stylesheet">\n<link href="/__proxy__/__karma__/absolute/fourth?sha222" rel="import">')
expect(response).to.beServedAs(200, 'CONTEXT\n<link type="text/css" href="/__proxy__/__karma__/absolute/first.css?sha007" rel="stylesheet">\n<link href="/__proxy__/__karma__/absolute/second.html?sha678" rel="import">\n<link type="text/css" href="/__proxy__/__karma__/absolute/third?sha111" rel="stylesheet">\n<link href="/__proxy__/__karma__/absolute/fourth?sha222" rel="import">\n<link type="text/css" href="http://some.url.com/fifth" rel="stylesheet">\n<link href="http://some.url.com/sixth" rel="import">')
done()
})

Expand Down

0 comments on commit bd1f799

Please sign in to comment.