Commit Graph

72 Commits

Author SHA1 Message Date
ylemkimon
5f32b71c85 Use webpack to build files and webpack-dev-server for testing (#1068)
* Create a separate entry point for webpack

Created a webpack entry point for KaTeX, which imports katex.less. As
flow[1] and jest[2] doesn't support CSS modules natively, a separate
entry point is used and it is not flowtyped.

[1] https://gist.github.com/lambdahands/d19e0da96285b749f0ef
[2] https://facebook.github.io/jest/docs/en/webpack.html

* Use webpack to build files

* Made webpack.config.js export valid webpack configuration
* Use:
browserify -> webpack
babelify -> babel-loader
UglifyJS CLI -> UglifyJsPlugin
Less CLI -> less-loader
cleancss -> cssnano in css-loader
build/fonts -> file-loader
* Inline CSS(Less) using style-loader and export them using
ExtractTextPlugin
* Add `watch` npm script calling `webpack --watch`

* Improve local testing(webpack-dev-server)

* Made webpackDevServer export a valid webpack configuration
* Compile Less and inline CSS using less-loader and style-loader
* Instead of copying files serve files from /static and use file-loader
* Remove old server.js and its dependencies

* Use webpack-dev-server in Screenshotter

* Include contrib in webpack-dev-server

+ Moved common configurations to webpack.common.js

* Rename webpackDevServer.js to webpack.dev...

to be consistent, avoid confusion with webpack-dev-server and follow
webpack configuration naming convention.

* Remove unnecessary conditional output.path

* Use map instead of reduce

+ Add comments regarding function arguments

* Remove unnecessary mkdir and clean build/* before build

* Use katex as external dependency instead of global variable in contrib

Fixes #692.

* Unblock codes as they are built as a module

* Update package-lock.json

* Add comments regarding devServer option

* Lint renamed webpack.dev.js

a0d8b33

* Export ES6 module and expose its default export

* Revert "Browserify hotfix (#1057)"

This reverts commit f6b509123b.

* Enables colors on the console when running the dev server in Screenshotter

* Add context to webpack configuration

Allows webpack to be run from other directories

* Move `rm -rf build/*` to npm scripts

* Check dependencies before build

* Move UglifyJsPlugin into config creation

* Let webpack handle ES6 modules

Do not transform modules to commonjs in Babel. However Jest doesn't not
support ES6 modules, so transfrom modules to commonjs when NODE_ENV is
`test`.

* Add documentation on testing in IE 9 and 10 using webpack-dev-server

Changed version range to include IE-compatible version
2018-01-21 19:48:25 -05:00
nickkolok
f6b509123b Browserify hotfix (#1057) 2018-01-14 17:16:12 -05:00
Erik Demaine
63733f796a Update testing infrastructure NPM packages (#1044)
* Update testing infrastructure NPM packages

Travis is currently failing all tests.  This should fix it,
as documented in https://github.com/eslint/eslint/issues/9767

* Add package-lock.json
2017-12-29 10:06:26 -07:00
Ryan Randall
50765a0ccd Stacking text commands (#1009)
* Adding support for SansSerif-Bold

* Updating to include SansSerif Italic.

* WIP

* Working text stacking

* More robust screenshot.

* Don't want to break users :)

* Updating per PR comments.

* Fixing Unicode and updating snapshots.

* Adding suggested tests.

* Opting to use old method for unit testing.

* Adding TODO
2017-12-13 09:10:23 -05:00
Erik Demaine
fd2544f8f9 Output port number of server, and lint fixes (#980) 2017-11-22 21:54:21 -05:00
Erik Demaine
7f6f59ef8a Lint .less files with stylelint (#925)
Lint .less files with stylelint. Fix #921

In particular, prevent tabs.
2017-10-10 11:14:09 -04:00
Ryan Randall
141afa091a Fixing CJS modules and Globals (#920)
* Working CJS modules.

* Changing cjs imports to es6.
2017-10-08 10:56:07 -06:00
Kevin Barabash
2e27d4248b Bump master to v0.10.0-pre 2017-10-05 11:40:49 -06:00
Kevin Barabash
71e0b35b27 allow sizing commands inside optional groups (#885)
* allow sizing commands inside optional groups

* allow color, old font, and style commands inside optional groups
2017-10-03 11:30:59 -06:00
Ryan Randall
fbffdc5fc7 Webpack dev server (#902)
* Initial webpack config. Moving to ES6 modules. Some module cleanup.

* WIP

* WIP

* Removing commented out code.

* Removing old deps.

* Removing the build script (used for testing).

* Working tests.

* Switching to node api over cli.

* Updating per comments. Still need to fix server.js to properly run the selenium tests.

* Cleaning up the config.

* More cleanup.

* Bringing back server.js for selenium tests.

* Bringing back old dependencies.

* Adding back eslint rules for webpack config. Final cleanup for webpack config.

* Pointing to correct pre-existing module versions. Adding some extra logic to server.js to ensure it gets transpiled properly.

* Getting make build to work again. Updating package.json with some shortcut scripts.

* Resolving conflict.

* Reverting back to commonjs modules.

* Removing extra spaces in babelrc
2017-09-26 12:16:35 -06:00
Kevin Barabash
dbc5a74ebd Allow test/lint scripts to run without requiring make (#878) 2017-09-13 10:01:39 -04:00
Erik Demaine
588f5a1ee6 eslint-plugin-flowtype & upgrade to eslint@4 (#849)
* Add eslint-plugin-flowtype. Fix #844

Using the recommended settings for plugin.
This involved adding some spaces to some existing union types.

* Upgrade to eslint@4, fix spotted bugs

Switched to indent-legacy to allow e.g. comments to have extra indents.
2017-09-06 22:06:26 -04:00
Aria Buckles
feef4107df Fix match-at flow errors (#847)
Upgrade match-at and flow versions to resolve the match-at flow
errors, allowing us to remove match-at from the .flowconfig ignore

Test plan:

run `jest` and get the following output:

    PASS  test/unicode-spec.js
    PASS  test/errors-spec.js
    PASS  test/mathml-spec.js
    PASS  test/katex-spec.js (5.104s)

run `flow` and get:

    No errors!
2017-09-05 22:37:17 -04:00
Kevin Barabash
6db61cb219 run flow as part of 'npm test' so it runs on travis-ci 2017-09-02 15:11:44 -04:00
Kevin Barabash
d8116bdc64 update defineFunction to accept a single arg, introduce flow to do some typechecking 2017-09-02 15:11:44 -04:00
Schmulik Raskin
d36ca4a2fa Add contrib to NPM files 2017-08-30 05:55:19 +09:00
Kevin Barabash
96c1fe7ad8 Bump master to v0.8.4-pre 2017-08-27 18:01:07 -04:00
Kevin Barabash
796551021b switch pre-commit hook to use pre-commit npm package (#823) 2017-08-27 17:53:41 -04:00
Erik Demaine
6d2cf79f53 Pre-commit hook to call make lint (#815) 2017-08-21 21:55:49 -04:00
Kevin Barabash
2cd961dbe0 Bump master to v0.8.3-pre 2017-08-17 01:13:27 -04:00
Kevin Barabash
e192be2177 Update package.json to point 'main' at dist/katex.js (#791)
Summary:
Now that we're using ES6 import statements in our source code
it makes it difficult for people to consume the katex package
as a node module unless they're using node.js version 8.x.

This diff points the node entry to dist/katex.js which
is the compiled version of katex.js.

Test Plan:
- publish
- create a new project node project and add the new npm katex package as a deep
- require katex in a test file and run it using node.js version 6.x
2017-08-15 00:15:34 +09:00
Kevin Barabash
fafaf85f96 Fix MathML output for ' and large operators with limits (#788)
Summary: (@kevinbarabash)
This diff extracts MathML builder tests out into a separate file and
updates them to use jest snapshot testing.  It updates the output of
prime ' from using identifier nodes <mi> to operator nodes <mo>.  It
also updates large operators with limits to use munderover instead
of msupsub. I added an option to remove unnecessary mrows to buildGroup.
Right now it's only used for by groupTypes.supsub. I'll see if it can be used
elsewhere (everywhere?) in a follow up PR.

Test Plan:
- make test w/o errors
- verify mathml snapshots contain the desired markup
2017-08-14 22:27:48 +09:00
Kevin Barabash
ef66f30912 Bump master to v0.8.2-pre 2017-08-11 22:14:52 -04:00
Kevin Barabash
107d5284b5 Bump master to v0.9.0-pre 2017-08-11 20:00:34 -04:00
Kevin Barabash
361c500a7f 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
2017-07-11 14:16:26 -04:00
Hossein Saniei
a019f36f8a Upgrade the source to use ES6 syntax including classes, import and static properties (#679)
* Add babel transform-class-properties to have static class properties

* Upgrade Lexer and Parser files to use ES6 classes

* Update eslint max line length to 90 character (more indent because of using ES6 classes)

* Upgrade eslint and jasmin to support ES stage-2 features

* Use static properties to place constants near their functions

* Migrate all remaining sources to ES6 syntax

* Increase eslint max line length to 84

* Remove non-babelified endpoint in dev server.js

* Clean up server.js functions after removing browserified

* Make screenshotter not to use babel endpoint as we babelify everything now
2017-07-03 08:09:21 -04:00
Martin von Gagern
7ec455083f Builtin macros, macro arguments, overset and underset
* Ship predefined macros with the library, in macros.js.
* Allow macro arguments #1 and so on, with argument count deduced from string.
* Use these features to implement \overset and \underset, fixes #484.
2017-04-05 21:42:38 +01:00
Kevin Barabash
8dd161d4b2 Merge pull request #615 from gagern/release
Improve release script and bower support
2017-01-21 17:49:15 -05:00
Martin von Gagern
9b565a6375 Include babelify step in browserify calls
This allows using ES6 syntax in our code, while maintaining backwards
compatibility for the generated file.
2017-01-13 22:37:17 -05:00
Martin von Gagern
5783e193ed Update CDN version numbers and SRI hashes on release 2017-01-13 13:43:41 +01:00
Martin von Gagern
79d53bd29f Use morgan to log requests in the dev server
This is motivated by the recent switch to Express 4.
Without this commit, “make serve” will print the following message:

Error: Most middleware (like logger) is no longer bundled
with Express and must be installed separately.  Please see
https://github.com/senchalabs/connect#middleware.
2017-01-12 09:52:29 +01:00
Martin von Gagern
90e25fecc2 Update dependencies to more recent version
All these version ranges include the latest version at the time of this
commit, except for the selenium webdriver.  There version 3 is incompatible
with version 2, and switching to a version 3 library appears to require
switching to version 3 docker images as well, which would entail using
different browser versions which in turn would lead to differences for a
large number of screenshots.  That doesn't appear warranted at this time.
2017-01-09 15:09:43 +01:00
Emily Eisenberg
8f46eeaf1b Bump master to v0.8.0-pre 2017-01-06 19:50:50 -08:00
Emily Eisenberg
4d2e46e7f6 Remove trailing commas for IE 9 compatibility
Summary: IE 9 doesn't like trailing commas. When we introduced eslint, we added
a bunch of trailing commas, which makes IE 9 sad.

Test Plan:
 - `make lint`
 - Visit http://localhost:7936/ using IE 9 on browserstack.
 - See that the math loads, and there are no errors in the F12 developer tools.

@kevinb
2017-01-06 19:06:01 -08:00
Martin von Gagern
e6de31d2d6 Call “npm install” automatically if package.json changed (#505)
This adds a stamp file which is used to detect whether the `package.json`
file got updated since the last `npm install`.  If so, `npm install` is run
again to update all modules to the version described in `package.json`.
This happens as a dependency of only those modules which actually need some
npm-installed module.

Setting the corresponding make variable to the empty string disables the
feature, which is used by the `make` invocation in the `prepublish` script
inside `package.json` to avoid infinite loops.  It can also be used by
developers working in an environment with reduced connectivity, as long as
they know what they are doing.
2016-08-23 18:05:50 -07:00
Martin von Gagern
befe1c1af7 Upgrade less to version 2 (#503)
This fixes a problem where the graceful-js dependency of the old less
version is incompatible with node 7, and will cause warnings on node 6.
The resulting katex.min.css is exactly the same as with the previous
version, so the major version upgrade does not seem to affect the outcome.

The less.Parser has been deprecated, and less.render is the supported
approach now, so we have to switch the development server to that.
2016-07-12 12:23:28 -07:00
Kevin Barabash
5991a6078b Bump master to v0.7.0-pre 2016-04-15 18:18:36 -07:00
Jon Tirsen
a5207fef94 Bundle css and fonts in npm package. 2016-02-18 09:21:28 +01:00
Kevin Barabash
14a58adb90 Migrate to eslint
Summary
We'd like contributors to use the same linter and lint rules that we use
internally.  This diff swaps out eslint for jshint and fixes all lint failures
except for the max-len failures in the test suites.

Test Plan:
- ka-lint src
- make lint
- make test

Reviewers: emily
2015-12-01 10:02:08 -08:00
Martin von Gagern
cc17f36edc Drop local copy of jasmine, multiple spec files in browser tests
Instead of having our own copy of jasmine in the repository, we use
jasmine-core as an npm dependency and load it from there.  That reduces the
size of the repository and helps keeping up to date.  We're not using the
transitive dependency on jasmine-core via jasmine, since the jasmine package
might change its dependency any day (although unlikely).

The katex-spec.js shipped from the server now includes all
`test/*[Ss]pec.js` (as matched via glob) so that additional spec files can
be created and will automatically get included in the browser-side test
suite.  The contrib specs are not included at this point.

Visit http://0.0.0.0:7936/test/test.html while running server.js to see this
in action and verify the lack of failures.
2015-11-12 18:34:31 +01:00
Martin von Gagern
92034c17f9 Switch from jasmine-node to jasmine itself
Jasmine supports node these days, so there is no longer a need to use a
separate (and unmaintained) package to provide such bindings.

Making the switch exposed several misuses of the `toMatch` assertion in the
existing specification.  Most of them were converted to `toEqual`, since
`toMatch` is only for matching against regular expressions.
2015-11-10 12:38:49 +01:00
Martin von Gagern
2e002ff37a Use jspngopt and pako to create reproducible PNG files for Chrome as well
The combination of jspngopt and pako should eliminate possible causes for
different PNG encodings, although the core reason for #325 remains unknown.
Pako has poorer compression rates than native libz, but optimization can
counter that effect, and actually reduce the size of the screenshots.

The screenshots for LimitControls and UnsupportedCmds on Firefox used to
exhibit subpixel rendering before, for reasons unknown.  The regenerated
versions don't exhibit this.  See #324 for a discussion.
2015-08-30 02:12:55 +02:00
Martin von Gagern
758f4a73d9 Merge remote-tracking branch 'origin/master' into ssYaml 2015-08-06 10:18:04 +02:00
Emily Eisenberg
2600587f78 Update master version numbers
Summary: Update the version numbers on master to <the-next-version>-pre.

Test plan:
 - ???

Auditors: kevinb, alpert
2015-07-16 14:20:29 -07:00
Martin von Gagern
fb403fa9eb Switch Screenshotter data from JSON to YAML
Escaping TeX in JSON as query strings is a pain: you have to double all the
\\, you have to escape the & and the #, you can't easily include line breaks
for readability, and so on.  YAML solves most of these problems for most of
the situations.  Now each test case can be structured, while simple test
cases only consist of a line of verbatim TeX code, with no escaping.

The most troublesome items remaining are lines starting in { since in YAML
these would denote inline mapping types. We use block notation for these.
2015-07-16 08:57:17 +02:00
Martin von Gagern
5d155c75db Switch from own docker image to standard selenium images
Since the Selenium images are available for download, and downloading them
is usually faster than building them from scratch, this makes taking
screenshots easier.  Furthermore, since the Selenium image is not specific
to KaTeX, it could as well be used for other purposes, thus saving space
since a single image can be used in multiple projects.

This change also deals with the non-determinism in the Lap screenshot:
We detect the one known (and accepted) alternate rendering and change the
output file name to Lap_alt in this case.  So either Lap or Lap_alt gets
saved to, and if the image is different from both, then one of these files
will show a modification.  On the other hand, if it is equal to either of
these, then the matching one will get overwritten, showing no change.
2015-07-14 18:09:58 +02:00
Martin von Gagern
1603162267 Save auto-generated font metrics data to separate JSON file
This separates auto-generated code from manually created code.
We need a more recent version of browserify to directly require JSON.
Note that the data was copied, not recreated, so it has not been changed.
This addresses issue #301.
2015-07-10 14:30:41 +02:00
Kevin Barabash
4ea7d38b5c Summary: add "main" field instead of "name" to bower.json
Test plan:
 - Run `bower install katex` from /tmp
 - Verify that there are no errors when running the command
 - Verify that `bower_components/katex/dist/` contains all the build files
 - Verify that the version is 0.4.2

Auditors: emily
2015-06-20 11:08:58 -06:00
Kevin Barabash
b11a1b97b7 Summary:
- Add "main" field to bower.json to prevent errors during installation.
- Bump version to 0.4.1 in bower.json and package.json

https://github.com/Khan/KaTeX/issues/181

Test plan:
 - Run `bower install katex` from /tmp
 - Verify that there are no errors when running the command
   and that `bower_components/katex/dist/` contains all the build files

Auditors: emily
2015-06-20 11:00:41 -06:00
Ben Alpert
0f6530096b Don't slice in lexer
Summary: Theoretically this allocates way less. In practice it seems to be exactly the same speed.

Test Plan: make test

Reviewers: emily

Reviewed By: emily

Differential Revision: https://phabricator.khanacademy.org/D16621
2015-04-06 10:39:39 -07:00