Improve testing
Summary: Move dom creation into katex.js so our tests can test non-dom things, and add some buildTree tests. Add some checks make utils.js work in node. Add support for jasmine-node, to allow for command line unit testing. Test Plan: - Make sure tests work, in both the browser and with `make test` - Make sure huxley screenshots didn't change Reviewers: alpert Reviewed By: alpert Differential Revision: http://phabricator.khanacademy.org/D13125
This commit is contained in:
parent
5cca3a299e
commit
403dca64ab
5
Makefile
5
Makefile
|
@ -1,4 +1,4 @@
|
||||||
.PHONY: build setup copy serve clean metrics
|
.PHONY: build setup copy serve clean metrics test
|
||||||
build: setup build/katex.min.js build/katex.min.css compress
|
build: setup build/katex.min.js build/katex.min.css compress
|
||||||
|
|
||||||
setup:
|
setup:
|
||||||
|
@ -27,6 +27,9 @@ compress: build/katex.min.js build/katex.min.css
|
||||||
serve:
|
serve:
|
||||||
node server.js
|
node server.js
|
||||||
|
|
||||||
|
test:
|
||||||
|
./node_modules/.bin/jasmine-node test/katex-spec.js
|
||||||
|
|
||||||
metrics:
|
metrics:
|
||||||
cd metrics && ./mapping.pl | ./extract_tfms.py | ./replace_line.py
|
cd metrics && ./mapping.pl | ./extract_tfms.py | ./replace_line.py
|
||||||
|
|
||||||
|
|
|
@ -708,7 +708,7 @@ var buildTree = function(tree) {
|
||||||
makeSpan(["katex-inner"], [topStrut, bottomStrut, span])
|
makeSpan(["katex-inner"], [topStrut, bottomStrut, span])
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return katexNode.toDOM();
|
return katexNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = buildTree;
|
module.exports = buildTree;
|
||||||
|
|
2
katex.js
2
katex.js
|
@ -8,7 +8,7 @@ var process = function(toParse, baseNode) {
|
||||||
utils.clearNode(baseNode);
|
utils.clearNode(baseNode);
|
||||||
|
|
||||||
var tree = parseTree(toParse);
|
var tree = parseTree(toParse);
|
||||||
var node = buildTree(tree);
|
var node = buildTree(tree).toDOM();
|
||||||
|
|
||||||
baseNode.appendChild(node);
|
baseNode.appendChild(node);
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,6 +14,10 @@
|
||||||
"less": "~1.4.2",
|
"less": "~1.4.2",
|
||||||
"uglify-js": "~2.4.15",
|
"uglify-js": "~2.4.15",
|
||||||
"clean-css": "~2.2.15",
|
"clean-css": "~2.2.15",
|
||||||
"huxley": "~0.7.4"
|
"huxley": "~0.7.4",
|
||||||
|
"jasmine-node": "git://github.com/mhevery/jasmine-node.git#Jasmine2.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "make test"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,9 +41,9 @@ app.get("/katex.css", function(req, res, next) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/test/katex-tests.js", function(req, res, next) {
|
app.get("/test/katex-spec.js", function(req, res, next) {
|
||||||
var b = browserify();
|
var b = browserify();
|
||||||
b.add("./test/katex-tests");
|
b.add("./test/katex-spec");
|
||||||
|
|
||||||
var stream = b.bundle({});
|
var stream = b.bundle({});
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,15 @@ var buildTree = require("../buildTree");
|
||||||
var parseTree = require("../parseTree");
|
var parseTree = require("../parseTree");
|
||||||
var ParseError = require("../ParseError");
|
var ParseError = require("../ParseError");
|
||||||
|
|
||||||
|
var getBuilt = function(expr) {
|
||||||
|
expect(expr).toBuild();
|
||||||
|
|
||||||
|
var built = buildTree(parseTree(expr));
|
||||||
|
|
||||||
|
// Remove the outer .katex and .katex-inner layers
|
||||||
|
return built.children[0].children[2].children;
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
jasmine.addMatchers({
|
jasmine.addMatchers({
|
||||||
toParse: function() {
|
toParse: function() {
|
||||||
|
@ -949,3 +958,31 @@ describe("A style change parser", function() {
|
||||||
expect(displayBody[0].value).toMatch("e");
|
expect(displayBody[0].value).toMatch("e");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("A bin builder", function() {
|
||||||
|
it("should create mbins normally", function() {
|
||||||
|
var built = getBuilt("x + y");
|
||||||
|
|
||||||
|
expect(built[1].classes).toContain("mbin");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should create ords when at the beginning of lists", function() {
|
||||||
|
var built = getBuilt("+ x");
|
||||||
|
|
||||||
|
expect(built[0].classes).toContain("mord");
|
||||||
|
expect(built[0].classes).not.toContain("mbin");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should create ords after some other objects", function() {
|
||||||
|
expect(getBuilt("x + + 2")[2].classes).toContain("mord");
|
||||||
|
expect(getBuilt("( + 2")[1].classes).toContain("mord");
|
||||||
|
expect(getBuilt("= + 2")[1].classes).toContain("mord");
|
||||||
|
expect(getBuilt("\\sin + 2")[1].classes).toContain("mord");
|
||||||
|
expect(getBuilt(", + 2")[1].classes).toContain("mord");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should correctly interact with color objects", function() {
|
||||||
|
expect(getBuilt("\\blue{x}+y")[1].classes).toContain("mbin");
|
||||||
|
expect(getBuilt("\\blue{x+}+y")[1].classes).toContain("mord");
|
||||||
|
});
|
||||||
|
});
|
|
@ -5,7 +5,7 @@
|
||||||
<script src="jasmine/jasmine-html.js"></script>
|
<script src="jasmine/jasmine-html.js"></script>
|
||||||
<script src="jasmine/boot.js"></script>
|
<script src="jasmine/boot.js"></script>
|
||||||
<link rel="stylesheet" href="jasmine/jasmine.css">
|
<link rel="stylesheet" href="jasmine/jasmine.css">
|
||||||
<script src="katex-tests.js"></script>
|
<script src="katex-spec.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
</body>
|
</body>
|
||||||
|
|
2
utils.js
2
utils.js
|
@ -21,6 +21,7 @@ var contains = function(list, elem) {
|
||||||
|
|
||||||
var setTextContent;
|
var setTextContent;
|
||||||
|
|
||||||
|
if (typeof document !== "undefined") {
|
||||||
var testNode = document.createElement("span");
|
var testNode = document.createElement("span");
|
||||||
if ("textContent" in testNode) {
|
if ("textContent" in testNode) {
|
||||||
setTextContent = function(node, text) {
|
setTextContent = function(node, text) {
|
||||||
|
@ -31,6 +32,7 @@ if ("textContent" in testNode) {
|
||||||
node.innerText = text;
|
node.innerText = text;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function clearNode(node) {
|
function clearNode(node) {
|
||||||
setTextContent(node, "");
|
setTextContent(node, "");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user