Skip to content

Commit bd1f799

Browse files
josh18dignifiedquire
authored andcommitted
fix(middleware): add file type to absolute urls
1 parent fca048b commit bd1f799

4 files changed

Lines changed: 11 additions & 7 deletions

File tree

lib/config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ Pattern.prototype.compare = function (other) {
5050
return helper.mmComparePatternWeights(this.weight, other.weight)
5151
}
5252

53-
var UrlPattern = function (url) {
54-
Pattern.call(this, url, false, true, false, false)
53+
var UrlPattern = function (url, type) {
54+
Pattern.call(this, url, false, true, false, false, type)
5555
}
5656

5757
var createPatternObject = function (pattern) {
@@ -62,7 +62,7 @@ var createPatternObject = function (pattern) {
6262
if (helper.isObject(pattern)) {
6363
if (pattern.pattern && helper.isString(pattern.pattern)) {
6464
return helper.isUrlAbsolute(pattern.pattern)
65-
? new UrlPattern(pattern.pattern)
65+
? new UrlPattern(pattern.pattern, pattern.type)
6666
: new Pattern(
6767
pattern.pattern,
6868
pattern.served,

lib/file-list.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,10 @@ List.prototype._refresh = function () {
152152

153153
var promise = Promise.map(this._patterns, function (patternObject) {
154154
var pattern = patternObject.pattern
155+
var type = patternObject.type
155156

156157
if (helper.isUrlAbsolute(pattern)) {
157-
buckets.set(pattern, new Set([new Url(pattern)]))
158+
buckets.set(pattern, new Set([new Url(pattern, type)]))
158159
return Promise.resolve()
159160
}
160161

lib/url.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
//
44
// Url object used for tracking files in `file-list.js`
55

6-
var Url = function (path) {
6+
var Url = function (path, type) {
77
this.path = path
8+
this.type = type
89
this.isUrl = true
910
}
1011

test/unit/middleware/karma.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,14 @@ describe('middleware.karma', () => {
215215
new MockFile('/first.css', 'sha007'),
216216
new MockFile('/second.html', 'sha678'),
217217
new MockFile('/third', 'sha111', 'css'),
218-
new MockFile('/fourth', 'sha222', 'html')
218+
new MockFile('/fourth', 'sha222', 'html'),
219+
new Url('http://some.url.com/fifth', 'css'),
220+
new Url('http://some.url.com/sixth', 'html')
219221
])
220222

221223
response.once('end', () => {
222224
expect(nextSpy).not.to.have.been.called
223-
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">')
225+
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">')
224226
done()
225227
})
226228

0 commit comments

Comments
 (0)