-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #153 from opentable/compress
js.gz + css.gz handling
- Loading branch information
Showing
6 changed files
with
144 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
'use strict'; | ||
|
||
var expect = require('chai').expect; | ||
|
||
describe('utils : getFileInfo', function(){ | ||
|
||
var getFileInfo = require('../../utils/get-file-info'); | ||
|
||
describe('when extension is .js', function(){ | ||
var fileInfo = getFileInfo('/path/file.js'); | ||
|
||
it('should return the correct myme type', function(){ | ||
expect(fileInfo.mimeType).to.equal('application/javascript'); | ||
}); | ||
|
||
it('should return the correct extension', function(){ | ||
expect(fileInfo.extname).to.equal('.js'); | ||
}); | ||
|
||
it('should recognise it is not a gzip', function(){ | ||
expect(fileInfo.gzip).to.be.false; | ||
}); | ||
}); | ||
|
||
describe('when extension is .js.gz', function(){ | ||
var fileInfo = getFileInfo('path/file.js.gz'); | ||
|
||
it('should return the correct myme type', function(){ | ||
expect(fileInfo.mimeType).to.equal('application/javascript'); | ||
}); | ||
|
||
it('should return the correct extension', function(){ | ||
expect(fileInfo.extname).to.equal('.js'); | ||
}); | ||
|
||
it('should recognise it is a gzip', function(){ | ||
expect(fileInfo.gzip).to.be.true; | ||
}); | ||
}); | ||
|
||
describe('when extension is .css.gz', function(){ | ||
var fileInfo = getFileInfo('path/file.css.gz'); | ||
|
||
it('should return the correct myme type', function(){ | ||
expect(fileInfo.mimeType).to.equal('text/css'); | ||
}); | ||
|
||
it('should return the correct extension', function(){ | ||
expect(fileInfo.extname).to.equal('.css'); | ||
}); | ||
|
||
it('should recognise it is a gzip', function(){ | ||
expect(fileInfo.gzip).to.be.true; | ||
}); | ||
}); | ||
|
||
describe('when extension is unknown', function(){ | ||
var fileInfo = getFileInfo('.heisenberg'); | ||
|
||
it('should return mime undefined', function(){ | ||
expect(fileInfo.mimeType).to.be.undefined; | ||
}); | ||
|
||
it('should handle it as not gzip', function(){ | ||
expect(fileInfo.gzip).to.be.false; | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
var path = require('path'); | ||
|
||
var getMimeType = require('./get-mime-type'); | ||
|
||
module.exports = function(filePath){ | ||
var ext = path.extname(filePath).toLowerCase(), | ||
isGzipped = false; | ||
|
||
if(ext === '.gz'){ | ||
isGzipped = true; | ||
ext = path.extname(filePath.slice(0, -3)).toLowerCase(); | ||
} | ||
|
||
return { | ||
gzip: isGzipped, | ||
extname: ext, | ||
mimeType: getMimeType(ext) | ||
}; | ||
}; |