Skip to content

Latest commit

 

History

History

javascript

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Javascript Tests in Tilt

A wrapper for Tilt's testing functionality for easier Go test setup. Currently, we offer extensions for running the specified tests with Jest via your JS package manager (currently either npm or Yarn).

Usage

Load the function you need with:

load('ext://tests/javascript', 'test_jest_npm')

Parameters

test_jest_npm, test_jest_yarn, test_jest_pnpm accept the same parameters. These are:

  • name (str): name of the created test resource.
  • dir (str): directory from which to run npm|yarn|pnpm test

You may also pass the following optional parameters:

  • deps (Union[str, List[str]]): a list of files or directories to be added as dependencies to this test. Tilt will watch those files and will run the test when they change. By default, will be set to dir. Only accepts real paths, not file globs.
  • only_changed (bool, optional): by default, True. If true, Jest will run tests affected by files changed since last commit; otherwise, will run all tests at the specified dir/path(s). (only_changed = True is equivalent to passing the --onlyChanged flag to Jest.)
  • with_install (bool, optional): by default, False. If true, run npm|yarn|pnpm install before running any tests, to ensure that your local dependencies are up to date.
  • project_root (str, optional): if dir is not the root of the JS project, specify the project root here so that Tilt can locate package.json and your lockfile. By default, will be set to dir. (Mostly relevant if you have specified with_install=True, so that Tilt can watch your package.json and lockfile and rerun in the install command either changes.)
  • ignore (List[str], optional): set of file patterns that will be ignored. Ignored files will not trigger builds and will not be included in images. Follows the dockerignore syntax. Paths will be evaluated relative to the Tiltfile.
  • extra_args (List[str], optional): any other args to pass to npm|yarn|pnpm test.
  • **kwargs: will be passed to the underlying test call

Examples

  1. Run tests in a directory

    test_jest_yarn('test-js', './web')
  2. Run tests in a directory other than the project root

    # 'package.json' and 'yarn.lock' both live in './web/'
    test_jest_yarn('test-js', './web/src',
                  with_install=True, project_root='./web')
  3. Run tests with notifications

    test_jest_yarn('test-js', './web',
                  extra_args=['--notify'])
  4. Run your slow/expensive tests manually

    test_jest_yarn('integration-tests', './integration',
                trigger_mode=TRIGGER_MODE_MANUAL, auto_init=False)

    The trigger_mode and auto_init parameters will be passed to the underlying test call (see docs on Manual Update Control).

  5. Run only tests related to file changed since the last commit--except in CI mode, which should run all tests

    test_jest_yarn('test-js', './web',
                      run_all=config.tilt_subcommand == 'ci')