-
Notifications
You must be signed in to change notification settings - Fork 74
Testing
Testing in DeepForge is currently done using mocha and can be run using
npm testDuring development, I recommend using nodemon. nodemon is a utility to execute some given command whenever certain files change. That is, running the following command from the DeepForge root:
nodemon -w src -w test --exec npm testwill result in the tests being automatically run whenever a src or test file is updated (saved). nodemon can be installed from npm with npm install -g nodemon`
Plugins are generally tested by
- loading a given seed
- running the plugin with some given config
- testing either the...
- updated model
- generated plugin artifacts.
Almost all plugins are run on the devTests seed. Most plugins create read from test/test-cases or are given a list of test cases and generate the tests on the fly. For example, in the GenerateArchitecture plugin, we can find a variation of the below code snippet:
describe('test cases', function() {
var cases = [
['/4', 'basic.lua'],
['/T', 'basic-transfers.lua'],
['/W', 'overfeat.lua']
// etc
];
var runTest = function(pair, done) {
var id = pair[0], // node path to run plugin on
name = pair[1]; // filename to look up and compare output to
// omitted for simplicity in this example.
};
// Creates each test case!
cases.forEach(pair => {
it(`should correctly evaluate ${pair[0]} (${pair[1]})`,
runTest.bind(this, pair));
});
});In this code snippet, additional test cases can be added by adding another nodePath-filename "tuple" to the cases array. This results in another test being created in the cases.forEach... portion at the bottom of the snippet. The runTest method will then
- find the node (by it's path) in the
devTestsseed - run the plugin on the given node
- get the generated code and compare it with
test-cases/generated-code/FILENAME- where
FILENAMEis the second element in the given test case pair
- where
It is worth noting that, when adding new test cases, you will often need to add new nodes to the devTests seed. This can be done as follows:
From the browser (dev mode):
- Click on the logo in the top left
- Select "Import Project"
- Type "devTests" (and enter)
- Select the file
src/seeds/devTests/devTests.webgmex - Click "Create"
Now you have loaded the devTests seed and can add nodes as desired. Once you have made your given edits and want to use them in the tests, run webgme new seed devTests from the DeepForge root.
Currently, you will also need to update the webgmex file that was used to load devTests initially (this step will be removed in future versions):
From the browser (dev mode):
- Open the
devTestsproject - Click on "master" in the header bar (the branch name)
- Select "Export branch..."
- This should download a file called
guest+devTests.webgmex
- This should download a file called
- Move and rename the downloaded file to
src/seeds/devTests/devTests.webgmex
Intro
Development
Design Notes