building-testing.rst 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. Building and testing
  2. ====================
  3. To actually run highlight.js it is necessary to build it for the environment
  4. where you're going to run it: a browser, the node.js server, etc.
  5. Building
  6. --------
  7. The build tool is written in JavaScript using node.js. Before running the
  8. script, make sure to have node installed and run ``npm install`` to get the
  9. dependencies.
  10. The tool is located in ``tools/build.js``. A few useful examples:
  11. * Build for a browser using only common languages::
  12. node tools/build.js :common
  13. * Build for node.js including all available languages::
  14. node tools/build.js -t node
  15. * Build two specific languages for debugging, skipping compression in this case::
  16. node tools/build.js -n python ruby
  17. On some systems the node binary is named ``nodejs``; simply replace ``node``
  18. with ``nodejs`` in the examples above if that is the case.
  19. The full option reference is available with the usual ``--help`` option.
  20. The build result will be in the ``build/`` directory.
  21. .. _basic-testing:
  22. Basic testing
  23. -------------
  24. The usual approach to debugging and testing a language is first doing it
  25. visually. You need to build highlight.js with only the language you're working
  26. on (without compression, to have readable code in browser error messages) and
  27. then use the Developer tool in ``tools/developer.html`` to see how it highlights
  28. a test snippet in that language.
  29. A test snippet should be short and give the idea of the overall look of the
  30. language. It shouldn't include every possible syntactic element and shouldn't
  31. even make practical sense.
  32. After you satisfied with the result you need to make sure that language
  33. detection still works with your language definition included in the whole suite.
  34. Testing is done using `Mocha <http://mochajs.org/>`_ and the
  35. files are found in the ``test/`` directory. You can use the node build to
  36. run the tests in the command line with ``npm test`` after installing the
  37. dependencies with ``npm install``.
  38. **Note**: for Debian-based machine, like Ubuntu, you might need to create an
  39. alias or symbolic link for nodejs to node. The reason for this is the
  40. dependencies that are requires to test highlight.js has a reference to
  41. "node".
  42. Place the snippet you used inside the browser in
  43. ``test/detect/<language>/default.txt``, build the package with all the languages
  44. for node and run the test suite. If your language breaks auto-detection, it
  45. should be fixed by :ref:`improving relevance <relevance>`, which is a black art
  46. in and of itself. When in doubt, please refer to the discussion group!
  47. Testing markup
  48. --------------
  49. You can also provide additional markup tests for the language to test isolated
  50. cases of various syntactic construct. If your language has 19 different string
  51. literals or complicated heuristics for telling division (``/``) apart from
  52. regexes (``/ .. /``) -- this is the place.
  53. A test case consists of two files:
  54. * ``test/markup/<language>/<test_name>.txt``: test code
  55. * ``test/markup/<language>/<test_name>.expect.txt``: reference rendering
  56. To generate reference rendering use the Developer tool located at
  57. ``tools/developer.html``. Make sure to explicitly select your language in the
  58. drop-down menu, as automatic detection is unlikely to work in this case.