Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

partial tests cleanup & lint cleanup

  • Loading branch information...
commit 1489b18b50f47d0b41123c22365f740210d9dc05 1 parent 1bed95b
@puzrin puzrin authored
View
2  lib/mincer/engines/less_engine.js
@@ -56,7 +56,7 @@ LessEngine.prototype.initializeEngine = function () {
// helper to generate human-friendly errors.
// adapted version from original bin/less
-function less_error(ctx, options) {
+function less_error(ctx /*, options*/) {
var message = "";
var extract = ctx.extract;
var error = [];
View
2  lib/mincer/server.js
@@ -38,7 +38,6 @@
// stdlib
-var http = require('http');
var zlib = require('zlib');
var url = require('url');
var format = require('util').format;
@@ -50,7 +49,6 @@ var async = require('async');
// internal
var logger = require('./logger');
-var getter = require('./common').getter;
var prop = require('./common').prop;
var start_timer = require('./common').timer;
View
2  lib/mincer/template.js
@@ -218,7 +218,7 @@ Template.prototype.initializeEngine = function () {};
* - [[Template#acceptLazySource]]
* - [[Template#lazySource]]
**/
-Template.prototype.evaluate = function (context, locals, callback) {
+Template.prototype.evaluate = function (/*context, locals, callback*/) {
throw new Error((this.constructor.name || '') +
'#evaluate() is not implemented.');
};
View
12 package.json
@@ -26,10 +26,14 @@
"shellwords" : "~ 0.1.0"
},
"devDependencies" : {
- "mocha" : "*",
- "ejs" : "*",
- "eco" : "*",
- "coffee-script": "*"
+ "mocha" : "*",
+ "ejs" : "*",
+ "eco" : "*",
+ "coffee-script" : "*",
+ "haml-coffee" : "*",
+ "jade" : "*",
+ "less" : "*",
+ "stylus" : "*"
},
"engines" : { "node": ">= 0.6.0" }
}
View
30 test/eco.js
@@ -2,11 +2,12 @@
'use strict';
-var assert = require('assert'),
- path = require('path'),
- fs = require('fs'),
- ECO = require('eco'),
- Mincer = require('../lib/mincer');
+var assert = require('assert')
+ , path = require('path')
+ , fs = require('fs')
+ , vm = require('vm')
+ , ECO = require('eco')
+ , Mincer = require('../lib/mincer');
Mincer.logger.use(console); // provide logger backend
@@ -70,7 +71,6 @@ describe('Asset', function () {
describe('#compile() with JST', function () {
var assetName = 'templates/figure-eco', /* jst.eco */
compiledAsset,
- callable,
scope = {};
var context = {
id: 1,
@@ -84,37 +84,33 @@ describe('Asset', function () {
asset.compile(function (err, asset) {
if (err) { throw err; }
compiledAsset = asset;
- callable = new Function(asset.toString());
- callable.call(scope);
+ vm.runInNewContext(asset.toString(), scope, 'asset.vm');
done();
});
});
});
- it('should generate a JST object in the scope', function (done) {
+ it('should generate a JST object in the scope', function () {
assert.ok(scope.JST, 'a JST object must be generated, no JST found');
- done();
});
- it('should generate a template inside JST object', function (done) {
+ it('should generate a template inside JST object', function () {
assert.ok(scope.JST[assetName],
'a member named by the assetName without extension, must be ' +
'generated inside JST object, no JST[' + assetName + '] found.');
- done();
});
- it('should generate a template function inside JST object', function (done) {
+ /* That's invalid, because VM has another prototypes
+ it('should generate a template function inside JST object', function () {
assert.ok(scope.JST[assetName] instanceof Function,
'the member of JST object named by the assetName without extension ' +
'must be a function');
- done();
});
-
- it('should generate a template function that renders correctly', function (done) {
+ */
+ it('should generate a template function that renders correctly', function () {
var source = fs.readFileSync(compiledAsset.pathname, 'utf8').trim();
assert.equal(ECO.render(source, context),
scope.JST[assetName](context));
- done();
});
});
});
View
29 test/ejs.js
@@ -2,11 +2,12 @@
'use strict';
-var assert = require('assert'),
- path = require('path'),
- fs = require('fs'),
- EJS = require('ejs'),
- Mincer = require('../lib/mincer');
+var assert = require('assert')
+ , path = require('path')
+ , fs = require('fs')
+ , vm = require('vm')
+ , EJS = require('ejs')
+ , Mincer = require('../lib/mincer');
Mincer.logger.use(console); // provide logger backend
@@ -62,7 +63,6 @@ describe('Asset', function () {
describe('#compile() with JST', function () {
var assetName = 'templates/figure-ejs', /* jst.ejs */
compiledAsset,
- callable,
scope = {},
locals = {};
var context = {
@@ -77,33 +77,31 @@ describe('Asset', function () {
asset.compile(function (err, asset) {
if (err) { throw err; }
compiledAsset = asset;
- callable = new Function(asset.toString());
- callable.call(scope, locals);
+ vm.runInNewContext(asset.toString(), scope, 'asset.vm');
done();
});
});
});
- it('should generate a JST object in the scope', function (done) {
+ it('should generate a JST object in the scope', function () {
assert.ok(scope.JST, 'a JST object must be generated, no JST found');
- done();
});
- it('should generate a template inside JST object', function (done) {
+ it('should generate a template inside JST object', function () {
assert.ok(scope.JST[assetName],
'a member named by the assetName without extension, must be ' +
'generated inside JST object, no JST[' + assetName + '] found.');
- done();
});
- it('should generate a template function inside JST object', function (done) {
+ /* That's invalid, because VM has another prototypes
+ it('should generate a template function inside JST object', function () {
assert.ok(scope.JST[assetName] instanceof Function,
'the member of JST object named by the assetName without extension ' +
'must be a function');
- done();
});
+ */
- it('should generate a template function that renders correctly', function (done) {
+ it('should generate a template function that renders correctly', function () {
var source = fs.readFileSync(compiledAsset.pathname, 'utf8').trim(),
options = { scope: context,
locals: locals,
@@ -112,7 +110,6 @@ describe('Asset', function () {
assert.equal(EJS.render(source, options),
scope.JST[assetName].call(context, locals));
- done();
});
});
});
View
5 test/issues/.gitignore
@@ -1,5 +0,0 @@
-assets/
-Cakefile
-Cakefile.js
-*.compiled
-**/*.compiled
View
64 test/issues/issue-13.js
@@ -1,64 +0,0 @@
-'use strict';
-
-
-// stdlib
-var fs = require('fs');
-var path = require('path');
-
-
-// mincer
-var mincer = require('../..');
-
-
-////////////////////////////////////////////////////////////////////////////////
-
-
-var ASSETS_ROOT = path.join(__dirname, 'assets');
-
-
-function report(message, test) {
- console.log('[' + (test ? ' OK ' : 'FAIL') + '] ' + message);
-}
-
-
-function write(file, text) {
- fs.writeFileSync(path.join(ASSETS_ROOT, file), text);
-}
-
-
-////////////////////////////////////////////////////////////////////////////////
-
-
-var env = new (mincer.Environment)(__dirname);
-
-
-// append assets path
-env.appendPath('assets');
-
-
-// create assets dir if needed
-if (!fs.existsSync(ASSETS_ROOT)) {
- fs.mkdirSync(ASSETS_ROOT);
-}
-
-
-// write dummy asset
-write('foo.js', '/*' + Date.now() + '*/\n//= require bar');
-write('bar.js', '/*' + Date.now() + '*/');
-
-
-env.findAsset('foo').compile(function () {
- report('foo should be fresh', env.findAsset('foo').isFresh(env));
-
- setTimeout(function () {
- write('bar.js', '/*' + Date.now() + '*/');
- report('foo should be stale', !env.findAsset('foo').isFresh(env));
-
- env.findAsset('foo').compile(function () {
- report('foo should be fresh', env.findAsset('foo').isFresh(env));
-
- write('foo.js', '/*' + Date.now() + '*/\n//= require bar');
- report('foo should be stale', !env.findAsset('foo').isFresh(env));
- });
- }, 1234);
-});
View
33 test/issues/issue-38.js
@@ -1,33 +0,0 @@
-'use strict';
-
-
-// stdlib
-var fs = require('fs');
-var path = require('path');
-
-
-// mincer
-var mincer = require('../..');
-
-
-////////////////////////////////////////////////////////////////////////////////
-
-
-function report(message, test) {
- console.log('[' + (test ? ' OK ' : 'FAIL') + '] ' + message);
-}
-
-
-////////////////////////////////////////////////////////////////////////////////
-
-
-var env = new (mincer.Environment)(__dirname);
-
-
-// append assets path
-env.appendPath('issue-38');
-
-
-env.findAsset('rpc').compile(function (err, asset) {
- console.log(asset.toString());
-});
View
3  test/issues/issue-38/rpc/index.js
@@ -1,3 +0,0 @@
-//= require ./rpc
-
-var a = 1;
View
1  test/issues/issue-38/rpc/rpc.js
@@ -1 +0,0 @@
-var b = 2;
View
1  test/mocha.opts
@@ -0,0 +1 @@
+-R spec
View
37 test/template.js
@@ -2,11 +2,11 @@
'use strict';
-var assert = require('assert'),
- path = require('path'),
- fs = require('fs'),
- _ = require('underscore'),
- Mincer = require('../lib/mincer');
+var assert = require('assert')
+ , path = require('path')
+ , fs = require('fs')
+ , _ = require('underscore')
+ , Mincer = require('../lib/mincer');
Mincer.logger.use(console); // provide logger backend
@@ -89,30 +89,26 @@ function generateDescriptionWithJST(assetName) {
});
});
- it('should generate a JST object in the scope', function (done) {
+ it('should generate a JST object in the scope', function () {
assert.ok(scope.JST, 'a JST object must be generated, no JST found');
- done();
});
- it('should generate a template inside JST object', function (done) {
+ it('should generate a template inside JST object', function () {
assert.ok(scope.JST[assetName],
'a member named by the assetName without extension, must be ' +
'generated inside JST object, no JST[' + assetName + '] found.');
- done();
});
- it('should generate a template function inside JST object', function (done) {
+ it('should generate a template function inside JST object', function () {
assert.ok(scope.JST[assetName] instanceof Function,
'the member of JST object named by the assetName without extension ' +
'must be a function');
- done();
});
- it('should generate a template function that renders correctly', function (done) {
+ it('should generate a template function that renders correctly', function () {
var source = fs.readFileSync(compiledAsset.pathname, 'utf8').trim();
assert.equal(compileSource(source).call(context, locals).trim(),
scope.JST[assetName].call(context, locals).trim());
- done();
});
};
}
@@ -161,7 +157,7 @@ function generateDescription(engineExtension, engineFileName, returnLazySource)
});
if (returnLazySource) {
- it('should evaluate lazy', function (done) {
+ it('should evaluate lazy', function () {
assert.ok(!_.isString(result) && result instanceof EngineClass,
'should evaluate lazy, but a string was passed to the callback. ' +
'Expected the template object itself.');
@@ -169,37 +165,32 @@ function generateDescription(engineExtension, engineFileName, returnLazySource)
'a lazySource function must be generated in the template object');
assert.ok(result.toString && _.isFunction(result.toString),
'a toString method must be generated in the template object');
- done();
});
describe('#lazySource()', function () {
- it('should convert properly', function (done) {
+ it('should convert properly', function () {
assert.equal(myStrip(compiledSource.call(context[0], context[1])),
myStrip(result.lazySource.call(context[0], context[1])));
- done();
});
});
describe('#toString()', function () {
- it('should convert properly', function (done) {
+ it('should convert properly', function () {
assert.equal(myStrip(compiledSource.call(context[0], context[1])),
myStrip(result.toString()));
- done();
});
});
} else {
- it('should evaluate passing a string to the callback.', function (done) {
+ it('should evaluate passing a string to the callback.', function () {
assert.ok(_.isString(result),
'Passed result is ' + (typeof result) + '. String expected');
- done();
});
- it('should convert properly', function (done) {
+ it('should convert properly', function () {
var renderized = new Function('locals', 'return ' + result +
'.call(this, locals)');
assert.equal(myStrip(compiledSource.call(context[0], context[1])),
myStrip(renderized.call(context[0], context[1])));
- done();
});
}
});
Please sign in to comment.
Something went wrong with that request. Please try again.