Skip to content

Latest commit

 

History

History
76 lines (61 loc) · 3.09 KB

DEVELOP.md

File metadata and controls

76 lines (61 loc) · 3.09 KB

Development

CLI & Automation

API Tests

git clone <project_git_uri>
cd <project_dir>/
npm install
npm run test # run all API tests
    # each test file can be run standalone by running `npm run test:...` for the
    # corresponding script entry in `package.json`; for example, when testing
    # local changes to a file, testing only that file reduces execution time
    #
    # when several test files are run together from a single Bash command, they
    # will not share any data (the `global` object for example) between each
    # run; this is due to the multiple `test:...` entries of the `scripts`
    # object in `package.json`, instead of a single entry as follows for
    # example:
    #     `"test": "echo Running tests... && mocha ./tests/_index.js ./tests/jsu*.js && echo Finished!"`

Advanced checks (not optional, complement API tests)

After npm install, the following commands can be considered, the most important being labeled "key".

Browser-specific tests

  • npm run browser:gen-tests: generate browser-specific tests from CLI-oriented ones; the tests are generated in a dedicated directory and can be run in a web browser via tests_browserified/index.html.
  • npm run browser:check-tests: check browser-specific tests from the CLI, assuming they have already been generated. While this is essential in an automated workflow, it is recommended to also run the tests from a real web browser to ensure that they do not fail due to memory leak warnings displayed by mocha (our test framework), as these warnings are not generated by the CLI.
  • npm run browser:run-tests: generate and check browser-specific tests from the CLI.

More checks

  • npm run code:check-scripts: check all build scripts.
  • npm run code:check-sources: validate source code; e.g. check that the correct version of ECMAScript is targeted.
  • npm run code:gen-main-test-coverage: run tests excluding browser-specific ones to generate informative code coverage in the coverage directory.
  • npm run code:check-state (key): validate source code and run all kinds of tests, including code coverage generation; this is the command to use in GitLab CI/CD automation for example.

Cleaning generated data

  • npm run clean: delete any data that may have been generated by the above npm run xxx commands.

Dependencies

We use the following npm packages which were all installed using npm install <package> --save-dev.

Tests

  • mocha as a test framework (and Node.js' built-in assert module for assertions).
  • sinon for spies, stubs and mocks.
  • jsdom to imitate in a Node.js environment the behavior of a browser.
  • nyc to generate code coverage from tests; outputs to .nyc_output and coverage by default.
  • browser-or-node to trigger different test routines for Node.js and web browsers for example.
  • browserify to generate browser-specific versions of test scripts.
  • karma to run browser-specific tests from the CLI, and some karma-xxx plugins installed as npm packages.

Others

  • jshint for assurance on supported ECMAScript specifications; implicitly uses the linting options defined in .jshintrc.