Skip to content

Testing

Brian Broll edited this page Apr 29, 2016 · 3 revisions

Testing

Testing in DeepForge is currently done using mocha and can be run using

npm test

During 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 test

will 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

Plugins are generally tested by

  • loading a given seed
  • running the plugin with some given config
  • testing either the...
    • updated model
    • generated plugin artifacts.

Adding Test Cases

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 devTests seed
  • run the plugin on the given node
  • get the generated code and compare it with test-cases/generated-code/FILENAME
    • where FILENAME is the second element in the given test case pair

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 "New Project"
  • Type "devTests" (and enter)
  • Select the seed devTests
  • 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.

Clone this wiki locally