Skip to content

Latest commit

 

History

History
89 lines (67 loc) · 3.63 KB

development_setup.md

File metadata and controls

89 lines (67 loc) · 3.63 KB

Development setup

Development setup is mostly about getting confortable with automated tests: it's nice to add new features, it's better to know that those features won't be broken or removed by mistake. This can be done by adding automated tests: those tests will be run before publishing any new version to guarantee that the new version doesn't introduce any regression.

Summary

Install tests dependencies

npm install

This will install the dependencies we need to run tests, especially:

  • mocha: the executable to which we pass test files, and that defines the following global functions used in test files: describe, it, beforeEach, etc
  • should.js: a lib to easily make assertions and throw errors when those assertions aren't true:
(12).should.be.above(10) // will not throw
(12).should.be.below(10) // will throw and thus make the test fail

Unit tests

Unit tests are used to test a single function at once, and can be run without any other setup.

Run a single unit test file

./node_modules/.bin/mocha ./tests/unit/parse_instance.js

Just try to run it, you can't break anything! And then try to modify the function it tests, lib/parse_instance.js, and see how that makes the tests fail.

To run only one test in that file, replace it( by it.only(

Run all the unit tests

npm run test:unit

Integration tests

Integration tests are used to check that the function produce the desired behaviour on a Wikibase instance. We thus need to have a Wikibase instance at hand to run our functions against, thus the more elaborated setup.

Setup a test Wikibase instance

Create a ./config/local.js file overriding values in ./config/default.js with your credentials on the Wikibase instance you want to use: either test.wikidata.org or your own local Wikibase.

That's the easiest option.

Pros:

  • zero setup

Cons:

  • tests are slowed down by network latency
  • doesn't work when you're offline/on a bad connection

Tests should pass as any user can create properties on that instance. That's probably the easiest setup to get started.

Install a local Wikibase with Docker

git clone https://github.com/wmde/wikibase-docker
cd wikibase-docker
docker-compose up -d wikibase

See Docker documentation

Run a single integration test file

./node_modules/.bin/mocha ./tests/integration/label/set.js

To run only one test in that file, replace it( by it.only(

Run all the integration tests

npm run test:integration