Allow test/lint scripts to run without requiring make (#878)

This commit is contained in:
Kevin Barabash
2017-09-13 10:01:39 -04:00
committed by GitHub
parent 4f63909d08
commit dbc5a74ebd
7 changed files with 44 additions and 45 deletions

3
.eslintignore Normal file
View File

@@ -0,0 +1,3 @@
**/node_modules/*
build/*
dist/*

View File

@@ -70,18 +70,6 @@
"valid-jsdoc": 0, "valid-jsdoc": 0,
"require-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": { "env": {
"es6": true, "es6": true,
"node": true, "node": true,

View File

@@ -57,8 +57,8 @@ single file. The goal is to have all functions use this new system.
## Testing ## Testing
Local testing can be done by running the node server in `server.js`. Run `make Local testing can be done by running the node server in `server.js`. Run
setup` to install dependencies, and then `make serve` to start the server. `npm install` to install dependencies, and then `npm start` to start the server.
This will host an interactive editor at 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
@@ -68,7 +68,7 @@ changes.
The JavaScript parser and some of the HTML and MathML tree The JavaScript parser and some of the HTML and MathML tree
builders are tested with Jest. These tests can be run using node with 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) [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 The interactive editor can also be used for debugging tests in the browser by

View File

@@ -1,5 +1,5 @@
.PHONY: build dist lint setup copy serve clean metrics test coverage zip contrib .PHONY: build dist lint setup copy serve clean metrics test coverage zip contrib flow
build: lint build/katex.min.js build/katex.min.css contrib zip compress build: test build/katex.min.js build/katex.min.css contrib zip compress
ifeq ($(KATEX_DIST),skip) ifeq ($(KATEX_DIST),skip)
@@ -14,6 +14,7 @@ dist: build
endif endif
NODE := node # pass NODE=nodejs on Debian without package nodejs-legacy NODE := node # pass NODE=nodejs on Debian without package nodejs-legacy
NPM := npm
NODECHK := $(shell $(NODE) ./check-node-version.js) NODECHK := $(shell $(NODE) ./check-node-version.js)
ifneq ($(NODECHK),OK) ifneq ($(NODECHK),OK)
$(error "Node not found or wrong version") $(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 KATEX_DIST=skip npm install # dependencies only, don't build
@touch $(NIS) @touch $(NIS)
lint: $(NIS) katex.js server.js cli.js $(wildcard src/*.js) $(wildcard test/*.js) $(wildcard contrib/*/*.js) $(wildcard dockers/*/*.js) lint: $(NIS)
./node_modules/.bin/eslint $(filter-out %.stamp,$^) $(NPM) run lint
build/katex.js: katex.js $(wildcard src/*.js) $(NIS) build/katex.js: katex.js $(wildcard src/*.js) $(NIS)
$(BROWSERIFY) -t [ babelify ] $< --standalone katex > $@ $(BROWSERIFY) -t [ babelify ] $< --standalone katex > $@
@@ -101,16 +102,16 @@ compress: build/katex.min.js build/katex.min.css
printf "Total: %6d\n" "$${TOTAL}" printf "Total: %6d\n" "$${TOTAL}"
serve: $(NIS) serve: $(NIS)
$(NODE) server.js $(NPM) start
flow: $(NIS) flow: $(NIS)
node_modules/.bin/flow $(NPM) run flow
test: $(NIS) test: $(NIS)
node_modules/.bin/jest $(NPM) test
coverage: $(NIS) coverage: $(NIS)
node_modules/.bin/jest --coverage $(NPM) run 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)

View File

@@ -25,6 +25,7 @@
"babel-register": "^6.24.0", "babel-register": "^6.24.0",
"babelify": "^7.3.0", "babelify": "^7.3.0",
"browserify": "^13.3.0", "browserify": "^13.3.0",
"check-dependencies": "^1.1.0",
"clean-css": "^3.4.23", "clean-css": "^3.4.23",
"eslint": "^4.6.1", "eslint": "^4.6.1",
"eslint-plugin-flowtype": "^2.35.1", "eslint-plugin-flowtype": "^2.35.1",
@@ -47,9 +48,13 @@
}, },
"bin": "cli.js", "bin": "cli.js",
"scripts": { "scripts": {
"lint": "make lint", "lint": "eslint katex.js server.js cli.js src test contrib dockers",
"test": "make lint flow test", "flow": "flow",
"prepublish": "make NIS= dist" "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": [ "pre-commit": [
"lint" "lint"

View File

@@ -55,7 +55,7 @@ defineFunction({
// The steps taken here are similar to the html version. // The steps taken here are similar to the html version.
let output = []; let output = [];
if (group.value.value.length > 0) { if (group.value.value.length > 0) {
let temp = mml.buildExpression(group.value.value, options); const temp = mml.buildExpression(group.value.value, options);
let word = ""; let word = "";
for (let i = 0; i < temp.length; i++) { for (let i = 0; i < temp.length; i++) {

View File

@@ -7,19 +7,20 @@
* The export of this module is simply a dictionary of test cases. * The export of this module is simply a dictionary of test cases.
*/ */
var fs = require("fs"); const fs = require("fs");
var jsyaml = require("js-yaml"); const jsyaml = require("js-yaml");
var querystring = require("querystring"); const querystring = require("querystring");
var queryKeys = ["tex", "pre", "post", "display", "noThrow", "errorColor"]; const queryKeys = ["tex", "pre", "post", "display", "noThrow", "errorColor"];
var dict = fs.readFileSync(require.resolve("./ss_data.yaml")); let dict = fs.readFileSync(require.resolve("./ss_data.yaml"));
dict = jsyaml.safeLoad(dict); dict = jsyaml.safeLoad(dict);
for (var key in dict) { for (const key in dict) {
var itm = dict[key]; if (dict.hasOwnProperty(key)) {
let itm = dict[key];
if (typeof itm === "string") { if (typeof itm === "string") {
itm = dict[key] = { tex: itm }; itm = dict[key] = { tex: itm };
} }
var query = {}; const query = {};
queryKeys.forEach(function(key) { queryKeys.forEach(function(key) {
if (itm.hasOwnProperty(key)) { if (itm.hasOwnProperty(key)) {
query[key] = itm[key]; query[key] = itm[key];
@@ -30,4 +31,5 @@ for (var key in dict) {
itm.query += "&" + querystring.stringify(itm.macros); itm.query += "&" + querystring.stringify(itm.macros);
} }
} }
}
module.exports = dict; module.exports = dict;