Add mocha tests
This commit is contained in:
@@ -38,7 +38,8 @@
|
|||||||
"acorn": "~0.6.0",
|
"acorn": "~0.6.0",
|
||||||
"escodegen": "~1.3.3",
|
"escodegen": "~1.3.3",
|
||||||
"esfuzz": "~0.3.1",
|
"esfuzz": "~0.3.1",
|
||||||
"estraverse": "~1.5.1"
|
"estraverse": "~1.5.1",
|
||||||
|
"mocha": "~2.3.4"
|
||||||
},
|
},
|
||||||
"browserify": {
|
"browserify": {
|
||||||
"transform": [
|
"transform": [
|
||||||
|
|||||||
29
test/mocha.js
Normal file
29
test/mocha.js
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
var Mocha = require('mocha'),
|
||||||
|
fs = require('fs'),
|
||||||
|
path = require('path');
|
||||||
|
|
||||||
|
// Instantiate a Mocha instance.
|
||||||
|
var mocha = new Mocha({});
|
||||||
|
|
||||||
|
var testDir = __dirname + '/mocha/';
|
||||||
|
|
||||||
|
// Add each .js file to the mocha instance
|
||||||
|
fs.readdirSync(testDir).filter(function(file){
|
||||||
|
// Only keep the .js files
|
||||||
|
return file.substr(-3) === '.js';
|
||||||
|
|
||||||
|
}).forEach(function(file){
|
||||||
|
mocha.addFile(
|
||||||
|
path.join(testDir, file)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = function() {
|
||||||
|
mocha.run(function(failures) {
|
||||||
|
if (failures !== 0) {
|
||||||
|
process.on('exit', function () {
|
||||||
|
process.exit(failures);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
29
test/mocha/string-literal.js
Normal file
29
test/mocha/string-literal.js
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
var UglifyJS = require('../../');
|
||||||
|
var assert = require("assert");
|
||||||
|
|
||||||
|
describe("String literals", function() {
|
||||||
|
it("Should throw syntax error if a string literal contains a newline", function() {
|
||||||
|
var inputs = [
|
||||||
|
"'\n'",
|
||||||
|
"'\r'",
|
||||||
|
'"\r\n"',
|
||||||
|
"'\u2028'",
|
||||||
|
'"\u2029"'
|
||||||
|
];
|
||||||
|
|
||||||
|
var test = function(input) {
|
||||||
|
return function() {
|
||||||
|
var ast = UglifyJS.parse(input);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var error = function(e) {
|
||||||
|
return e instanceof UglifyJS.JS_Parse_Error &&
|
||||||
|
e.message === "Unterminated string constant"
|
||||||
|
};
|
||||||
|
|
||||||
|
for (var input in inputs) {
|
||||||
|
assert.throws(test(inputs[input]), error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -16,6 +16,9 @@ if (failures) {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var mocha_tests = require("./mocha.js");
|
||||||
|
mocha_tests();
|
||||||
|
|
||||||
var run_sourcemaps_tests = require('./sourcemaps');
|
var run_sourcemaps_tests = require('./sourcemaps');
|
||||||
run_sourcemaps_tests();
|
run_sourcemaps_tests();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user