@itee/tasks 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/configs/docs/doc.conf.mjs +55 -0
- package/docs/-_utils.mjs.html +848 -0
- package/docs/cleans_clean.task.mjs.html +239 -0
- package/docs/fonts/glyphicons-halflings-regular.eot +0 -0
- package/docs/fonts/glyphicons-halflings-regular.svg +288 -0
- package/docs/fonts/glyphicons-halflings-regular.ttf +0 -0
- package/docs/fonts/glyphicons-halflings-regular.woff +0 -0
- package/docs/fonts/glyphicons-halflings-regular.woff2 +0 -0
- package/docs/global.html +1668 -0
- package/docs/helps_help.task.mjs.html +362 -0
- package/docs/img/glyphicons-halflings-white.png +0 -0
- package/docs/img/glyphicons-halflings.png +0 -0
- package/docs/index.html +228 -0
- package/docs/lints_lint.task.mjs.html +252 -0
- package/docs/patches_patch.task.mjs.html +251 -0
- package/docs/quicksearch.html +31 -0
- package/docs/releases_release.task.mjs.html +238 -0
- package/docs/scripts/docstrap.lib.js +11 -0
- package/docs/scripts/fulltext-search-ui.js +89 -0
- package/docs/scripts/fulltext-search.js +36 -0
- package/docs/scripts/lunr.min.js +6 -0
- package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/docs/scripts/prettify/jquery.min.js +6 -0
- package/docs/scripts/prettify/lang-css.js +21 -0
- package/docs/scripts/prettify/prettify.js +496 -0
- package/docs/scripts/sunlight.js +1157 -0
- package/docs/scripts/toc.js +203 -0
- package/docs/styles/darkstrap.css +960 -0
- package/docs/styles/prettify-tomorrow.css +132 -0
- package/docs/styles/site.cerulean.css +7008 -0
- package/docs/styles/site.cosmo.css +7061 -0
- package/docs/styles/site.cyborg.css +7048 -0
- package/docs/styles/site.darkly.css +7171 -0
- package/docs/styles/site.darkstrap.css +5638 -0
- package/docs/styles/site.dibs-bootstrap.css +5899 -0
- package/docs/styles/site.flatly.css +7147 -0
- package/docs/styles/site.journal.css +6973 -0
- package/docs/styles/site.lumen.css +7298 -0
- package/docs/styles/site.paper.css +7623 -0
- package/docs/styles/site.readable.css +6997 -0
- package/docs/styles/site.sandstone.css +7035 -0
- package/docs/styles/site.simplex.css +7023 -0
- package/docs/styles/site.slate.css +7343 -0
- package/docs/styles/site.spacelab.css +7055 -0
- package/docs/styles/site.superhero.css +7131 -0
- package/docs/styles/site.united.css +6895 -0
- package/docs/styles/site.yeti.css +7195 -0
- package/docs/styles/sunlight.dark.css +345 -0
- package/docs/styles/sunlight.default.css +344 -0
- package/docs/tests_benchmarks_compute-benchmarks.task.mjs.html +442 -0
- package/docs/tests_benchmarks_run-benchmarks-for-backend.task.mjs.html +249 -0
- package/docs/tests_benchmarks_run-benchmarks-for-frontend.task.mjs.html +254 -0
- package/docs/tests_bundlings_check-bundling-from-esm-files-direct.task.mjs.html +300 -0
- package/docs/tests_bundlings_check-bundling.task.mjs.html +231 -0
- package/docs/tests_run-tests.task.mjs.html +228 -0
- package/docs/tests_units_compute-unit-tests.task.mjs.html +753 -0
- package/docs/tests_units_run-unit-tests-for-backend.task.mjs.html +254 -0
- package/docs/tests_units_run-unit-tests-for-frontend.task.mjs.html +254 -0
- package/package.json +5 -2
- package/sources/_utils.mjs +29 -3
- package/sources/patches/patch.task.mjs +45 -0
- package/configs/docs/doc.conf.json +0 -1
|
@@ -0,0 +1,753 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
|
|
3
|
+
<html lang="en">
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width">
|
|
7
|
+
<title>@itee/tasks v1.1.1 Source: tests/units/compute-unit-tests.task.mjs</title>
|
|
8
|
+
|
|
9
|
+
<!--[if lt IE 9]>
|
|
10
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
11
|
+
<![endif]-->
|
|
12
|
+
<link type="text/css" rel="stylesheet" href="styles/sunlight.dark.css">
|
|
13
|
+
|
|
14
|
+
<link type="text/css" rel="stylesheet" href="styles/site.cyborg.css">
|
|
15
|
+
|
|
16
|
+
</head>
|
|
17
|
+
|
|
18
|
+
<body>
|
|
19
|
+
|
|
20
|
+
<div class="navbar navbar-default navbar-fixed-top ">
|
|
21
|
+
<div class="container">
|
|
22
|
+
<div class="navbar-header">
|
|
23
|
+
<a class="navbar-brand" href="index.html">@itee/tasks v1.1.1</a>
|
|
24
|
+
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#topNavigation">
|
|
25
|
+
<span class="icon-bar"></span>
|
|
26
|
+
<span class="icon-bar"></span>
|
|
27
|
+
<span class="icon-bar"></span>
|
|
28
|
+
</button>
|
|
29
|
+
</div>
|
|
30
|
+
<div class="navbar-collapse collapse" id="topNavigation">
|
|
31
|
+
<ul class="nav navbar-nav">
|
|
32
|
+
|
|
33
|
+
<li class="dropdown">
|
|
34
|
+
<a href="global.html" class="dropdown-toggle" data-toggle="dropdown">Global<b class="caret"></b></a>
|
|
35
|
+
<ul class="dropdown-menu inline">
|
|
36
|
+
<li><a href="global.html#checkBundlingFromEsmFilesDirectTask">checkBundlingFromEsmFilesDirectTask</a></li><li><a href="global.html#checkBundlingTask">checkBundlingTask</a></li><li><a href="global.html#computeBenchmarksTask">computeBenchmarksTask</a></li><li><a href="global.html#computeUnitTestsTask">computeUnitTestsTask</a></li><li><a href="global.html#createRollupConfigs">createRollupConfigs</a></li><li><a href="global.html#npmrunclean">npm run clean</a></li><li><a href="global.html#npmrunhelpdefault">npm run help ( default )</a></li><li><a href="global.html#npmrunlint">npm run lint</a></li><li><a href="global.html#npmrunpatch">npm run patch</a></li><li><a href="global.html#npmrunrelease">npm run release</a></li><li><a href="global.html#npmruntest">npm run test</a></li><li><a href="global.html#runBenchmarksForBackendTask">runBenchmarksForBackendTask</a></li><li><a href="global.html#runBenchmarksForFrontendTask">runBenchmarksForFrontendTask</a></li><li><a href="global.html#runUnitTestsForBackendTask">runUnitTestsForBackendTask</a></li><li><a href="global.html#runUnitTestsForFrontendTask">runUnitTestsForFrontendTask</a></li>
|
|
37
|
+
</ul>
|
|
38
|
+
</li>
|
|
39
|
+
|
|
40
|
+
</ul>
|
|
41
|
+
|
|
42
|
+
<div class="col-sm-3 col-md-3">
|
|
43
|
+
<form class="navbar-form" role="search">
|
|
44
|
+
<div class="input-group">
|
|
45
|
+
<input type="text" class="form-control" placeholder="Search" name="q" id="search-input">
|
|
46
|
+
<div class="input-group-btn">
|
|
47
|
+
<button class="btn btn-default" id="search-submit"><i class="glyphicon glyphicon-search"></i></button>
|
|
48
|
+
</div>
|
|
49
|
+
</div>
|
|
50
|
+
</form>
|
|
51
|
+
</div>
|
|
52
|
+
|
|
53
|
+
</div>
|
|
54
|
+
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
<div class="container" id="toc-content">
|
|
60
|
+
<div class="row">
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
<div class="col-md-12">
|
|
64
|
+
|
|
65
|
+
<div id="main">
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
<h1 class="page-title">Source: tests/units/compute-unit-tests.task.mjs</h1>
|
|
69
|
+
|
|
70
|
+
<section>
|
|
71
|
+
<article>
|
|
72
|
+
<pre
|
|
73
|
+
class="sunlight-highlight-javascript linenums">import colors from 'ansi-colors'
|
|
74
|
+
import childProcess from 'child_process'
|
|
75
|
+
import log from 'fancy-log'
|
|
76
|
+
import { glob } from 'glob'
|
|
77
|
+
import { isNotEmptyArray } from 'itee-validators'
|
|
78
|
+
import {
|
|
79
|
+
basename,
|
|
80
|
+
dirname,
|
|
81
|
+
extname,
|
|
82
|
+
join,
|
|
83
|
+
normalize,
|
|
84
|
+
relative
|
|
85
|
+
} from 'path'
|
|
86
|
+
import {
|
|
87
|
+
createDirectoryIfNotExist,
|
|
88
|
+
createFile,
|
|
89
|
+
getPrettyPackageName,
|
|
90
|
+
getTaskConfigurationFor,
|
|
91
|
+
Indenter,
|
|
92
|
+
logLoadingTask,
|
|
93
|
+
packageName,
|
|
94
|
+
packageNodeModulesDirectory,
|
|
95
|
+
packageSourcesDirectory,
|
|
96
|
+
packageTestsUnitsDirectory
|
|
97
|
+
} from '../../_utils.mjs'
|
|
98
|
+
|
|
99
|
+
logLoadingTask( import.meta.filename )
|
|
100
|
+
|
|
101
|
+
const {
|
|
102
|
+
red,
|
|
103
|
+
yellow,
|
|
104
|
+
} = colors
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @description Will generate unit test files from source code using type inference from comments
|
|
108
|
+
*/
|
|
109
|
+
const computeUnitTestsTask = async ( done ) => {
|
|
110
|
+
|
|
111
|
+
createDirectoryIfNotExist( packageTestsUnitsDirectory )
|
|
112
|
+
|
|
113
|
+
// Get task configuration
|
|
114
|
+
const filePathsToIgnore = await getTaskConfigurationFor( import.meta.filename )
|
|
115
|
+
|
|
116
|
+
// Get source files to process
|
|
117
|
+
const pattern = join( packageSourcesDirectory, '**' )
|
|
118
|
+
const sourceFiles = glob.sync( pattern )
|
|
119
|
+
.map( filePath => normalize( filePath ) )
|
|
120
|
+
.filter( filePath => {
|
|
121
|
+
const fileName = basename( filePath )
|
|
122
|
+
const isJsFile = fileName.endsWith( '.js' )
|
|
123
|
+
const isNotPrivateFile = !fileName.startsWith( '_' )
|
|
124
|
+
const isNotIgnoredFile = !filePathsToIgnore.includes( fileName )
|
|
125
|
+
return isJsFile && isNotPrivateFile && isNotIgnoredFile
|
|
126
|
+
} )
|
|
127
|
+
|
|
128
|
+
const unitsImportMap = []
|
|
129
|
+
for ( let sourceFile of sourceFiles ) {
|
|
130
|
+
|
|
131
|
+
const specificFilePath = sourceFile.replace( packageSourcesDirectory, '' )
|
|
132
|
+
const specificDir = dirname( specificFilePath )
|
|
133
|
+
|
|
134
|
+
const fileName = basename( sourceFile, extname( sourceFile ) )
|
|
135
|
+
const unitFileName = `${ fileName }.unit.mjs`
|
|
136
|
+
const unitDirPath = join( packageTestsUnitsDirectory, specificDir )
|
|
137
|
+
const unitFilePath = join( unitDirPath, unitFileName )
|
|
138
|
+
|
|
139
|
+
const nsName = `${ fileName }Namespace`
|
|
140
|
+
const unitName = `${ fileName }Units`
|
|
141
|
+
const importDirPath = relative( unitDirPath, packageSourcesDirectory )
|
|
142
|
+
const importFilePath = join( importDirPath, specificFilePath ).replace( /\\/g, '/' )
|
|
143
|
+
|
|
144
|
+
try {
|
|
145
|
+
|
|
146
|
+
const jsdocPath = join( packageNodeModulesDirectory, '/jsdoc/jsdoc.js' )
|
|
147
|
+
const jsdocOutput = childProcess.execFileSync( 'node', [ jsdocPath, '-X', sourceFile ] ).toString()
|
|
148
|
+
|
|
149
|
+
const classNames = []
|
|
150
|
+
const usedLongnames = []
|
|
151
|
+
const jsonData = JSON.parse( jsdocOutput ).filter( data => {
|
|
152
|
+
|
|
153
|
+
const longName = data.longname
|
|
154
|
+
|
|
155
|
+
const kind = data.kind
|
|
156
|
+
if ( kind !== 'function' ) {
|
|
157
|
+
if ( kind === 'class' && !classNames.includes( longName ) ) {
|
|
158
|
+
classNames.push( longName )
|
|
159
|
+
}
|
|
160
|
+
return false
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const undocumented = data.undocumented
|
|
164
|
+
if ( undocumented ) {
|
|
165
|
+
return false
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const scope = data.scope
|
|
169
|
+
if ( ![ 'global', 'static' ].includes( scope ) ) {
|
|
170
|
+
return false
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if ( longName.includes( ' ' ) || longName.includes( '~' ) || usedLongnames.includes( longName ) ) {
|
|
174
|
+
return false
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
for ( let className of classNames ) {
|
|
178
|
+
if ( longName.includes( className ) ) {
|
|
179
|
+
return false
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
usedLongnames.push( longName )
|
|
184
|
+
|
|
185
|
+
return true
|
|
186
|
+
|
|
187
|
+
} )
|
|
188
|
+
|
|
189
|
+
if ( jsonData.length === 0 ) {
|
|
190
|
+
log( 'Ignoring', yellow( `${ sourceFile }, no usable exports found` ) )
|
|
191
|
+
continue
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
let describes = ''
|
|
195
|
+
const {
|
|
196
|
+
I,
|
|
197
|
+
I_,
|
|
198
|
+
I__,
|
|
199
|
+
I___,
|
|
200
|
+
} = new Indenter( '\t', 3 )
|
|
201
|
+
|
|
202
|
+
for ( let docData of jsonData ) {
|
|
203
|
+
|
|
204
|
+
try {
|
|
205
|
+
|
|
206
|
+
//check input parameters and types
|
|
207
|
+
const docParameters = docData.params || []
|
|
208
|
+
const parameters = []
|
|
209
|
+
for ( let pIndex = 0 ; pIndex < docParameters.length ; pIndex++ ) {
|
|
210
|
+
const param = docParameters[ pIndex ]
|
|
211
|
+
let paramName = param.name
|
|
212
|
+
if ( !paramName ) {
|
|
213
|
+
paramName = `param${ pIndex }`
|
|
214
|
+
log( yellow( `Missing parameter name for [${ docData.longname }]. Defaulting to [${ paramName }]` ) )
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const paramType = param.type
|
|
218
|
+
if ( !paramType ) {
|
|
219
|
+
throw new ReferenceError( `Missing parameter type. Unable to create unit test for [${ docData.longname }] !` )
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const parameter = {
|
|
223
|
+
name: paramName,
|
|
224
|
+
types: []
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const paramTypeNames = paramType.names
|
|
228
|
+
for ( let type of paramTypeNames ) {
|
|
229
|
+
parameter.types.push( type )
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
parameters.push( parameter )
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Check returns types
|
|
236
|
+
const docReturns = docData.returns || []
|
|
237
|
+
const returns = []
|
|
238
|
+
for ( let docReturn of docReturns ) {
|
|
239
|
+
const returnType = docReturn.type
|
|
240
|
+
if ( !returnType ) {
|
|
241
|
+
throw new ReferenceError( `Missing return type for [${ docData.longname }]. Ignore current target !` )
|
|
242
|
+
}
|
|
243
|
+
returns.push( ...returnType.names )
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Todo check throws
|
|
247
|
+
|
|
248
|
+
// Get user define rules
|
|
249
|
+
// const rules = []
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
// Infer basic rules
|
|
253
|
+
const baseIndent = 2
|
|
254
|
+
let its = ''
|
|
255
|
+
|
|
256
|
+
if ( parameters.length === 0 ) {
|
|
257
|
+
|
|
258
|
+
if ( returns.length === 0 ) {
|
|
259
|
+
|
|
260
|
+
const result = `${ I._( baseIndent + 1 ) }const result = ${ nsName }.${ docData.name }()` + '\n'
|
|
261
|
+
const expect = `${ I._( baseIndent + 1 ) }expect(result).to.be.a('undefined')` + '\n'
|
|
262
|
+
|
|
263
|
+
its += '' +
|
|
264
|
+
`${ I._( baseIndent ) }it( 'should return undefined value on call', async function () {` + '\n' +
|
|
265
|
+
'\n' +
|
|
266
|
+
`${ result }` +
|
|
267
|
+
`${ expect }` +
|
|
268
|
+
'\n' +
|
|
269
|
+
`${ I._( baseIndent ) }} )` + '\n'
|
|
270
|
+
|
|
271
|
+
} else if ( returns.length === 1 ) {
|
|
272
|
+
|
|
273
|
+
const firstReturnType = returns[ 0 ]
|
|
274
|
+
const lowerName = firstReturnType.toLowerCase()
|
|
275
|
+
|
|
276
|
+
const result = `${ I._( baseIndent + 1 ) }const result = ${ nsName }.${ docData.name }()` + '\n'
|
|
277
|
+
|
|
278
|
+
let expect = ''
|
|
279
|
+
if ( lowerName.startsWith( 'array' ) ) {
|
|
280
|
+
//todo array of...
|
|
281
|
+
expect += `${ I._( baseIndent + 1 ) }expect(result).to.be.a('array')` + '\n'
|
|
282
|
+
} else {
|
|
283
|
+
expect += `${ I._( baseIndent + 1 ) }expect(result).to.be.a('${ lowerName }')` + '\n'
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
its += '' +
|
|
287
|
+
`${ I._( baseIndent ) }it( 'should return value of type ${ lowerName }', async function() {` + '\n' +
|
|
288
|
+
'\n' +
|
|
289
|
+
`${ result }` +
|
|
290
|
+
`${ expect }` +
|
|
291
|
+
'\n' +
|
|
292
|
+
`${ I._( baseIndent ) }} )` + '\n'
|
|
293
|
+
|
|
294
|
+
} else {
|
|
295
|
+
|
|
296
|
+
const result = `${ I._( baseIndent + 1 ) }const result = ${ nsName }.${ docData.name }()` + '\n'
|
|
297
|
+
|
|
298
|
+
let returnTypesLabel = []
|
|
299
|
+
let oneOf = []
|
|
300
|
+
for ( let returnType of returns ) {
|
|
301
|
+
|
|
302
|
+
const lowerName = returnType.toLowerCase()
|
|
303
|
+
returnTypesLabel.push( lowerName )
|
|
304
|
+
|
|
305
|
+
if ( lowerName.startsWith( 'array' ) ) {
|
|
306
|
+
//todo array of...
|
|
307
|
+
oneOf.push( 'array' )
|
|
308
|
+
} else {
|
|
309
|
+
oneOf.push( `'${ lowerName }'` )
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const underlyingType = `${ I._( baseIndent + 1 ) }const resultType = (result === null) ? 'null' : typeof result` + '\n'
|
|
315
|
+
const expect = `${ I._( baseIndent + 1 ) }expect(resultType).to.be.oneOf([${ oneOf.join( ',' ) }])` + '\n'
|
|
316
|
+
|
|
317
|
+
its += '' +
|
|
318
|
+
`${ I._( baseIndent ) }it( 'should return value where type is ${ returnTypesLabel.join( ' or ' ) }', async function() {` + '\n' +
|
|
319
|
+
'\n' +
|
|
320
|
+
`${ result }` +
|
|
321
|
+
`${ underlyingType }` +
|
|
322
|
+
`${ expect }` +
|
|
323
|
+
'\n' +
|
|
324
|
+
`${ I._( baseIndent ) }} )` + '\n'
|
|
325
|
+
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
} else {
|
|
329
|
+
|
|
330
|
+
if ( returns.length === 0 ) {
|
|
331
|
+
|
|
332
|
+
let itDeclaration = []
|
|
333
|
+
let index = 0
|
|
334
|
+
let indent = baseIndent + 1
|
|
335
|
+
let localIndent = indent
|
|
336
|
+
let dataSets = ''
|
|
337
|
+
let forLoopOpens = ''
|
|
338
|
+
let forLoopCloses = ''
|
|
339
|
+
let args = []
|
|
340
|
+
for ( let parameter of parameters ) {
|
|
341
|
+
|
|
342
|
+
const parameterType = parameter.types[ 0 ]
|
|
343
|
+
itDeclaration.push( `${ parameter.name } is of type ${ parameterType }` )
|
|
344
|
+
|
|
345
|
+
dataSets += `${ I._( indent ) }const dataSet${ index } = _dataMap[ '${ parameterType }s' ]` + '\n'
|
|
346
|
+
// dataSets += `${ I._( indent ) }const dataSet${ index } = this._dataMap[ '${ parameterType }s' ]` + '\n'
|
|
347
|
+
forLoopOpens += '' + '\n' +
|
|
348
|
+
`${ I._( localIndent ) }for ( let key${ index } in dataSet${ index } ) {` + '\n' +
|
|
349
|
+
`${ I._( localIndent + 1 ) }const dataSetValue${ index } = dataSet${ index }[ key${ index } ]` + '\n'
|
|
350
|
+
|
|
351
|
+
args.push( `dataSetValue${ index }` )
|
|
352
|
+
|
|
353
|
+
forLoopCloses = `${ I._( localIndent ) }}` + '\n' + `${ forLoopCloses }`
|
|
354
|
+
|
|
355
|
+
index++
|
|
356
|
+
localIndent++
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const result = `${ I._( localIndent ) }const result = ${ nsName }.${ docData.name }( ${ args.join( ', ' ) } )` + '\n'
|
|
360
|
+
const expect = `${ I._( localIndent ) }expect(result).to.be.a('undefined')` + '\n'
|
|
361
|
+
|
|
362
|
+
const param = '' +
|
|
363
|
+
`${ dataSets }` +
|
|
364
|
+
`${ forLoopOpens }` +
|
|
365
|
+
`${ result }` +
|
|
366
|
+
`${ expect }` +
|
|
367
|
+
`${ forLoopCloses }`
|
|
368
|
+
|
|
369
|
+
its += '' +
|
|
370
|
+
`${ I._( baseIndent ) }it( 'should return undefined value when ${ itDeclaration.join( ' and ' ) }', async function() {` + '\n' +
|
|
371
|
+
'\n' +
|
|
372
|
+
`${ param }` +
|
|
373
|
+
'\n' +
|
|
374
|
+
`${ I._( baseIndent ) }} )` + '\n'
|
|
375
|
+
|
|
376
|
+
} else if ( returns.length === 1 ) {
|
|
377
|
+
|
|
378
|
+
const firstReturnType = returns[ 0 ]
|
|
379
|
+
const lowerName = firstReturnType.toLowerCase()
|
|
380
|
+
|
|
381
|
+
let itDeclaration = []
|
|
382
|
+
let index = 0
|
|
383
|
+
let indent = baseIndent + 1
|
|
384
|
+
let localIndent = indent
|
|
385
|
+
let dataSets = ''
|
|
386
|
+
let forLoopOpens = ''
|
|
387
|
+
let forLoopCloses = ''
|
|
388
|
+
let args = []
|
|
389
|
+
for ( let parameter of parameters ) {
|
|
390
|
+
|
|
391
|
+
const parameterType = parameter.types[ 0 ]
|
|
392
|
+
const isAnyType = ( parameterType === '*' || parameterType.toLowerCase() === 'any' )
|
|
393
|
+
const declaration = ( isAnyType )
|
|
394
|
+
? `${ parameter.name } is of any type`
|
|
395
|
+
: `${ parameter.name } is of type ${ parameterType }`
|
|
396
|
+
itDeclaration.push( declaration )
|
|
397
|
+
|
|
398
|
+
if ( isAnyType ) {
|
|
399
|
+
|
|
400
|
+
dataSets += `${ I._( indent ) }const dataMap${ index } = _dataMap` + '\n' +
|
|
401
|
+
// dataSets += `${ I._( indent ) }const dataMap${ index } = this._dataMap` + '\n' +
|
|
402
|
+
`${ I._( localIndent ) }for ( let dataSetKey${ index } in dataMap${ index } ) {` + '\n'
|
|
403
|
+
|
|
404
|
+
localIndent++
|
|
405
|
+
dataSets += `${ I._( indent + 1 ) }const dataSet${ index } = dataMap${ index }[ dataSetKey${ index } ]` + '\n'
|
|
406
|
+
forLoopOpens += '' + '\n' +
|
|
407
|
+
`${ I._( localIndent ) }for ( let key${ index } in dataSet${ index } ) {` + '\n' +
|
|
408
|
+
`${ I._( localIndent + 1 ) }const dataSetValue${ index } = dataSet${ index }[ key${ index } ]` + '\n'
|
|
409
|
+
|
|
410
|
+
args.push( `dataSetValue${ index }` )
|
|
411
|
+
|
|
412
|
+
forLoopCloses = `${ I._( localIndent ) }}` + '\n' +
|
|
413
|
+
`${ I._( localIndent - 1 ) }}` + '\n' +
|
|
414
|
+
`${ forLoopCloses }`
|
|
415
|
+
|
|
416
|
+
} else {
|
|
417
|
+
|
|
418
|
+
dataSets += `${ I._( indent ) }const dataSet${ index } = _dataMap[ '${ parameterType }s' ]` + '\n'
|
|
419
|
+
// dataSets += `${ I._( indent ) }const dataSet${ index } = this._dataMap[ '${ parameterType }s' ]` + '\n'
|
|
420
|
+
forLoopOpens += '' + '\n' +
|
|
421
|
+
`${ I._( localIndent ) }for ( let key${ index } in dataSet${ index } ) {` + '\n' +
|
|
422
|
+
`${ I._( localIndent + 1 ) }const dataSetValue${ index } = dataSet${ index }[ key${ index } ]` + '\n'
|
|
423
|
+
|
|
424
|
+
args.push( `dataSetValue${ index }` )
|
|
425
|
+
|
|
426
|
+
forLoopCloses = `${ I._( localIndent ) }}` + '\n' + `${ forLoopCloses }`
|
|
427
|
+
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
index++
|
|
432
|
+
localIndent++
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
const result = `${ I._( localIndent ) }const result = ${ nsName }.${ docData.name }( ${ args.join( ', ' ) } )` + '\n'
|
|
436
|
+
|
|
437
|
+
let expect = ''
|
|
438
|
+
if ( lowerName.startsWith( 'array' ) ) {
|
|
439
|
+
expect = `${ I._( localIndent ) }expect(result).to.be.a('array')` + '\n'
|
|
440
|
+
//todo array of...
|
|
441
|
+
} else {
|
|
442
|
+
expect = `${ I._( localIndent ) }expect(result).to.be.a('${ lowerName }')` + '\n'
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
const param = '' +
|
|
446
|
+
`${ dataSets }` +
|
|
447
|
+
`${ forLoopOpens }` +
|
|
448
|
+
`${ result }` +
|
|
449
|
+
`${ expect }` +
|
|
450
|
+
`${ forLoopCloses }`
|
|
451
|
+
|
|
452
|
+
its += '' +
|
|
453
|
+
`${ I._( baseIndent ) }it( 'should return value of type ${ lowerName } when ${ itDeclaration.join( ' and ' ) }', async function() {` + '\n' +
|
|
454
|
+
'\n' +
|
|
455
|
+
`${ param }` +
|
|
456
|
+
'\n' +
|
|
457
|
+
`${ I._( baseIndent ) }} )` + '\n'
|
|
458
|
+
|
|
459
|
+
} else {
|
|
460
|
+
|
|
461
|
+
let itDeclaration = []
|
|
462
|
+
let index = 0
|
|
463
|
+
let indent = baseIndent + 1
|
|
464
|
+
let localIndent = indent
|
|
465
|
+
let dataSets = ''
|
|
466
|
+
let forLoopOpens = ''
|
|
467
|
+
let forLoopCloses = ''
|
|
468
|
+
let args = []
|
|
469
|
+
for ( let parameter of parameters ) {
|
|
470
|
+
|
|
471
|
+
const parameterType = parameter.types[ 0 ]
|
|
472
|
+
itDeclaration.push( `${ parameter.name } is of type ${ parameterType }` )
|
|
473
|
+
|
|
474
|
+
dataSets += `${ I._( localIndent ) }const dataSet${ index } = _dataMap[ '${ parameterType }s' ]` + '\n'
|
|
475
|
+
// dataSets += `${ I._( indent ) }const dataSet${ index } = this._dataMap[ '${ parameterType }s' ]` + '\n'
|
|
476
|
+
forLoopOpens += '' + '\n' +
|
|
477
|
+
`${ I._( localIndent ) }for ( let key${ index } in dataSet${ index } ) {` + '\n' +
|
|
478
|
+
`${ I._( localIndent + 1 ) }const dataSetValue${ index } = dataSet${ index }[ key${ index } ]` + '\n'
|
|
479
|
+
|
|
480
|
+
args.push( `dataSetValue${ index }` )
|
|
481
|
+
|
|
482
|
+
forLoopCloses = `${ I._( localIndent ) }}` + '\n' + `${ forLoopCloses }`
|
|
483
|
+
|
|
484
|
+
index++
|
|
485
|
+
localIndent++
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const result = `${ I._( localIndent + 1 ) }const result = ${ nsName }.${ docData.name }( ${ args.join( ', ' ) } )` + '\n'
|
|
489
|
+
|
|
490
|
+
let returnTypesLabel = []
|
|
491
|
+
let oneOf = []
|
|
492
|
+
for ( let returnType of returns ) {
|
|
493
|
+
|
|
494
|
+
const lowerName = returnType.toLowerCase()
|
|
495
|
+
returnTypesLabel.push( lowerName )
|
|
496
|
+
|
|
497
|
+
if ( lowerName.startsWith( 'array' ) ) {
|
|
498
|
+
//todo array of...
|
|
499
|
+
oneOf.push( 'array' )
|
|
500
|
+
} else {
|
|
501
|
+
oneOf.push( `'${ lowerName }'` )
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
const underlyingType = `${ I._( localIndent + 1 ) }const resultType = (result === null) ? 'null' : typeof result` + '\n'
|
|
507
|
+
const expect = `${ I._( localIndent + 1 ) }expect(resultType).to.be.oneOf([${ oneOf.join( ',' ) }])` + '\n'
|
|
508
|
+
|
|
509
|
+
const param = '' +
|
|
510
|
+
`${ dataSets }` +
|
|
511
|
+
`${ forLoopOpens }` +
|
|
512
|
+
`${ result }` +
|
|
513
|
+
`${ underlyingType }` +
|
|
514
|
+
`${ expect }` +
|
|
515
|
+
`${ forLoopCloses }`
|
|
516
|
+
|
|
517
|
+
its += '' +
|
|
518
|
+
`${ I._( baseIndent ) }it( 'should return value of type ${ returnTypesLabel.join( ' or ' ) } when ${ itDeclaration.join( ' and ' ) }', async function() {` + '\n' +
|
|
519
|
+
'\n' +
|
|
520
|
+
`${ param }` +
|
|
521
|
+
'\n' +
|
|
522
|
+
`${ I._( baseIndent ) }} )` + '\n'
|
|
523
|
+
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
describes += '' +
|
|
529
|
+
`${ I_ }describe( '${ docData.name }()', function () {` + '\n' +
|
|
530
|
+
'\n' +
|
|
531
|
+
`${ I__ }it( 'should be bundlable', async function () {` + '\n' +
|
|
532
|
+
'\n' +
|
|
533
|
+
`${ I___ }expect(${ nsName }.${ docData.name }).to.exist` + '\n' +
|
|
534
|
+
'\n' +
|
|
535
|
+
`${ I__ }} )` + '\n' +
|
|
536
|
+
'\n' +
|
|
537
|
+
`${ its }` +
|
|
538
|
+
'\n' +
|
|
539
|
+
`${ I_ }} )` + '\n' +
|
|
540
|
+
'\n'
|
|
541
|
+
|
|
542
|
+
} catch ( error ) {
|
|
543
|
+
|
|
544
|
+
log( red( error.message ) )
|
|
545
|
+
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
const template = '' +
|
|
551
|
+
`import { expect } from 'chai'` + '\n' +
|
|
552
|
+
`import { Testing } from 'itee-utils/sources/testings/benchmarks.js'` + '\n' +
|
|
553
|
+
`import * as ${ nsName } from '${ importFilePath }'` + '\n' +
|
|
554
|
+
'\n' +
|
|
555
|
+
`describe( '${ unitName }', function () {` + '\n' +
|
|
556
|
+
'\n' +
|
|
557
|
+
`${ I_ }let _dataMap` + '\n' +
|
|
558
|
+
`${ I_ }before( function() {` + '\n' +
|
|
559
|
+
`${ I__ }_dataMap = Testing.createDataMap()` + '\n' +
|
|
560
|
+
`${ I_ }} )` + '\n' +
|
|
561
|
+
'\n' +
|
|
562
|
+
`${ describes }` +
|
|
563
|
+
'' +
|
|
564
|
+
`} )` + '\n'
|
|
565
|
+
|
|
566
|
+
const importUnitFilePath = relative( packageTestsUnitsDirectory, unitFilePath )
|
|
567
|
+
unitsImportMap.push( {
|
|
568
|
+
exportName: unitName,
|
|
569
|
+
path: importUnitFilePath.replace( /\\/g, '/' )
|
|
570
|
+
} )
|
|
571
|
+
|
|
572
|
+
createDirectoryIfNotExist( unitDirPath )
|
|
573
|
+
createFile( unitFilePath, template )
|
|
574
|
+
|
|
575
|
+
} catch ( error ) {
|
|
576
|
+
|
|
577
|
+
log( red( error.message ) )
|
|
578
|
+
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
// If some tests to import generate global units file
|
|
584
|
+
let unitsTemplate
|
|
585
|
+
if ( isNotEmptyArray( unitsImportMap ) ) {
|
|
586
|
+
|
|
587
|
+
let computedImports = []
|
|
588
|
+
for ( let entry of unitsImportMap ) {
|
|
589
|
+
// computedImports.push(`import { ${ entry.exportName } } from './${ entry.path }'`)
|
|
590
|
+
computedImports.push( `export * from './${ entry.path }'` )
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
unitsTemplate = computedImports.join( '\n' )
|
|
594
|
+
|
|
595
|
+
} else {
|
|
596
|
+
|
|
597
|
+
log( 'Warning ', yellow( 'No tests were generated. Create fallback global root import file.' ) )
|
|
598
|
+
const defaultUnitsDir = join( packageTestsUnitsDirectory, 'default' )
|
|
599
|
+
const defaultUnitsPath = join( defaultUnitsDir, 'default.unit.mjs' )
|
|
600
|
+
|
|
601
|
+
createDirectoryIfNotExist( defaultUnitsDir )
|
|
602
|
+
createFile( defaultUnitsPath, '// Avoid web test runner crash on empty benches' )
|
|
603
|
+
|
|
604
|
+
const prettyPackageName = getPrettyPackageName( '#' )
|
|
605
|
+
unitsTemplate = `describe( '${ prettyPackageName }', () => {} )` + '\n'
|
|
606
|
+
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
const unitsFilePath = join( packageTestsUnitsDirectory, `${ packageName }.units.mjs` )
|
|
610
|
+
createFile( unitsFilePath, unitsTemplate )
|
|
611
|
+
|
|
612
|
+
done()
|
|
613
|
+
|
|
614
|
+
}
|
|
615
|
+
computeUnitTestsTask.displayName = basename( import.meta.filename, '.task.mjs' )
|
|
616
|
+
computeUnitTestsTask.description = 'Will generate unit test files from source code using type inference from comments'
|
|
617
|
+
computeUnitTestsTask.flags = null
|
|
618
|
+
|
|
619
|
+
export { computeUnitTestsTask }</pre>
|
|
620
|
+
</article>
|
|
621
|
+
</section>
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
</div>
|
|
628
|
+
</div>
|
|
629
|
+
|
|
630
|
+
<div class="clearfix"></div>
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
</div>
|
|
635
|
+
</div>
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
<div class="modal fade" id="searchResults">
|
|
639
|
+
<div class="modal-dialog">
|
|
640
|
+
<div class="modal-content">
|
|
641
|
+
<div class="modal-header">
|
|
642
|
+
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
|
643
|
+
<h4 class="modal-title">Search results</h4>
|
|
644
|
+
</div>
|
|
645
|
+
<div class="modal-body"></div>
|
|
646
|
+
<div class="modal-footer">
|
|
647
|
+
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
|
648
|
+
</div>
|
|
649
|
+
</div><!-- /.modal-content -->
|
|
650
|
+
</div><!-- /.modal-dialog -->
|
|
651
|
+
</div>
|
|
652
|
+
|
|
653
|
+
|
|
654
|
+
<footer>
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
<span class="copyright">
|
|
658
|
+
Copyright 2015-Present <a href="https://github.com/Itee">Itee</a> (Tristan Valcke)
|
|
659
|
+
</span>
|
|
660
|
+
|
|
661
|
+
<span class="jsdoc-message">
|
|
662
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a>
|
|
663
|
+
|
|
664
|
+
using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
|
|
665
|
+
</span>
|
|
666
|
+
</footer>
|
|
667
|
+
|
|
668
|
+
<script src="scripts/docstrap.lib.js"></script>
|
|
669
|
+
<script src="scripts/toc.js"></script>
|
|
670
|
+
|
|
671
|
+
<script type="text/javascript" src="scripts/fulltext-search-ui.js"></script>
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
<script>
|
|
675
|
+
$( function () {
|
|
676
|
+
$( "[id*='$']" ).each( function () {
|
|
677
|
+
var $this = $( this );
|
|
678
|
+
|
|
679
|
+
$this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
|
|
680
|
+
} );
|
|
681
|
+
|
|
682
|
+
$( ".tutorial-section pre, .readme-section pre, pre.prettyprint.source" ).each( function () {
|
|
683
|
+
var $this = $( this );
|
|
684
|
+
|
|
685
|
+
var example = $this.find( "code" );
|
|
686
|
+
exampleText = example.html();
|
|
687
|
+
var lang = /{@lang (.*?)}/.exec( exampleText );
|
|
688
|
+
if ( lang && lang[1] ) {
|
|
689
|
+
exampleText = exampleText.replace( lang[0], "" );
|
|
690
|
+
example.html( exampleText );
|
|
691
|
+
lang = lang[1];
|
|
692
|
+
} else {
|
|
693
|
+
var langClassMatch = example.parent()[0].className.match(/lang\-(\S+)/);
|
|
694
|
+
lang = langClassMatch ? langClassMatch[1] : "javascript";
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
if ( lang ) {
|
|
698
|
+
|
|
699
|
+
$this
|
|
700
|
+
.addClass( "sunlight-highlight-" + lang )
|
|
701
|
+
.addClass( "linenums" )
|
|
702
|
+
.html( example.html() );
|
|
703
|
+
|
|
704
|
+
}
|
|
705
|
+
} );
|
|
706
|
+
|
|
707
|
+
Sunlight.highlightAll( {
|
|
708
|
+
lineNumbers : true,
|
|
709
|
+
showMenu : true,
|
|
710
|
+
enableDoclinks : true
|
|
711
|
+
} );
|
|
712
|
+
|
|
713
|
+
$.catchAnchorLinks( {
|
|
714
|
+
navbarOffset: 10
|
|
715
|
+
} );
|
|
716
|
+
$( "#toc" ).toc( {
|
|
717
|
+
anchorName : function ( i, heading, prefix ) {
|
|
718
|
+
return $( heading ).attr( "id" ) || ( prefix + i );
|
|
719
|
+
},
|
|
720
|
+
selectors : "#toc-content h1,#toc-content h2,#toc-content h3,#toc-content h4",
|
|
721
|
+
showAndHide : false,
|
|
722
|
+
smoothScrolling: true
|
|
723
|
+
} );
|
|
724
|
+
|
|
725
|
+
$( "#main span[id^='toc']" ).addClass( "toc-shim" );
|
|
726
|
+
$( '.dropdown-toggle' ).dropdown();
|
|
727
|
+
|
|
728
|
+
$( "table" ).each( function () {
|
|
729
|
+
var $this = $( this );
|
|
730
|
+
$this.addClass('table');
|
|
731
|
+
} );
|
|
732
|
+
|
|
733
|
+
} );
|
|
734
|
+
</script>
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
<!--Navigation and Symbol Display-->
|
|
739
|
+
|
|
740
|
+
|
|
741
|
+
<!--Google Analytics-->
|
|
742
|
+
|
|
743
|
+
|
|
744
|
+
|
|
745
|
+
<script type="text/javascript">
|
|
746
|
+
$(document).ready(function() {
|
|
747
|
+
SearcherDisplay.init();
|
|
748
|
+
});
|
|
749
|
+
</script>
|
|
750
|
+
|
|
751
|
+
|
|
752
|
+
</body>
|
|
753
|
+
</html>
|