Upload
studio-stfalconcom
View
144
Download
1
Embed Size (px)
Citation preview
Why we should write tests
Why this project cannot start on my computer?
Victor VyshnevskyTrainee at JsSolutions
- Typo/error in your code- Wrong version of global
module (mongo, node)- Not compatible OS/browser- Floating version of package(
2.x, ~3.5.2, >=1.5.0)- Floating version of
subpackage- Npm package was deleted
from npm- 3rd party service changed
their API or died
How the common test looks like?
sync setup
async setup
Actual test
Unit tests run
Unit tests
require function call
Compare actual result with expected
gocardlessFactory.js
gocardlessFactory.spec.js
Integration tests
JSON REST API Integration tests
<- send JSON-> get JSON check json
2 unit tests, 0 integration
End-to-end tests (client tests)
JSON REST API
Client test
Open pageInteracts with pageChecks DOM
<- send JSON-> get JSON
Client (browser) ⇔ webdriver protocol
How do you feel when you see this
What do you use to lint your code?
How do you run this lint?
Package.json
{ “scripts”: { “test”: “mocha test && jshint lib/** && csslint client/css/**” }}
Linting could also be a test!
https://www.npmjs.com/package/mocha-jshint
https://www.npmjs.com/package/mocha-csslint
https://www.npmjs.com/package/mocha-eslint
https://www.npmjs.com/package/mocha-jscs
eslint.spec.js
Who is guilty?
- Tests should run before merging branch to master
- Tests should work on Continous Integration server
(Travis, Jenkins, TeamCity, CircleCI)
Why this project cannot start on my computer?
- Typo/error in your code- Wrong version of global
module (mongo, node)- Not compatible OS/browser- Floating version of package(
2.x, ~3.5.2, >=1.5.0)- Floating version of
subpackage- Npm package was deleted
from npm- 3rd party service changed
their API/died)
How to check wrong version of node?
+ nodeversioncheck
$ node app.jsRunning correct node V5.8.0. (according to package.json we need V5.8.0)
or$ node app.jsRunning WRONG node V5.8.0. (according to package.json we need V7.8.0)
.travis.yml
Node 0.10Mongo 2.6
Node 0.12Mongo 2.6
Node iojsMongo 2.6
Node 0.10Mongo 2.8
Node 0.12Mongo 2.8
Node iojsMongo 2.8
Node 0.10Mongo 3.0
Node 0.12Mongo 3.0
Node iojsMongo 3.0
Why this project cannot start on my computer?
- Typo/error in your code- Wrong version of global
module (mongo, node)- Not compatible OS/browser- Floating version of package(
2.x, ~3.5.2, >=1.5.0)- Floating version of
subpackage- Npm package was deleted
from npm- 3rd party service changed
their API/died)
Nightly test!Schedule all your tests on master to run during night!
rm -rf node modulesnpm inpm test
Your team will use tests when they will be:
- Stable (minimize radom things)- Valuable (check only what make sense) - They should work on your machine, machines of your colleges and
on CI server (setup contionius integration)- Fast enough to use it (slow tests should go to nightly-test)- Easy to write ( declaritive style of setup )- Easy to maintain
Examples of bad tests
Example of bad test (2)
https://mochajs.org/
http://chaijs.com/
http://webdriver.io
https://www.npmjs.com/package/selenium-standalone
http://eagleeye.github.io
Useful links