| Jeremy Mordkoff | e29efc3 | 2016-09-07 18:59:17 -0400 | [diff] [blame] | 1 | define(function (require) { |
| 2 | var base_plugins = ['about', 'accounts', 'composer', 'debug', 'goodbyeworld', 'helloworld', 'launchpad', 'logging']; |
| 3 | var registerSuite = require('intern!object'); |
| 4 | var assert = require('intern/chai!assert'); |
| 5 | var plugin_discoverer = require('intern/dojo/node!../../framework/core/modules/plugin_discoverer.js'); |
| 6 | var skyquakeEmitter = require('intern/dojo/node!../../framework/core/modules/skyquakeEmitter.js'); |
| 7 | var _ = require('intern/dojo/node!lodash'); |
| 8 | var fs = require('intern/dojo/node!fs'); |
| 9 | registerSuite({ |
| 10 | name: 'plugin_discoverer', |
| 11 | before: function() { |
| 12 | |
| 13 | }, |
| 14 | after: function() { |
| 15 | // Exit process. |
| 16 | // TODO: Should cleanup plugin_discoverer instead and call that |
| 17 | setTimeout(function() { |
| 18 | var path = process.cwd() + '/plugins/helloworld/test.txt'; |
| 19 | fs.unlinkSync(path); |
| 20 | process.exit(0); |
| 21 | }); |
| 22 | }, |
| 23 | 'Test init': function () { |
| 24 | var res = plugin_discoverer.init(); |
| 25 | assert.isUndefined(res, 'return value is undefined'); |
| 26 | }, |
| 27 | 'Test config': function() { |
| 28 | var path = process.cwd() + '/plugins'; |
| 29 | var res = plugin_discoverer.config({ |
| 30 | plugins_path: path |
| 31 | }); |
| 32 | assert.isUndefined(res, 'return value is undefined'); |
| 33 | }, |
| 34 | 'Test run plugin add discovery': function() { |
| 35 | var deferred = this.async(); |
| 36 | |
| 37 | var plugins_detected = []; |
| 38 | |
| 39 | skyquakeEmitter.on('plugin_discoverer.plugin_discovered', function(plugin_name) { |
| 40 | plugins_detected.push(plugin_name); |
| 41 | if (_.intersection(plugins_detected, base_plugins).length == 8 ) { |
| 42 | // all expected plugins were discovered |
| 43 | deferred.resolve('All expected plugins discovered'); |
| 44 | } |
| 45 | }); |
| 46 | |
| 47 | var res = plugin_discoverer.run(); |
| 48 | }, |
| 49 | 'Test run plugin update discovery': function() { |
| 50 | var deferred = this.async(); |
| 51 | |
| 52 | setTimeout(function() { |
| 53 | var path = process.cwd() + '/plugins/helloworld/test.txt'; |
| 54 | fs.openSync(path, 'a+'); |
| 55 | }); |
| 56 | |
| 57 | skyquakeEmitter.on('plugin_discoverer.plugin_updated', function(plugin_name) { |
| 58 | deferred.resolve(); |
| 59 | }); |
| 60 | }, |
| 61 | }); |
| 62 | }); |