Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriangalliat committed Oct 5, 2014
1 parent af96a6c commit 7389a1e
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
/node_modules
/test/dest
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -35,7 +35,8 @@

"devDependencies": {
"eslint": "0.*",
"nodeunit": "0.*"
"nodeunit": "0.*",
"rimraf": "2.*"
},

"scripts": {
Expand Down
63 changes: 63 additions & 0 deletions test/index.js
@@ -0,0 +1,63 @@
'use strict';

var fs = require('fs');
var path = require('path');
var rimraf = require('rimraf');

var j = path.join;

var THEME = path.resolve(__dirname, 'theme');
var DEST = path.resolve(__dirname, 'dest');

process.on('uncaughtException', function (e) {
console.error(e.stack);
});

exports.render = function (test) {
test.expect(2);

rimraf(DEST, function () {
var themeleon = require('..')();

themeleon.use(j(THEME, 'mixin'), 'test');
themeleon.use({object: 'object'});

var theme = themeleon(THEME, function (t) {
test.ok(t.test === 'test', 'Node.js module mixin (function)');
test.ok(t.object === 'object', 'Object mixin (literal)');

t.copy('assets');
t.copy('assets', 'public');
});

theme(DEST, {}).done(test.done);
});
};

exports.copy = function (t) {
t.ok(
compare(
j(THEME, 'assets/css/main.css'),
j(DEST, 'assets/css/main.css')
),
'Copy an asset (same name)'
);

t.ok(
compare(
j(THEME, 'assets/css/main.css'),
j(DEST, 'public/css/main.css')
),
'Copy an asset (rename)'
);

t.done();
};

function compare(src, dest) {
return cat(src) === cat(dest);
}

function cat(file) {
return fs.readFileSync(file, 'utf8');
}
3 changes: 3 additions & 0 deletions test/theme/assets/css/main.css
@@ -0,0 +1,3 @@
body {
margin: 0;
}
7 changes: 7 additions & 0 deletions test/theme/mixin.js
@@ -0,0 +1,7 @@
'use strict';

module.exports = function (test) {
return {
test: test,
};
};

0 comments on commit 7389a1e

Please sign in to comment.