UNPKG

2.42 kBJavaScriptView Raw
1/**
2 * @fileoverview NodeUnit test
3 * @copyright Bertrand Chevrier 2012
4 * @author Bertrand Chevrier <chevrier.bertrand@gmail.com>
5 * @license MIT
6 *
7 * @module test/jsdoc-plugin_test
8 */
9
10/**
11 * This function enables you to extract
12 * the declared arguments from a function.
13 * @param {Function} fn - the function to extract the arguments for
14 * @returns {Array} the list of arguments
15 * @throw {Error} in case of wrong argument given
16 */
17var extractArgs = function(fn) {
18 'use strict';
19
20 if (typeof fn !== 'function') {
21 throw new Error('TypeError : The extractArgs function requires the fn argument to be a function!');
22 }
23 return fn.toString().match(/function\s+\w*\s*\((.*?)\)/)[1].split(/\s*,\s*/);
24};
25
26/**
27 * NodeUnit group of test that check the jsdoc Grunt task.
28 *
29 * @see https://github.com/caolan/nodeunit/
30 *
31 * @class JsdocTest
32 */
33exports.JsdocTest = {
34
35 /**
36 * Set up the test by load the tasks/jsdoc-plugin module
37 * @memberOf JsdocTest
38 * @param {Function} done - to call once the setup is done.
39 */
40 setUp: function(done) {
41 'use strict';
42
43 this.jsdocTask = require('../tasks/jsdoc-plugin');
44 done();
45 },
46
47 /**
48 * Check the task is loaded and complies with the grunt requirements.
49 * @memberOf JsdocTest
50 * @param {Object} test - the node unit test context
51 */
52 'taskCheck': function(test) {
53 'use strict';
54
55 test.notStrictEqual(this.jsdocTask, undefined, 'the jsdoc task should be set up');
56 test.equal(typeof this.jsdocTask, 'function', 'the task must be a function');
57
58 var taskArgs = extractArgs(this.jsdocTask);
59 test.ok(taskArgs.length > 0 && taskArgs[0] === 'grunt', 'the task must declare the grunt context as 1st parameter');
60
61 test.done();
62 },
63
64 /**
65 * Do some check on the exec library
66 * @memberOf JsdocTest
67 * @param {Object} test - the node unit test context
68 */
69 'execCheck': function(test) {
70 'use strict';
71
72 var exec = require('../tasks/lib/exec');
73
74 test.notStrictEqual(exec, undefined, 'the exec lib should be required');
75 test.equal(typeof exec, 'object', 'exec is an object');
76
77 test.equal(typeof exec.buildSpawned, 'function', 'exec must have a buildSpawned method');
78 test.equal(typeof exec.lookup, 'function', 'exec must have a lookup method');
79
80 test.done();
81 }
82};
83