Tests can now be via "jake test" or "npm test"

This commit is contained in:
Arnavion
2013-09-11 19:01:41 -07:00
parent 1a4a75ecd0
commit 04e2cd83d5
8 changed files with 117 additions and 40 deletions
+24
View File
@@ -429,3 +429,27 @@ task("clean", [], function () {
}
});
});
desc("Test");
task("test", [], function () {
var Mocha = require("mocha");
var mocha = new Mocha({
ui: "tdd"
});
fs.readdirSync("./tests/").filter(function (filename) {
if (filename.indexOf("test-") === 0) {
var extensionIndex = filename.lastIndexOf(".js");
if (extensionIndex !== -1 && extensionIndex === filename.length - ".js".length) {
return true;
}
}
return false;
}).forEach(function (filename) {
mocha.addFile("./tests/" + filename);
});
mocha.run();
// .\node_modules\.bin\mocha -u tdd tests/test*.js
});
+3 -1
View File
@@ -20,10 +20,12 @@
"url": "https://github.com/Arnavion/libjass"
},
"scripts": {
"postinstall": "jake clean && jake --trace"
"postinstall": "jake clean && jake --trace",
"test": "jake test"
},
"dependencies": {
"jake": "latest",
"mocha": "~1.12",
"pegjs": "0.7.0",
"typescript": "0.9.1-1",
"uglify-js": "~2"
+15 -34
View File
@@ -29,6 +29,21 @@ var suite = null;
var setup = null;
var test = null;
var require = function (name) {
if (name === "../libjass.js") {
return libjass;
}
else if (name === "assert") {
return assert;
}
else if (name === "./parser-test.js") {
return parserTest;
}
else {
throw new Error("Cannot require unmocked module: " + name);
}
};
(function () {
var Suite = function (name, parent) {
this.name = name;
@@ -206,40 +221,6 @@ var assert = new function () {
};
};
var parserTest = function (description, input, rule, expected) {
var result = test(description, function () {
var actual = null;
try {
actual = libjass.parser.parse(input, rule);
}
catch (parseException) {
if (expected === null) {
passed = true;
return;
}
else {
throw new Error("Expected parse to succeed but it threw an exception: " + parseException.message);
}
}
if (expected === null) {
throw new Error("Expected parse to fail.");
}
else if (actual === null) {
throw new Error("Parse failed without throwing an exception.");
}
assert.deepEqual(actual, expected);
});
result.customProperties = Object.create(null);
result.customProperties.input = input;
result.customProperties.rule = rule;
return result;
};
var Logger = function (outputDiv) {
var testDiv = document.createElement("div");
testDiv.className = "test";
+4 -3
View File
@@ -34,10 +34,11 @@
</style>
<script src="../libjass.js" />
<script src="index.js" />
<script src="parser-test.js" />
<script src="primitives.js" />
<script src="tags.js" />
<script src="miscellaneous.js" />
<script src="test-primitives.js" />
<script src="test-tags.js" />
<script src="test-miscellaneous.js" />
</head>
<body>
<div id="output" />
+60
View File
@@ -0,0 +1,60 @@
/**
* libjass
*
* https://github.com/Arnavion/libjass
*
* Copyright 2013 Arnav Singh
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var libjass = require("../libjass.js");
var assert = require("assert");
var parserTest = function (description, input, rule, expected) {
var result = test(description, function () {
var actual = null;
try {
actual = libjass.parser.parse(input, rule);
}
catch (parseException) {
if (expected === null) {
passed = true;
return;
}
else {
throw new Error("Expected parse to succeed but it threw an exception: " + parseException.message);
}
}
if (expected === null) {
throw new Error("Expected parse to fail.");
}
else if (actual === null) {
throw new Error("Parse failed without throwing an exception.");
}
assert.deepEqual(actual, expected);
});
result.customProperties = Object.create(null);
result.customProperties.input = input;
result.customProperties.rule = rule;
return result;
};
if (typeof module !== "undefined") {
module.exports = parserTest;
}
@@ -18,8 +18,11 @@
* limitations under the License.
*/
var libjass = require("../libjass.js");
var parserTest = require("./parser-test.js");
suite("Miscellaneous", function () {
parserTest("herkz", "{\\pos(311,4)\\blur0.8\\fs40\\bord0\\c&H3F171F&\\t(3820,3820,\\blur6}Chi{\\c&H422CB1&}tose {\\c&H3F171F&}Furu", "dialogue", [
parserTest("herkz", "{\\pos(311,4)\\blur0.8\\fs40\\bord0\\c&H3F171F&\\t(3820,3820,\\blur6}Chi{\\c&H422CB1&}tose {\\c&H3F171F&}Furu", "dialogueParts", [
new libjass.tags.Comment("\\pos(311,4)\\blur0.8\\fs40\\bord0\\c&H3F171F&\\t(3820,3820,\\blur6"),
new libjass.tags.Text("Chi"),
new libjass.tags.PrimaryColor(new libjass.tags.Color(177, 44, 66, 1)),
@@ -18,6 +18,9 @@
* limitations under the License.
*/
var libjass = require("../libjass.js");
var parserTest = require("./parser-test.js");
suite("Primitives", function () {
suite("Color", function () {
parserTest("BBGGRR", "&H3F171F&", "color", new libjass.tags.Color(31, 23, 63, 1));
+4 -1
View File
@@ -18,6 +18,9 @@
* limitations under the License.
*/
var libjass = require("../libjass.js");
var parserTest = require("./parser-test.js");
suite("Tags", function () {
suite("Bold tag - \\b", function () {
parserTest("True", "b1", "tag_b", new libjass.tags.Bold(true));
@@ -60,7 +63,7 @@ suite("Tags", function () {
parserTest("Enclosed tag", "{\\c&H3F171F&}", "enclosedTags", [new libjass.tags.PrimaryColor(new libjass.tags.Color(31, 23, 63, 1))]);
parserTest("Dialogue", "{\\c&H3F171F&}", "dialogue", [new libjass.tags.PrimaryColor(new libjass.tags.Color(31, 23, 63, 1))]);
parserTest("Dialogue", "{\\c&H3F171F&}", "dialogueParts", [new libjass.tags.PrimaryColor(new libjass.tags.Color(31, 23, 63, 1))]);
});
suite("Alpha tag - \\alpha", function () {