Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial commit - node_modules and an example without promises
- Loading branch information
0 parents
commit bf44e20
Showing
21 changed files
with
3,675 additions
and
0 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,31 @@ | ||
if (typeof define !== 'function') { var define = require('amdefine')(module); } | ||
|
||
define(["fs", "path"], function(fs, path){ | ||
|
||
var defaultLang = "en", UTF = 'utf-8'; | ||
|
||
var getFn = function(lang, pageId) | ||
{ | ||
return path.join("testdata", pageId+"."+lang+".html"); | ||
}; | ||
|
||
var getHtml = function (lang, pageId, callback) | ||
{ | ||
fs.readFile(getFn(lang, pageId), UTF, function(e, data){ | ||
if (e != null) { | ||
if (lang == defaultLang) { | ||
callback(e, null); | ||
} else { | ||
getHtml(defaultLang, pageId, callback); | ||
} | ||
return; | ||
} | ||
callback(null, data); | ||
}); | ||
}; | ||
|
||
return { | ||
getHtml: getHtml | ||
}; | ||
|
||
}); |
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,69 @@ | ||
if (typeof define !== 'function') { var define = require('amdefine')(module); } | ||
|
||
define("00-withoutPromises.test", ["buster", "fs", "./00-withoutPromises"], function(buster, fs, html) { | ||
|
||
buster.testCase("00", { | ||
|
||
|
||
"setUp": function() | ||
{ | ||
this.fsStub = this.stub(fs, "readFile"); | ||
this.fsStub.withArgs("testdata/one.en.html", "utf-8").yields(null, "one english"); | ||
this.fsStub.withArgs("testdata/one.de.html", "utf-8").yields(null, "one german"); | ||
this.fsStub.withArgs("testdata/two.en.html", "utf-8").yields(null, "two english"); | ||
this.fsStub.withArgs("testdata/two.de.html", "utf-8").yields(new Error(), null); | ||
this.fsStub.withArgs("testdata/na.en.html", "utf-8").yields(new Error(), null); | ||
this.fsStub.withArgs("testdata/na.de.html", "utf-8").yields(new Error(), null); | ||
}, | ||
|
||
"should read file (de, exists)": function(done) | ||
{ | ||
html.getHtml("de", "one", function(e, data){ | ||
|
||
expect(this.fsStub).toHaveBeenCalledOnce(); | ||
expect(e).toBeNull(); | ||
expect(data).toEqual("one german"); | ||
done(); | ||
|
||
}.bind(this)); | ||
}, | ||
|
||
"should read file (de, fallback)": function(done) | ||
{ | ||
html.getHtml("de", "two", function(e, data){ | ||
|
||
expect(this.fsStub).toHaveBeenCalledTwice(); | ||
expect(e).toBeNull(); | ||
expect(data).toEqual("two english"); | ||
done(); | ||
|
||
}.bind(this)); | ||
}, | ||
|
||
"should return error (en, na)": function(done) | ||
{ | ||
html.getHtml("en", "na", function(e, data){ | ||
|
||
expect(this.fsStub).toHaveBeenCalledOnce(); | ||
expect(e).not.toBeNull(); | ||
expect(data).toBeNull(); | ||
done(); | ||
|
||
}.bind(this)); | ||
}, | ||
|
||
"should return error (de, na)": function(done) | ||
{ | ||
html.getHtml("de", "na", function(e, data){ | ||
|
||
expect(this.fsStub).toHaveBeenCalledTwice(); | ||
expect(e).not.toBeNull(); | ||
expect(data).toBeNull(); | ||
done(); | ||
|
||
}.bind(this)); | ||
} | ||
|
||
}); | ||
|
||
}); |
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,13 @@ | ||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | ||
Version 2, December 2004 | ||
|
||
Copyright (C) 2012 Dominykas Blyžė https://twitter.com/dymonaz | ||
|
||
Everyone is permitted to copy and distribute verbatim or modified | ||
copies of this license document, and changing it is allowed as long | ||
as the name is changed. | ||
|
||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | ||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | ||
|
||
0. You just DO WHAT THE FUCK YOU WANT TO. |
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 @@ | ||
A test project for dublinjs Oct/2012 meetup - examples with TDD and promises |
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,9 @@ | ||
var config = module.exports; | ||
|
||
config["Node tests"] = { | ||
rootPath:".", | ||
environment:"node", | ||
tests:[ | ||
"*.test.js" | ||
] | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.