mirror of
https://github.com/NASAWorldWind/WebWorldWind.git
synced 2026-01-18 15:12:57 +00:00
79 lines
3.3 KiB
Plaintext
79 lines
3.3 KiB
Plaintext
|
||
- Preparation: install Karma and Jasmine
|
||
In a terminal go to the repo folder and do “npm install” (we are considering you have node.js already installed) to install
|
||
all the necessary dependencies saved as devDependencies in 'package.json' file.
|
||
|
||
- How to Create a test:
|
||
1) Go to the 'test' folder and create a new file (notice that 'test' folder should maintain the same structure of 'src'
|
||
folder, so if my module to be tested is located in 'src/features/', the related test should be in 'test/features')
|
||
2) Save the file as '<name of the module to be tested>.test.js'
|
||
3) The basic structure of the test is the following:
|
||
|
||
define([ <list of paths of the modules that this module depends on> ], function (< list of parameters>) {
|
||
|
||
"use strict";
|
||
|
||
describe("<Name of the module to be tested to help you understand what the test is supposed to be>", function() {
|
||
....
|
||
|
||
it("<Description of the expected results of the test, usually it starts with the word 'should'>",
|
||
function() {
|
||
expect( ... ).<matcher>(...);
|
||
|
||
})
|
||
});
|
||
});
|
||
|
||
At the following link you can find an introduction to the Jasmine framework http://jasmine.github.io/2.0/introduction.html
|
||
|
||
- Auto-run and continuous testing on local machine:
|
||
Execute “karma start karma.conf.js” to start a process which auto-runs all tests when source files have been changed and
|
||
saved and leave the terminal open.
|
||
|
||
Open the file “REPO/src/formats/kml/KmlCamera.js” and change a line which lets the test fail
|
||
(like commenting a return statement) and save. (don’t close the file, it’s needed later) -> The test in the
|
||
terminal should now fail. (The test file can be found at
|
||
“REPO/test/formats/kml/KmlCamera.test.js”).
|
||
|
||
Undo the changes in the KmlCamera.js file and save the file should
|
||
result in a successful test again.
|
||
|
||
Stop the terminal.
|
||
|
||
Running karma.conf.js in WebStorm (will run the test only once
|
||
unless the re-run option has been selected which runs all tests after
|
||
source changes similar to starting karma.conf.js in the terminal.):
|
||
|
||
- Go to Run -> Edit Configurations..
|
||
- Click on the '+' button on the top left side (Add New Configuration)
|
||
- Select 'karma' from the curtain menu
|
||
- In Configuration file box insert the path of the file 'karma.conf.js'
|
||
- In Name box insert the name of the configuration (e.g. Karma Testing)
|
||
- Save the configuration
|
||
- Click on Run--> Run Karma Testing to run the tests
|
||
|
||
|
||
To test for specific browsers (e.g. Chrome) are also possible:
|
||
- Open karma.conf.js and go to line 60 and add ‘Chrome’ ("browsers: ['PhantomJS','Chrome’],”
|
||
now, don’t close the file).
|
||
|
||
- Add the chrome launcher for karma by executing “npm install
|
||
karma-chrome-launcher”.
|
||
|
||
- Execute “karma start karma.conf.js”. A Chrome window should open
|
||
automatically and the terminal should state that the tests for both
|
||
chrome and phantomjs were successful.
|
||
- Change again the file KmlCamera.js to let the test fail.
|
||
- Undo the changes and stop the terminal.
|
||
- Delete ‘Chrome’ again from the karma.conf.js.
|
||
|
||
Build process with integrated tests:
|
||
- Execute “grunt” to run the full build process with included tests
|
||
(If the full build process takes too long, the test task of grunt can
|
||
be executed with “grunt karma”).
|
||
- Grunt should report that the test has been successful. Reports of
|
||
the conducted tests can be found at
|
||
“REPO/test/<USED_BROWSER>/test-results.xml”.
|
||
|
||
|