mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-05 03:08:40 +00:00
Switch from jasmine to jest (#747)
Summary: The reasons for switching to jest: - easy snapshot testing so that we can easily verify the structure of the parse tree and MathML tree - easy compilation of ES6 features for tests as we continue to expand our use of ES6 Test Plan: - npm test
This commit is contained in:
committed by
Erik Demaine
parent
4480f2c987
commit
361c500a7f
1
.gitignore
vendored
1
.gitignore
vendored
@@ -12,3 +12,4 @@ diff.png
|
|||||||
/test/symgroups.log
|
/test/symgroups.log
|
||||||
/test/symgroups.pdf
|
/test/symgroups.pdf
|
||||||
/test/screenshotter/unicode-fonts
|
/test/screenshotter/unicode-fonts
|
||||||
|
coverage/
|
||||||
|
@@ -60,18 +60,22 @@ This will host an interactive editor at
|
|||||||
[http://localhost:7936/](http://localhost:7936/) to play around with and test
|
[http://localhost:7936/](http://localhost:7936/) to play around with and test
|
||||||
changes.
|
changes.
|
||||||
|
|
||||||
#### Jasmine tests
|
#### Jest tests
|
||||||
|
|
||||||
The JavaScript parser and some of the tree
|
The JavaScript parser and some of the HTML and MathML tree
|
||||||
builder is tested with Jasmine. These tests can be run either using node with
|
builders are tested with Jest. These tests can be run using node with
|
||||||
`make test`, or in the browser by visiting
|
`make test`. If you need to debug the tests see
|
||||||
[http://localhost:7936/test/test.html](http://localhost:7936/test/test.html).
|
[https://facebook.github.io/jest/docs/troubleshooting.html](https://facebook.github.io/jest/docs/troubleshooting.html)
|
||||||
|
|
||||||
The Jasmine tests should be run after every change, even the addition of small
|
The interactive editor can also be used for debugging tests in the browser by
|
||||||
|
copy/pasting the test case to be debugged into the editor. The permalink option
|
||||||
|
can come in really useful when doing repeated runs of the same test case.
|
||||||
|
|
||||||
|
The Jest tests should be run after every change, even the addition of small
|
||||||
symbols. However, [Travis](https://travis-ci.org/Khan/KaTeX/) will run these
|
symbols. However, [Travis](https://travis-ci.org/Khan/KaTeX/) will run these
|
||||||
tests when you submit a pull request, in case you forget.
|
tests when you submit a pull request, in case you forget.
|
||||||
|
|
||||||
If you make any changes to Parser.js, add Jasmine tests to ensure they work.
|
If you make any changes to Parser.js, add Jest tests to ensure they work.
|
||||||
|
|
||||||
#### Screenshot tests
|
#### Screenshot tests
|
||||||
|
|
||||||
|
7
Makefile
7
Makefile
@@ -1,4 +1,4 @@
|
|||||||
.PHONY: build dist lint setup copy serve clean metrics test zip contrib
|
.PHONY: build dist lint setup copy serve clean metrics test coverage zip contrib
|
||||||
build: lint build/katex.min.js build/katex.min.css contrib zip compress
|
build: lint build/katex.min.js build/katex.min.css contrib zip compress
|
||||||
|
|
||||||
ifeq ($(KATEX_DIST),skip)
|
ifeq ($(KATEX_DIST),skip)
|
||||||
@@ -101,7 +101,10 @@ serve: $(NIS)
|
|||||||
$(NODE) server.js
|
$(NODE) server.js
|
||||||
|
|
||||||
test: $(NIS)
|
test: $(NIS)
|
||||||
JASMINE_CONFIG_PATH=test/jasmine.json node_modules/.bin/jasmine
|
node_modules/.bin/jest
|
||||||
|
|
||||||
|
coverage: $(NIS)
|
||||||
|
node_modules/.bin/jest --coverage
|
||||||
|
|
||||||
PERL=perl
|
PERL=perl
|
||||||
PYTHON=$(shell python2 --version >/dev/null 2>&1 && echo python2 || echo python)
|
PYTHON=$(shell python2 --version >/dev/null 2>&1 && echo python2 || echo python)
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
/* global beforeEach: false */
|
/* global beforeEach: false */
|
||||||
/* global jasmine: false */
|
|
||||||
/* global expect: false */
|
/* global expect: false */
|
||||||
/* global it: false */
|
/* global it: false */
|
||||||
/* global describe: false */
|
/* global describe: false */
|
||||||
@@ -7,10 +6,8 @@
|
|||||||
const splitAtDelimiters = require("./splitAtDelimiters");
|
const splitAtDelimiters = require("./splitAtDelimiters");
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
jasmine.addMatchers({
|
expect.extend({
|
||||||
toSplitInto: function() {
|
toSplitInto: function(actual, left, right, result) {
|
||||||
return {
|
|
||||||
compare: function(actual, left, right, result) {
|
|
||||||
const message = {
|
const message = {
|
||||||
pass: true,
|
pass: true,
|
||||||
message: "'" + actual + "' split correctly",
|
message: "'" + actual + "' split correctly",
|
||||||
@@ -60,8 +57,6 @@ beforeEach(function() {
|
|||||||
|
|
||||||
return message;
|
return message;
|
||||||
},
|
},
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -4,6 +4,3 @@
|
|||||||
build/**
|
build/**
|
||||||
node_modules/**
|
node_modules/**
|
||||||
dist/**
|
dist/**
|
||||||
|
|
||||||
# Third party code
|
|
||||||
test/jasmine/**
|
|
||||||
|
12
package.json
12
package.json
@@ -16,6 +16,7 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-eslint": "^7.2.0",
|
"babel-eslint": "^7.2.0",
|
||||||
|
"babel-jest": "^20.0.3",
|
||||||
"babel-plugin-transform-class-properties": "^6.23.0",
|
"babel-plugin-transform-class-properties": "^6.23.0",
|
||||||
"babel-plugin-transform-runtime": "^6.15.0",
|
"babel-plugin-transform-runtime": "^6.15.0",
|
||||||
"babel-preset-es2015": "^6.18.0",
|
"babel-preset-es2015": "^6.18.0",
|
||||||
@@ -26,8 +27,7 @@
|
|||||||
"eslint": "^3.13.0",
|
"eslint": "^3.13.0",
|
||||||
"express": "^4.14.0",
|
"express": "^4.14.0",
|
||||||
"glob": "^7.1.1",
|
"glob": "^7.1.1",
|
||||||
"jasmine": "^2.3.2",
|
"jest": "^20.0.4",
|
||||||
"jasmine-core": "^2.3.4",
|
|
||||||
"js-yaml": "^3.3.1",
|
"js-yaml": "^3.3.1",
|
||||||
"jspngopt": "^0.2.0",
|
"jspngopt": "^0.2.0",
|
||||||
"less": "~2.7.1",
|
"less": "~2.7.1",
|
||||||
@@ -46,5 +46,13 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"match-at": "^0.1.0"
|
"match-at": "^0.1.0"
|
||||||
|
},
|
||||||
|
"jest": {
|
||||||
|
"testMatch": [
|
||||||
|
"**/test/*-spec.js"
|
||||||
|
],
|
||||||
|
"transform": {
|
||||||
|
"^.+\\.js$": "babel-jest"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -54,8 +54,6 @@ function getStatic(url, file) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
browserified("/katex.js", "katex", "katex");
|
browserified("/katex.js", "katex", "katex");
|
||||||
app.use("/test/jasmine", express.static(path.dirname(
|
|
||||||
require.resolve("jasmine-core/lib/jasmine-core/jasmine.js"))));
|
|
||||||
browserified("/test/katex-spec.js", "test/*[Ss]pec.js");
|
browserified("/test/katex-spec.js", "test/*[Ss]pec.js");
|
||||||
browserified(
|
browserified(
|
||||||
"/contrib/auto-render/auto-render.js",
|
"/contrib/auto-render/auto-render.js",
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
/* global beforeEach: false */
|
/* global beforeEach: false */
|
||||||
/* global jasmine: false */
|
|
||||||
/* global expect: false */
|
/* global expect: false */
|
||||||
/* global it: false */
|
/* global it: false */
|
||||||
/* global describe: false */
|
/* global describe: false */
|
||||||
@@ -10,11 +9,10 @@ import Settings from "../src/Settings";
|
|||||||
const defaultSettings = new Settings({});
|
const defaultSettings = new Settings({});
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
jasmine.addMatchers({
|
|
||||||
toFailWithParseError: function(util, customEqualityTesters) {
|
|
||||||
const prefix = "KaTeX parse error: ";
|
const prefix = "KaTeX parse error: ";
|
||||||
return {
|
|
||||||
compare: function(actual, expected) {
|
expect.extend({
|
||||||
|
toFailWithParseError: function(actual, expected) {
|
||||||
try {
|
try {
|
||||||
parseTree(actual, defaultSettings);
|
parseTree(actual, defaultSettings);
|
||||||
return {
|
return {
|
||||||
@@ -53,8 +51,6 @@ beforeEach(function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -1,11 +0,0 @@
|
|||||||
{
|
|
||||||
"spec_dir": ".",
|
|
||||||
"spec_files": [
|
|
||||||
"test/**/*[sS]pec.js",
|
|
||||||
"contrib/**/*[sS]pec.js"
|
|
||||||
],
|
|
||||||
"helpers": [
|
|
||||||
"helpers/**/*.js",
|
|
||||||
"node_modules/babel-core/register.js"
|
|
||||||
]
|
|
||||||
}
|
|
@@ -1,6 +1,5 @@
|
|||||||
/* eslint max-len:0 */
|
/* eslint max-len:0 */
|
||||||
/* global beforeEach: false */
|
/* global beforeEach: false */
|
||||||
/* global jasmine: false */
|
|
||||||
/* global expect: false */
|
/* global expect: false */
|
||||||
/* global it: false */
|
/* global it: false */
|
||||||
/* global describe: false */
|
/* global describe: false */
|
||||||
@@ -88,11 +87,8 @@ const parseAndSetResult = function(expr, result, settings) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
jasmine.addMatchers({
|
expect.extend({
|
||||||
|
toParse: function(actual, settings) {
|
||||||
toParse: function() {
|
|
||||||
return {
|
|
||||||
compare: function(actual, settings) {
|
|
||||||
const usedSettings = settings ? settings : defaultSettings;
|
const usedSettings = settings ? settings : defaultSettings;
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
@@ -102,12 +98,8 @@ beforeEach(function() {
|
|||||||
parseAndSetResult(actual, result, usedSettings);
|
parseAndSetResult(actual, result, usedSettings);
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
toNotParse: function() {
|
toNotParse: function(actual, settings) {
|
||||||
return {
|
|
||||||
compare: function(actual, settings) {
|
|
||||||
const usedSettings = settings ? settings : defaultSettings;
|
const usedSettings = settings ? settings : defaultSettings;
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
@@ -131,12 +123,8 @@ beforeEach(function() {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
toBuild: function() {
|
toBuild: function(actual, settings) {
|
||||||
return {
|
|
||||||
compare: function(actual, settings) {
|
|
||||||
const usedSettings = settings ? settings : defaultSettings;
|
const usedSettings = settings ? settings : defaultSettings;
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
@@ -161,12 +149,8 @@ beforeEach(function() {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
toParseLike: function(util, baton) {
|
toParseLike: function(actual, expected, settings) {
|
||||||
return {
|
|
||||||
compare: function(actual, expected, settings) {
|
|
||||||
const usedSettings = settings ? settings : defaultSettings;
|
const usedSettings = settings ? settings : defaultSettings;
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
@@ -185,18 +169,17 @@ beforeEach(function() {
|
|||||||
if (!expectedTree) {
|
if (!expectedTree) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
stripPositions(actualTree);
|
stripPositions(actualTree);
|
||||||
stripPositions(expectedTree);
|
stripPositions(expectedTree);
|
||||||
if (!util.equals(actualTree, expectedTree, baton)) {
|
|
||||||
|
if (JSON.stringify(actualTree) !== JSON.stringify(expectedTree)) {
|
||||||
result.pass = false;
|
result.pass = false;
|
||||||
result.message = "Parse trees of '" + actual +
|
result.message = "Parse trees of '" + actual +
|
||||||
"' and '" + expected + "' are not equivalent";
|
"' and '" + expected + "' are not equivalent";
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -1,12 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<script src="jasmine/jasmine.js"></script>
|
|
||||||
<script src="jasmine/jasmine-html.js"></script>
|
|
||||||
<script src="jasmine/boot.js"></script>
|
|
||||||
<link rel="stylesheet" href="jasmine/jasmine.css">
|
|
||||||
<script src="katex-spec.js"></script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@@ -1,6 +1,5 @@
|
|||||||
/* eslint max-len:0 */
|
/* eslint max-len:0 */
|
||||||
/* global beforeEach: false */
|
/* global beforeEach: false */
|
||||||
/* global jasmine: false */
|
|
||||||
/* global expect: false */
|
/* global expect: false */
|
||||||
/* global it: false */
|
/* global it: false */
|
||||||
/* global describe: false */
|
/* global describe: false */
|
||||||
@@ -27,11 +26,9 @@ const parseAndSetResult = function(expr, result, settings) {
|
|||||||
|
|
||||||
describe("unicode", function() {
|
describe("unicode", function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
jasmine.addMatchers({
|
expect.extend({
|
||||||
|
|
||||||
toParse: function() {
|
toParse: function(actual, settings) {
|
||||||
return {
|
|
||||||
compare: function(actual, settings) {
|
|
||||||
const usedSettings = settings ? settings : defaultSettings;
|
const usedSettings = settings ? settings : defaultSettings;
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
@@ -41,12 +38,8 @@ describe("unicode", function() {
|
|||||||
parseAndSetResult(actual, result, usedSettings);
|
parseAndSetResult(actual, result, usedSettings);
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
toNotParse: function() {
|
toNotParse: function(actual, settings) {
|
||||||
return {
|
|
||||||
compare: function(actual, settings) {
|
|
||||||
const usedSettings = settings ? settings : defaultSettings;
|
const usedSettings = settings ? settings : defaultSettings;
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
@@ -70,8 +63,6 @@ describe("unicode", function() {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user