MCPcopy
hub / github.com/mongodb/node-mongodb-native / _parseArgs

Function _parseArgs

test/tools/runner/metadata_ui.js:34–84  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

32 * @param {any} args
33 */
34 var _parseArgs = function (args) {
35 var testData = {};
36 if (typeof args[0] !== 'string') {
37 throw new Error('First argument must be a string.');
38 }
39 testData.title = args[0];
40 if (args.length === 1) {
41 // Only a title, to mark a pending test
42 return testData;
43 } else if (args.length === 2) {
44 // No metadata, describe(title, fn), or metadata as an object, describe(title, obj)
45 if (typeof args[1] === 'object') {
46 if (args[1].metadata && typeof args[1].metadata === 'object') {
47 testData.metadata = args[1].metadata;
48 if (args[1].tests && typeof args[1].tests === 'function') {
49 testData.fn = args[1].tests;
50 } else if (args[1].test && typeof args[1].test === 'function') {
51 testData.fn = args[1].test;
52 } else {
53 throw new Error(
54 'If passing an object as the second parameter, it must be of the form { <object>, <function> }'
55 );
56 }
57 } else {
58 throw new Error(
59 'If passing an object as the second parameter, it must be of the form { <object>, <function> }'
60 );
61 }
62 } else if (typeof args[1] === 'function') {
63 testData.fn = args[1];
64 } else {
65 throw new Error(
66 'Incorrect usage. Parameters must be either "<string>, { <object>, <function> }" or "<string>, <function>"'
67 );
68 }
69 } else if (args.length === 3) {
70 // Metadata as a param: describe(title, meta, fn)
71 if (args[1] && typeof args[1] === 'object' && args[2] && typeof args[2] === 'function') {
72 testData.metadata = args[1];
73 testData.fn = args[2];
74 } else {
75 throw new Error(
76 'If passing three parameters, they must be of the form "<string>, <object>, <function>"'
77 );
78 }
79 } else if (args.length > 3) {
80 throw new Error('Too many arguments passed.');
81 }
82
83 return testData;
84 };
85
86 /**
87 * Create new suite that can contain metadata

Callers 2

_createFunction · 0.85
metadata_ui.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected