mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-04 18:58:39 +00:00
Allow test/lint scripts to run without requiring make (#878)
This commit is contained in:
3
.eslintignore
Normal file
3
.eslintignore
Normal file
@@ -0,0 +1,3 @@
|
||||
**/node_modules/*
|
||||
build/*
|
||||
dist/*
|
12
.eslintrc
12
.eslintrc
@@ -70,18 +70,6 @@
|
||||
"valid-jsdoc": 0,
|
||||
"require-jsdoc": 0
|
||||
},
|
||||
"ecmaFeatures": {
|
||||
"arrowFunctions": true,
|
||||
"blockBindings": true,
|
||||
"classes": true,
|
||||
"destructuring": true,
|
||||
"experimentalObjectRestSpread": true,
|
||||
"forOf": true,
|
||||
"jsx": true,
|
||||
"restParams": true,
|
||||
"spread": true,
|
||||
"templateStrings": true
|
||||
},
|
||||
"env": {
|
||||
"es6": true,
|
||||
"node": true,
|
||||
|
@@ -57,8 +57,8 @@ single file. The goal is to have all functions use this new system.
|
||||
|
||||
## Testing
|
||||
|
||||
Local testing can be done by running the node server in `server.js`. Run `make
|
||||
setup` to install dependencies, and then `make serve` to start the server.
|
||||
Local testing can be done by running the node server in `server.js`. Run
|
||||
`npm install` to install dependencies, and then `npm start` to start the server.
|
||||
|
||||
This will host an interactive editor at
|
||||
[http://localhost:7936/](http://localhost:7936/) to play around with and test
|
||||
@@ -68,7 +68,7 @@ changes.
|
||||
|
||||
The JavaScript parser and some of the HTML and MathML tree
|
||||
builders are tested with Jest. These tests can be run using node with
|
||||
`make test`. If you need to debug the tests see
|
||||
`npm run jest`. If you need to debug the tests see
|
||||
[https://facebook.github.io/jest/docs/troubleshooting.html](https://facebook.github.io/jest/docs/troubleshooting.html)
|
||||
|
||||
The interactive editor can also be used for debugging tests in the browser by
|
||||
|
17
Makefile
17
Makefile
@@ -1,5 +1,5 @@
|
||||
.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
|
||||
.PHONY: build dist lint setup copy serve clean metrics test coverage zip contrib flow
|
||||
build: test build/katex.min.js build/katex.min.css contrib zip compress
|
||||
|
||||
ifeq ($(KATEX_DIST),skip)
|
||||
|
||||
@@ -14,6 +14,7 @@ dist: build
|
||||
endif
|
||||
|
||||
NODE := node # pass NODE=nodejs on Debian without package nodejs-legacy
|
||||
NPM := npm
|
||||
NODECHK := $(shell $(NODE) ./check-node-version.js)
|
||||
ifneq ($(NODECHK),OK)
|
||||
$(error "Node not found or wrong version")
|
||||
@@ -36,8 +37,8 @@ $(NIS) setup: package.json
|
||||
KATEX_DIST=skip npm install # dependencies only, don't build
|
||||
@touch $(NIS)
|
||||
|
||||
lint: $(NIS) katex.js server.js cli.js $(wildcard src/*.js) $(wildcard test/*.js) $(wildcard contrib/*/*.js) $(wildcard dockers/*/*.js)
|
||||
./node_modules/.bin/eslint $(filter-out %.stamp,$^)
|
||||
lint: $(NIS)
|
||||
$(NPM) run lint
|
||||
|
||||
build/katex.js: katex.js $(wildcard src/*.js) $(NIS)
|
||||
$(BROWSERIFY) -t [ babelify ] $< --standalone katex > $@
|
||||
@@ -101,16 +102,16 @@ compress: build/katex.min.js build/katex.min.css
|
||||
printf "Total: %6d\n" "$${TOTAL}"
|
||||
|
||||
serve: $(NIS)
|
||||
$(NODE) server.js
|
||||
$(NPM) start
|
||||
|
||||
flow: $(NIS)
|
||||
node_modules/.bin/flow
|
||||
$(NPM) run flow
|
||||
|
||||
test: $(NIS)
|
||||
node_modules/.bin/jest
|
||||
$(NPM) test
|
||||
|
||||
coverage: $(NIS)
|
||||
node_modules/.bin/jest --coverage
|
||||
$(NPM) run coverage
|
||||
|
||||
PERL=perl
|
||||
PYTHON=$(shell python2 --version >/dev/null 2>&1 && echo python2 || echo python)
|
||||
|
11
package.json
11
package.json
@@ -25,6 +25,7 @@
|
||||
"babel-register": "^6.24.0",
|
||||
"babelify": "^7.3.0",
|
||||
"browserify": "^13.3.0",
|
||||
"check-dependencies": "^1.1.0",
|
||||
"clean-css": "^3.4.23",
|
||||
"eslint": "^4.6.1",
|
||||
"eslint-plugin-flowtype": "^2.35.1",
|
||||
@@ -47,9 +48,13 @@
|
||||
},
|
||||
"bin": "cli.js",
|
||||
"scripts": {
|
||||
"lint": "make lint",
|
||||
"test": "make lint flow test",
|
||||
"prepublish": "make NIS= dist"
|
||||
"lint": "eslint katex.js server.js cli.js src test contrib dockers",
|
||||
"flow": "flow",
|
||||
"jest": "jest",
|
||||
"coverage": "jest --coverage",
|
||||
"test": "check-dependencies && npm run lint && npm run flow && npm run jest",
|
||||
"start": "check-dependencies && node server.js",
|
||||
"prepublishOnly": "make NIS= dist"
|
||||
},
|
||||
"pre-commit": [
|
||||
"lint"
|
||||
|
@@ -55,7 +55,7 @@ defineFunction({
|
||||
// The steps taken here are similar to the html version.
|
||||
let output = [];
|
||||
if (group.value.value.length > 0) {
|
||||
let temp = mml.buildExpression(group.value.value, options);
|
||||
const temp = mml.buildExpression(group.value.value, options);
|
||||
|
||||
let word = "";
|
||||
for (let i = 0; i < temp.length; i++) {
|
||||
|
@@ -7,27 +7,29 @@
|
||||
* The export of this module is simply a dictionary of test cases.
|
||||
*/
|
||||
|
||||
var fs = require("fs");
|
||||
var jsyaml = require("js-yaml");
|
||||
var querystring = require("querystring");
|
||||
const fs = require("fs");
|
||||
const jsyaml = require("js-yaml");
|
||||
const querystring = require("querystring");
|
||||
|
||||
var queryKeys = ["tex", "pre", "post", "display", "noThrow", "errorColor"];
|
||||
var dict = fs.readFileSync(require.resolve("./ss_data.yaml"));
|
||||
const queryKeys = ["tex", "pre", "post", "display", "noThrow", "errorColor"];
|
||||
let dict = fs.readFileSync(require.resolve("./ss_data.yaml"));
|
||||
dict = jsyaml.safeLoad(dict);
|
||||
for (var key in dict) {
|
||||
var itm = dict[key];
|
||||
if (typeof itm === "string") {
|
||||
itm = dict[key] = { tex: itm };
|
||||
}
|
||||
var query = {};
|
||||
queryKeys.forEach(function(key) {
|
||||
if (itm.hasOwnProperty(key)) {
|
||||
query[key] = itm[key];
|
||||
for (const key in dict) {
|
||||
if (dict.hasOwnProperty(key)) {
|
||||
let itm = dict[key];
|
||||
if (typeof itm === "string") {
|
||||
itm = dict[key] = { tex: itm };
|
||||
}
|
||||
const query = {};
|
||||
queryKeys.forEach(function(key) {
|
||||
if (itm.hasOwnProperty(key)) {
|
||||
query[key] = itm[key];
|
||||
}
|
||||
});
|
||||
itm.query = querystring.stringify(query);
|
||||
if (itm.macros) {
|
||||
itm.query += "&" + querystring.stringify(itm.macros);
|
||||
}
|
||||
});
|
||||
itm.query = querystring.stringify(query);
|
||||
if (itm.macros) {
|
||||
itm.query += "&" + querystring.stringify(itm.macros);
|
||||
}
|
||||
}
|
||||
module.exports = dict;
|
||||
|
Reference in New Issue
Block a user