Skip to content

Commit

Permalink
Chore: add testing framework
Browse files Browse the repository at this point in the history
- Move linting from `test` to a test prerequisite, the `pretest` script.

- Add Mocha `test` and `test:watch` scripts:
  - Tests are permitted in test/ and src/ per ticket requirements.
    However, it's unclear why they'd be wanted in both. The test/
    directory was also added to format and lint scripts.
  - A throwaway test was added since the absence of all tests causes a
    failure and to show that the setup works.

- Add Mocha, Sinon.JS, and Chokidar CLI to `devDependencies`:
  - Mocha is used because that's what Services and Readers'
    Infrastructure use and it's quite popular.
  - Sinon.JS is used because MobileFrontend uses it and Readers'
    Infrastructure is considering it (T151091*) and it's popular too.
  - Chokidar CLI (chokidar-cli) was chosen because it's popular, quick,
    and Chokidar is used by Live Server (live-server). watch and
    npm-watch were each tried but appeared to function sporadically and
    slowly on Ubuntu GNOME v17.04. `npm test -- -w` cannot be used
    because 1) continuous linting is also wanted, 2) [new files are not
    observed], 3) a maintainer indicated they were wanted to get rid of
    watch functionality in the same report, and 4) separating watch and
    testing responsibilities gives more flexibility in responding to
    file changes. No attempts were made to filter or throttle files
    observed.

  *The [Services team template] and most of the [Readers' Infrastructure
  repos] do not reference it.

  [Services team template]: https://github.com/wikimedia/service-template-node/blob/3842da2/package.json
  [Readers' Infrastructure repos]: as described on:
    - https://www.mediawiki.org/wiki/Wikimedia_Reading_Infrastructure_team#Projects
    - https://www.mediawiki.org/wiki/Reading/Component_responsibility
    And discovered with:
    $ find -not \( \( -name .git -o -name node_modules -o -name i18n -o -name sinonjs -o -name bundle -o -name .bundle \) -prune \) -type f|
      xargs -rd\\n grep -El 'sinon|\.(calledOn|calledWith|spy)\('
    mediawiki/tests/qunit/...
    mediawiki/extensions/MobileFrontend/...
    mediawiki/extensions/MultimediaViewer/...
    mediawiki/extensions/TimedMediaHandler/...
  [new files are not observed]: mochajs/mocha#2176

- A Mocha ESLint environment was deliberately omitted to force tests to
  explicitly specify their dependencies even though the Mocha API is a
  global.

Bug: T172432
  • Loading branch information
niedzielski committed Aug 5, 2017
1 parent 7956997 commit 81e2dc4
Show file tree
Hide file tree
Showing 3 changed files with 472 additions and 1,049 deletions.

0 comments on commit 81e2dc4

Please sign in to comment.