This repository has been archived by the owner on Mar 17, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add filename template param add tests
- Loading branch information
Showing
7 changed files
with
152 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/node_modules | ||
/coverage |
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,4 @@ | ||
language: node_js | ||
node_js: | ||
- "0.10" | ||
- "0.11" |
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,27 @@ | ||
# appveyor file | ||
# http://www.appveyor.com/docs/appveyor-yml | ||
|
||
init: | ||
- git config --global core.autocrlf input | ||
|
||
# what combinations to test | ||
environment: | ||
matrix: | ||
- nodejs_version: 0.10 | ||
- nodejs_version: 0.11 | ||
|
||
# combinations having this can fail | ||
matrix: | ||
allow_failures: | ||
- nodejs_version: 0.11 | ||
|
||
install: | ||
- ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) | ||
- npm install | ||
|
||
build: off | ||
|
||
test_script: | ||
- node --version | ||
- npm --version | ||
- cmd: npm test |
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,57 @@ | ||
var should = require("should"); | ||
var path = require("path"); | ||
var fileLoader = require("../"); | ||
|
||
function run(resourcePath, query, content) { | ||
content = content || new Buffer("1234"); | ||
var result = null; | ||
var context = { | ||
resourcePath: resourcePath, | ||
query: "?" + query, | ||
options: { | ||
context: "/this/is/the/context" | ||
}, | ||
emitFile: function(url, content2) { | ||
content2.should.be.eql(content); | ||
result = url; | ||
} | ||
}; | ||
fileLoader.call(context, content); | ||
return result; | ||
} | ||
|
||
function test(excepted, resourcePath, query, content) { | ||
run(resourcePath, query, content).should.be.eql(excepted); | ||
} | ||
|
||
describe("correct-filename", function() { | ||
it("should process defaults correctly", function() { | ||
test("81dc9bdb52d04dc20036dbd8313ed055.txt", "/file.txt", ""); | ||
test("81dc9bdb52d04dc20036dbd8313ed055.png", "/file.png", ""); | ||
test("81dc9bdb52d04dc20036dbd8313ed055.txt", "file.txt", ""); | ||
test("81dc9bdb52d04dc20036dbd8313ed055.bin", "", ""); | ||
}); | ||
it("should process name correctly", function() { | ||
test("file.txt", "/file.txt", "name=[name].[ext]"); | ||
test("file.png", "/file.png", "name=[name].[ext]"); | ||
test("file.txt", "file.txt", "name=[name].[ext]"); | ||
test("file.bin", "", "name=[name].[ext]"); | ||
test("file", "/file.txt", "name=[name]"); | ||
test("81dc9bdb52d04dc20036dbd8313ed055", "/file.txt", "name=[hash]"); | ||
test("81dc9bdb52d04dc20036dbd8313ed055/file.txt", "/file.txt", "name=[hash]/[name].[ext]"); | ||
test("file.txt", "/this/is/the/context/file.txt", "name=[path][name].[ext]"); | ||
test("dir/file.txt", "/this/is/the/context/dir/file.txt", "name=[path][name].[ext]"); | ||
test("dir/sub/file.txt", "/this/is/the/context/dir/sub/file.txt", "name=[path][name].[ext]"); | ||
test("_/_/dir/sub/file.txt", "/this/is/dir/sub/file.txt", "name=[path][name].[ext]"); | ||
test("dir/sub/file.txt", "/this/is/dir/sub/file.txt", "name=[path][name].[ext]&context=/this/is"); | ||
}); | ||
it("should process hash correctly", function() { | ||
test("d93591bdf7860e1e4ee2fca799911215.txt", "/file.txt", "", new Buffer("4321")); | ||
}); | ||
it("should process hash options correctly", function() { | ||
test("81dc9.txt", "/file.txt", "size=5"); | ||
test("d4045.txt", "/file.txt", "hash=sha512&size=5"); | ||
test("gdyb21LQTcIANtvYMT7QVQ==.txt", "/file.txt", "digest=base64"); | ||
}); | ||
|
||
}); |