[Pkg-javascript-commits] [uglifyjs] 81/190: Add mocha tests

Antonio Terceiro terceiro at moszumanska.debian.org
Sun Aug 7 23:17:15 UTC 2016


This is an automated email from the git hooks/post-receive script.

terceiro pushed a commit to annotated tag upstream/2.7.0
in repository uglifyjs.

commit 8c6af09ae014eb2370349fb7b419ee912abac64f
Author: Anthony Van de Gejuchte <anthonyvdgent at gmail.com>
Date:   Sun Dec 27 22:28:03 2015 +0100

    Add mocha tests
---
 package.json                 |  3 ++-
 test/mocha.js                | 29 +++++++++++++++++++++++++++++
 test/mocha/string-literal.js | 29 +++++++++++++++++++++++++++++
 test/run-tests.js            |  3 +++
 4 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/package.json b/package.json
index 6b0d2f4..bd4fb3e 100644
--- a/package.json
+++ b/package.json
@@ -38,7 +38,8 @@
     "acorn": "~0.6.0",
     "escodegen": "~1.3.3",
     "esfuzz": "~0.3.1",
-    "estraverse": "~1.5.1"
+    "estraverse": "~1.5.1",
+    "mocha": "~2.3.4"
   },
   "browserify": {
     "transform": [
diff --git a/test/mocha.js b/test/mocha.js
new file mode 100644
index 0000000..411f52c
--- /dev/null
+++ b/test/mocha.js
@@ -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);
+            });
+        }
+    });
+};
\ No newline at end of file
diff --git a/test/mocha/string-literal.js b/test/mocha/string-literal.js
new file mode 100644
index 0000000..6493363
--- /dev/null
+++ b/test/mocha/string-literal.js
@@ -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);
+        }
+    });
+});
\ No newline at end of file
diff --git a/test/run-tests.js b/test/run-tests.js
index 3ec04fd..b9a0f82 100755
--- a/test/run-tests.js
+++ b/test/run-tests.js
@@ -16,6 +16,9 @@ if (failures) {
     process.exit(1);
 }
 
+var mocha_tests = require("./mocha.js");
+mocha_tests();
+
 var run_sourcemaps_tests = require('./sourcemaps');
 run_sourcemaps_tests();
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git



More information about the Pkg-javascript-commits mailing list