From dbc5a74ebd37d3500acb3c0c67ecbf7719949276 Mon Sep 17 00:00:00 2001 From: Kevin Barabash Date: Wed, 13 Sep 2017 10:01:39 -0400 Subject: [PATCH] Allow test/lint scripts to run without requiring make (#878) --- .eslintignore | 3 +++ .eslintrc | 12 ----------- CONTRIBUTING.md | 6 +++--- Makefile | 17 ++++++++-------- package.json | 11 +++++++--- src/functions/operators.js | 2 +- test/screenshotter/ss_data.js | 38 ++++++++++++++++++----------------- 7 files changed, 44 insertions(+), 45 deletions(-) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..f543aa19 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +**/node_modules/* +build/* +dist/* diff --git a/.eslintrc b/.eslintrc index e09da909..943f8676 100644 --- a/.eslintrc +++ b/.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, diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 35c137ea..a09e8147 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 diff --git a/Makefile b/Makefile index 1226b118..bda5b1ac 100644 --- a/Makefile +++ b/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) diff --git a/package.json b/package.json index facab45f..6cb20ec0 100644 --- a/package.json +++ b/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" diff --git a/src/functions/operators.js b/src/functions/operators.js index 8334cad1..ef47d682 100644 --- a/src/functions/operators.js +++ b/src/functions/operators.js @@ -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++) { diff --git a/test/screenshotter/ss_data.js b/test/screenshotter/ss_data.js index 81ff909f..257d331b 100644 --- a/test/screenshotter/ss_data.js +++ b/test/screenshotter/ss_data.js @@ -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;