Permalink
Browse files

Added simple module parse test to ensure I do not break shit later

  • Loading branch information...
1 parent fdf19f8 commit 913eab0b01de4969856d9d93347d2cc12baec937 @davglass committed Aug 23, 2012
Showing with 109 additions and 1 deletion.
  1. +2 −1 package.json
  2. +107 −0 tests/builder.js
View
3 package.json
@@ -17,6 +17,7 @@
},
"devDependencies": {
"selleck": "*",
+ "rimraf": "*",
"vows": "*"
},
"keywords": [
@@ -27,6 +28,6 @@
},
"scripts": {
"pretest": "jslint --node --sloppy ./lib/*.js ./lib/*/*.js",
- "test": "vows ./tests/*.js"
+ "test": "vows --spec ./tests/*.js"
}
}
View
107 tests/builder.js
@@ -0,0 +1,107 @@
+var vows = require('vows'),
+ assert = require('assert'),
+ path = require('path'),
+ fs = require('fs'),
+ Stack = require('../lib/stack').Stack,
+ spawn = require('child_process').spawn,
+ shifter = path.join(__dirname, '../bin/shifter'),
+ base = path.join(__dirname, 'assets/yql/'),
+ crypto = require('crypto'),
+ buildBase = path.join(base, 'build'),
+ buildXBase = path.join(base, 'build-expected'),
+ srcBase = path.join(base, 'src/yql'),
+ rimraf = require('rimraf');
+
+
+var tests = {
+ 'clean build': {
+ topic: function() {
+ rimraf(path.join(buildBase, 'yql'), this.callback);
+ },
+ 'should not have build dir': {
+ topic: function() {
+ var self = this;
+ fs.stat(path.join(buildBase, 'yql'), function(err) {
+ self.callback(null, err);
+ });
+ },
+ 'should not have build/yql': function(foo, err) {
+ assert.isNotNull(err);
+ assert.equal(err.code, 'ENOENT');
+ },
+ 'and should build YQL': {
+ topic: function() {
+ var child = spawn(shifter, [], {
+ cwd: srcBase
+ });
+
+ child.on('exit', this.callback);
+ },
+ 'and should create build dir': {
+ topic: function() {
+ fs.stat(path.join(buildBase, 'yql'), this.callback);
+ },
+ 'and should create build/yql': function(err, stat) {
+ assert.isNull(err);
+ assert.isTrue(stat.isDirectory());
+ }
+ },
+ 'and should produce same files': {
+ topic: function() {
+ var stack = new Stack();
+ var results = {
+ pre: {},
+ post: {}
+ },
+ self = this;
+
+ fs.readdir(path.join(buildBase, 'yql'), stack.add(function(err, files) {
+ files.forEach(function(file) {
+ (function(file) {
+ fs.readFile(path.join(buildBase, 'yql', file), stack.add(function(err, data) {
+ var shasum = crypto.createHash('sha1');
+ shasum.update(data);
+ var d = shasum.digest('hex');
+ results.post[file] = d;
+ }));
+ }(file));
+ });
+ }));
+
+ fs.readdir(path.join(buildXBase, 'yql'), stack.add(function(err, files) {
+ files.forEach(function(file) {
+ (function(file) {
+ fs.readFile(path.join(buildBase, 'yql', file), stack.add(function(err, data) {
+ var shasum = crypto.createHash('sha1');
+ shasum.update(data);
+ var d = shasum.digest('hex');
+ results.pre[file] = d;
+ }));
+ }(file));
+ });
+ }));
+
+ stack.done(function() {
+ self.callback(null, results);
+ });
+
+ },
+ 'and min should be same': function(err, results) {
+ assert.equal(results.pre['yql-min.js'], results.post['yql-min.js']);
+ },
+ 'and raw should be same': function(err, results) {
+ assert.equal(results.pre['yql.js'], results.post['yql.js']);
+ },
+ 'and debug should be same': function(err, results) {
+ assert.equal(results.pre['yql-debug.js'], results.post['yql-debug.js']);
+ },
+ 'and coverage should be same': function(err, results) {
+ assert.equal(results.pre['yql-coverage.js'], results.post['yql-coverage.js']);
+ }
+ }
+ }
+ }
+ }
+};
+
+vows.describe('building').addBatch(tests).export(module);

0 comments on commit 913eab0

Please sign in to comment.