Skip to content

Commit

Permalink
initial commit - node_modules and an example without promises
Browse files Browse the repository at this point in the history
  • Loading branch information
dominykas committed Oct 1, 2012
0 parents commit bf44e20
Show file tree
Hide file tree
Showing 21 changed files with 3,675 additions and 0 deletions.
31 changes: 31 additions & 0 deletions 00-withoutPromises.js
@@ -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
};

});
69 changes: 69 additions & 0 deletions 00-withoutPromises.test.js
@@ -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));
}

});

});
13 changes: 13 additions & 0 deletions LICENSE
@@ -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.
1 change: 1 addition & 0 deletions README
@@ -0,0 +1 @@
A test project for dublinjs Oct/2012 meetup - examples with TDD and promises
9 changes: 9 additions & 0 deletions buster.js
@@ -0,0 +1,9 @@
var config = module.exports;

config["Node tests"] = {
rootPath:".",
environment:"node",
tests:[
"*.test.js"
]
};
2 changes: 2 additions & 0 deletions node_modules/amdefine/.npmignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions node_modules/amdefine/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

200 changes: 200 additions & 0 deletions node_modules/amdefine/amdefine.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bf44e20

Please sign in to comment.