run-test.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Copyright (c) Jupyter Development Team.
  2. # Distributed under the terms of the Modified BSD License.
  3. from __future__ import print_function, absolute_import
  4. import json
  5. import logging
  6. import os
  7. from traitlets import Bool
  8. from jupyterlab.tests.test_app import ProcessTestApp
  9. HERE = os.path.dirname(os.path.realpath(__file__))
  10. class ServicesTestApp(ProcessTestApp):
  11. """A notebook app that runs a mocha test."""
  12. coverage = Bool(False, help='Whether to run coverage')
  13. devtool = Bool(False, help='Whether to run with devtool')
  14. def get_command(self):
  15. """Get the command to run"""
  16. terminalsAvailable = self.web_app.settings['terminals_available']
  17. mocha = os.path.join(HERE, '..', 'node_modules', '.bin', '_mocha')
  18. mocha = os.path.realpath(mocha)
  19. defaults = ['build/**/*.spec.js', 'build/*.spec.js']
  20. defaults += ['--retries', '2',
  21. '--jupyter-config-data=./build/config.json']
  22. default_timeout = ['--timeout', '20000']
  23. debug = self.log.level == logging.DEBUG
  24. if self.coverage:
  25. istanbul = os.path.realpath(
  26. os.path.join(HERE, '..', 'node_modules', '.bin', 'istanbul')
  27. )
  28. cmd = [istanbul, 'cover', '--dir', 'coverage', '_mocha', '--']
  29. cmd += default_timeout + defaults
  30. elif self.devtool:
  31. cmd = ['devtool', mocha, '-qc', '--timeout', '120000'] + defaults
  32. else:
  33. cmd = [mocha] + default_timeout + defaults
  34. if debug:
  35. cmd += ['--debug-brk']
  36. config = dict(baseUrl=self.connection_url,
  37. terminalsAvailable=str(terminalsAvailable),
  38. token=self.token)
  39. with open(os.path.join(HERE, 'build', 'config.json'), 'w') as fid:
  40. json.dump(config, fid)
  41. return cmd, dict(cwd=HERE)
  42. if __name__ == '__main__':
  43. ServicesTestApp.launch_instance()