itee-validators 5.6.0 → 6.0.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.
Files changed (131) hide show
  1. package/.github/workflows/node.js.yml +2 -2
  2. package/.releaserc.mjs +94 -0
  3. package/.tasks/.builds/build-benchmarks.task.mjs +16 -0
  4. package/.tasks/.builds/build-tests.task.mjs +18 -0
  5. package/.tasks/.builds/build-unit-tests.task.mjs +16 -0
  6. package/.tasks/.builds/build.task.mjs +46 -0
  7. package/.tasks/.cleans/clean.task.mjs +23 -0
  8. package/.tasks/.docs/doc.task.mjs +35 -0
  9. package/.tasks/.helps/help.task.mjs +151 -0
  10. package/.tasks/.lints/lint.task.mjs +37 -0
  11. package/.tasks/.patches/patch.task.mjs +13 -0
  12. package/.tasks/.releases/release.task.mjs +26 -0
  13. package/.tasks/.tests/benchmarks/build-benchmarks-backend.task.mjs +42 -0
  14. package/.tasks/{tests/benchmarks/compute-benchmarks.mjs → .tests/benchmarks/compute-benchmarks.task.mjs} +46 -51
  15. package/.tasks/.tests/benchmarks/run-benchmarks-for-backend.task.mjs +39 -0
  16. package/.tasks/.tests/benchmarks/run-benchmarks-for-frontend.task.mjs +41 -0
  17. package/.tasks/.tests/benchmarks/run-benchmarks.task.mjs +18 -0
  18. package/.tasks/{tests/bundling/check-bundling-from-esm-build-import.mjs → .tests/bundling/check-bundling-from-esm-build-import.task.mjs} +31 -75
  19. package/.tasks/.tests/bundling/check-bundling-from-esm-files-direct.task.mjs +77 -0
  20. package/.tasks/.tests/bundling/check-bundling-from-esm-files-import.task.mjs +95 -0
  21. package/.tasks/.tests/bundling/check-bundling.task.mjs +20 -0
  22. package/.tasks/.tests/run-tests.task.mjs +18 -0
  23. package/.tasks/.tests/unit-tests/build-unit-tests-backend.task.mjs +42 -0
  24. package/.tasks/{tests/unit-tests/compute-unit-tests.mjs → .tests/unit-tests/compute-unit-tests.task.mjs} +152 -193
  25. package/.tasks/.tests/unit-tests/run-unit-tests-for-backend.task.mjs +44 -0
  26. package/.tasks/.tests/unit-tests/run-unit-tests-for-frontend.task.mjs +41 -0
  27. package/.tasks/.tests/unit-tests/run-unit-tests.task.mjs +18 -0
  28. package/.tasks/_refresh-gulpfile.task.mjs +65 -0
  29. package/.tasks/_utils.mjs +159 -33
  30. package/.tasks/configs/benchmarks.conf.mjs +57 -0
  31. package/.tasks/configs/build-benchmarks-backend.conf.mjs +51 -0
  32. package/.tasks/configs/build-unit-tests-backend.conf.mjs +46 -0
  33. package/.tasks/configs/build.conf.mjs +354 -0
  34. package/.tasks/configs/check-bundling.conf.mjs +26 -0
  35. package/.tasks/configs/clean.conf.mjs +9 -0
  36. package/.tasks/configs/compute-benchmarks.conf.mjs +28 -0
  37. package/.tasks/configs/compute-unit-tests.conf.mjs +27 -0
  38. package/.tasks/configs/doc.conf.json +50 -0
  39. package/.tasks/configs/eslint.conf.mjs +121 -0
  40. package/.tasks/configs/units.conf.mjs +27 -0
  41. package/.tasks/itee-benchmarks-framework.js +186 -0
  42. package/.tasks/itee-reporter.mjs +217 -0
  43. package/CHANGELOG.md +12 -0
  44. package/builds/itee-validators.cjs.js +53 -15
  45. package/builds/itee-validators.cjs.js.map +1 -1
  46. package/builds/itee-validators.cjs.min.js +36 -35
  47. package/builds/itee-validators.esm.js +25 -2
  48. package/builds/itee-validators.esm.js.map +1 -1
  49. package/builds/itee-validators.esm.min.js +3 -3
  50. package/builds/itee-validators.iife.js +25 -4
  51. package/builds/itee-validators.iife.js.map +1 -1
  52. package/builds/itee-validators.iife.min.js +10 -10
  53. package/package.json +49 -41
  54. package/sources/cores/_cores.js +10 -10
  55. package/sources/cores/arrays/_arrays.js +12 -12
  56. package/sources/cores/arrays/isArrayOfArray.js +2 -2
  57. package/sources/cores/arrays/isArrayOfBoolean.js +3 -3
  58. package/sources/cores/arrays/isArrayOfFunction.js +3 -3
  59. package/sources/cores/arrays/isArrayOfMultiElement.js +1 -1
  60. package/sources/cores/arrays/isArrayOfNull.js +3 -3
  61. package/sources/cores/arrays/isArrayOfNumber.js +3 -3
  62. package/sources/cores/arrays/isArrayOfObject.js +3 -3
  63. package/sources/cores/arrays/isArrayOfSingleElement.js +1 -1
  64. package/sources/cores/arrays/isArrayOfString.js +3 -3
  65. package/sources/cores/arrays/isArrayOfUndefined.js +3 -3
  66. package/sources/cores/arrays/isEmptyArray.js +1 -1
  67. package/sources/cores/booleans/_booleans.js +2 -2
  68. package/sources/cores/booleans/isTrue.js +1 -1
  69. package/sources/cores/cores.js +8 -8
  70. package/sources/cores/functions/_functions.js +1 -1
  71. package/sources/cores/numbers/_numbers.js +6 -6
  72. package/sources/cores/numbers/isNumber.js +3 -3
  73. package/sources/cores/objects/_objects.js +2 -2
  74. package/sources/cores/objects/isEmptyObject.js +1 -1
  75. package/sources/cores/objects/isObject.js +1 -1
  76. package/sources/cores/strings/_strings.js +3 -3
  77. package/sources/cores/strings/isBlankString.js +2 -2
  78. package/sources/cores/strings/isEmptyString.js +1 -1
  79. package/sources/cores/symbols/_symbols.js +1 -1
  80. package/sources/cores/tests/isTestUnitGenerator.js +5 -6
  81. package/sources/cores/typed-arrays/_typedArrays.js +12 -12
  82. package/sources/cores/voids/_voids.js +4 -4
  83. package/sources/cores/voids/isEmpty.js +4 -4
  84. package/sources/file-system/_file-system.js +9 -9
  85. package/sources/file-system/block-devices/_blockDevices.js +3 -3
  86. package/sources/file-system/block-devices/isBlockDevicePath.js +3 -3
  87. package/sources/file-system/block-devices/isValidBlockDevicePath.js +2 -2
  88. package/sources/file-system/character-devices/_characterDevices.js +3 -3
  89. package/sources/file-system/character-devices/isCharacterDevicePath.js +3 -3
  90. package/sources/file-system/character-devices/isValidCharacterDevicePath.js +2 -2
  91. package/sources/file-system/directories/_directories.js +4 -4
  92. package/sources/file-system/directories/isDirectoryPath.js +3 -3
  93. package/sources/file-system/directories/isEmptyDirectory.js +2 -2
  94. package/sources/file-system/directories/isValidDirectoryPath.js +2 -2
  95. package/sources/file-system/fifo-pipes/_fifoPipes.js +3 -3
  96. package/sources/file-system/fifo-pipes/isFIFOPath.js +3 -3
  97. package/sources/file-system/fifo-pipes/isValidFIFOPath.js +2 -2
  98. package/sources/file-system/files/_files.js +4 -4
  99. package/sources/file-system/files/isEmptyFile.js +3 -3
  100. package/sources/file-system/files/isFilePath.js +3 -3
  101. package/sources/file-system/files/isValidFilePath.js +2 -2
  102. package/sources/file-system/paths/_paths.js +2 -2
  103. package/sources/file-system/paths/isValidPath.js +1 -1
  104. package/sources/file-system/sockets/_sockets.js +3 -3
  105. package/sources/file-system/sockets/isSocketPath.js +3 -3
  106. package/sources/file-system/sockets/isValidSocketPath.js +2 -2
  107. package/sources/file-system/symbolic-links/_symbolicLinks.js +3 -3
  108. package/sources/file-system/symbolic-links/isSymbolicLinkPath.js +3 -3
  109. package/sources/file-system/symbolic-links/isValidSymbolicLinkPath.js +2 -2
  110. package/sources/itee-validators.js +4 -4
  111. package/sources/maths/_maths.js +1 -1
  112. package/sources/physics/_physics.js +2 -2
  113. package/sources/physics/temperatures/_temperatures.js +5 -5
  114. package/sources/physics/temperatures/isCelsius.js +2 -2
  115. package/sources/physics/temperatures/isFahrenheit.js +2 -2
  116. package/sources/physics/temperatures/isKelvin.js +2 -2
  117. package/sources/physics/temperatures/isTemperature.js +3 -3
  118. package/.tasks/builds/build.mjs +0 -65
  119. package/.tasks/cleans/clean.mjs +0 -20
  120. package/.tasks/docs/doc.mjs +0 -37
  121. package/.tasks/helps/help.mjs +0 -195
  122. package/.tasks/lints/lint.mjs +0 -33
  123. package/.tasks/patches/patch.mjs +0 -9
  124. package/.tasks/tests/benchmarks/bundle-benchmarks.mjs +0 -33
  125. package/.tasks/tests/benchmarks/run-benchmarks-for-backend.mjs +0 -24
  126. package/.tasks/tests/benchmarks/run-benchmarks-for-frontend.mjs +0 -38
  127. package/.tasks/tests/bundling/check-bundling-from-esm-files-direct.mjs +0 -129
  128. package/.tasks/tests/bundling/check-bundling-from-esm-files-import.mjs +0 -149
  129. package/.tasks/tests/unit-tests/bundle-unit-tests.mjs +0 -33
  130. package/.tasks/tests/unit-tests/run-unit-tests-for-backend.mjs +0 -25
  131. package/.tasks/tests/unit-tests/run-unit-tests-for-frontend.mjs +0 -41
@@ -1,52 +1,43 @@
1
+ import colors from 'ansi-colors'
2
+ import childProcess from 'child_process'
3
+ import log from 'fancy-log'
4
+ import {
5
+ existsSync,
6
+ mkdirSync,
7
+ writeFileSync
8
+ } from 'fs'
9
+ import { isNotEmptyArray } from 'itee-validators'
1
10
  import {
2
- join,
3
- normalize,
4
11
  basename,
5
12
  dirname,
6
13
  extname,
14
+ join,
7
15
  relative
8
- } from 'path'
16
+ } from 'path'
9
17
  import {
10
- getDirname,
11
- packageInfos
12
- } from '../../_utils.mjs'
13
- import glob from 'glob'
14
- import fs from 'fs'
15
- import log from 'fancy-log'
16
- import colors from 'ansi-colors'
17
- import { getGulpConfigForTask } from '../../../configs/gulp.conf.mjs'
18
- import childProcess from 'child_process'
18
+ Indenter,
19
+ nodeModulesDirectory,
20
+ packageName,
21
+ packageSourcesDirectory as sourcesDir,
22
+ packageTestsUnitsDirectory as unitsDir
23
+ } from '../../_utils.mjs'
24
+ import { sourcesFiles } from '../../configs/compute-unit-tests.conf.mjs'
19
25
 
20
26
  const {
21
27
  red,
22
28
  green,
23
- blue,
24
- cyan,
25
- yellow,
26
- magenta
29
+ yellow
27
30
  } = colors
28
31
 
32
+ /**
33
+ * @description Will generate unit test files from source code using type inference from comments
34
+ */
35
+ const computeUnitTestsTask = ( done ) => {
29
36
 
30
- function computeUnitTests( done ) {
31
-
32
- const baseDir = getDirname()
33
- const sourcesDir = join( baseDir, 'sources' )
34
- const testsDir = join( baseDir, 'tests' )
35
- const unitsDir = join( testsDir, 'units' )
36
-
37
- fs.mkdirSync( unitsDir, { recursive: true } )
38
-
39
- const filePathsToIgnore = getGulpConfigForTask( 'compute-unit-tests' )
40
-
41
- const sourcesFiles = glob.sync( join( sourcesDir, '**' ) )
42
- .map( filePath => normalize( filePath ) )
43
- .filter( filePath => {
44
- const fileName = basename( filePath )
45
- const isJsFile = fileName.endsWith( '.js' )
46
- const isNotPrivateFile = !fileName.startsWith( '_' )
47
- const isNotIgnoredFile = !filePathsToIgnore.includes( fileName )
48
- return isJsFile && isNotPrivateFile && isNotIgnoredFile
49
- } )
37
+ if ( !existsSync( unitsDir ) ) {
38
+ log( 'Creating', green( unitsDir ) )
39
+ mkdirSync( unitsDir, { recursive: true } )
40
+ }
50
41
 
51
42
  const unitsImportMap = []
52
43
  for ( let sourceFile of sourcesFiles ) {
@@ -55,7 +46,7 @@ function computeUnitTests( done ) {
55
46
  const specificDir = dirname( specificFilePath )
56
47
 
57
48
  const fileName = basename( sourceFile, extname( sourceFile ) )
58
- const unitFileName = `${ fileName }.unit.js`
49
+ const unitFileName = `${ fileName }.unit.mjs`
59
50
  const unitDirPath = join( unitsDir, specificDir )
60
51
  const unitFilePath = join( unitDirPath, unitFileName )
61
52
 
@@ -66,9 +57,8 @@ function computeUnitTests( done ) {
66
57
 
67
58
  try {
68
59
 
69
- const jsdocPath = join( baseDir, '/node_modules/jsdoc/jsdoc.js' )
70
- const jsdocOutput = childProcess.execFileSync( 'node', [ jsdocPath, '-X', sourceFile ] )
71
- .toString()
60
+ const jsdocPath = join( nodeModulesDirectory, '/jsdoc/jsdoc.js' )
61
+ const jsdocOutput = childProcess.execFileSync( 'node', [ jsdocPath, '-X', sourceFile ] ).toString()
72
62
 
73
63
  const classNames = []
74
64
  const usedLongnames = []
@@ -111,17 +101,17 @@ function computeUnitTests( done ) {
111
101
  } )
112
102
 
113
103
  if ( jsonData.length === 0 ) {
114
- log( yellow( `No usable exports found in [${ sourceFile }]. Ignore it !` ) )
104
+ log( 'Ignoring', yellow( `${ sourceFile }, no usable exports found` ) )
115
105
  continue
116
106
  }
117
107
 
118
108
  let describes = ''
119
- const I = n => '\t'.repeat( n )
120
- I._ = I( 1 )
121
- I.__ = I( 2 )
122
- I.___ = I( 3 )
123
- I.____ = I( 4 )
124
- I._____ = I( 5 )
109
+ const {
110
+ I,
111
+ I_,
112
+ I__,
113
+ I___,
114
+ } = new Indenter( '\t', 3 )
125
115
 
126
116
  for ( let docData of jsonData ) {
127
117
 
@@ -135,8 +125,7 @@ function computeUnitTests( done ) {
135
125
  let paramName = param.name
136
126
  if ( !paramName ) {
137
127
  paramName = `param${ pIndex }`
138
- // eslint-disable-next-line no-console
139
- console.warn( `Missing parameter name for [${ docData.longname }]. Defaulting to [${ paramName }]` )
128
+ log( yellow( `Missing parameter name for [${ docData.longname }]. Defaulting to [${ paramName }]` ) )
140
129
  }
141
130
 
142
131
  const paramType = param.type
@@ -175,91 +164,78 @@ function computeUnitTests( done ) {
175
164
 
176
165
 
177
166
  // Infer basic rules
178
- let its = ''
167
+ const baseIndent = 2
168
+ let its = ''
179
169
 
180
170
  if ( parameters.length === 0 ) {
181
171
 
182
172
  if ( returns.length === 0 ) {
183
173
 
184
- const result = `${ I( 1 + 1 + 1 + 1 ) }const result = ${ nsName }.${ docData.name }()` + '\n'
185
- const expect = `${ I( 1 + 1 + 1 + 1 ) }expect(result).to.be.a('undefined')` + '\n'
174
+ const result = `${ I._( baseIndent + 1 ) }const result = ${ nsName }.${ docData.name }()` + '\n'
175
+ const expect = `${ I._( baseIndent + 1 ) }expect(result).to.be.a('undefined')` + '\n'
186
176
 
187
177
  its += '' +
188
- `${ I( 1 + 1 + 1 ) }it( 'return type is undefined', () => {` + '\n' +
178
+ `${ I._( baseIndent ) }it( 'should return undefined value on call', async function () {` + '\n' +
189
179
  '\n' +
190
180
  `${ result }` +
191
181
  `${ expect }` +
192
182
  '\n' +
193
- `${ I( 1 + 1 + 1 ) }} )` + '\n'
183
+ `${ I._( baseIndent ) }} )` + '\n'
194
184
 
195
185
  } else if ( returns.length === 1 ) {
196
186
 
197
187
  const firstReturnType = returns[ 0 ]
198
188
  const lowerName = firstReturnType.toLowerCase()
199
189
 
200
- const result = `${ I( 1 + 1 + 1 + 1 ) }const result = ${ nsName }.${ docData.name }()` + '\n'
190
+ const result = `${ I._( baseIndent + 1 ) }const result = ${ nsName }.${ docData.name }()` + '\n'
201
191
 
202
192
  let expect = ''
203
193
  if ( lowerName.startsWith( 'array' ) ) {
204
194
  //todo array of...
205
- expect += `${ I( 1 + 1 + 1 + 1 ) }expect(result).to.be.a('array')` + '\n'
195
+ expect += `${ I._( baseIndent + 1 ) }expect(result).to.be.a('array')` + '\n'
206
196
  } else {
207
- expect += `${ I( 1 + 1 + 1 + 1 ) }expect(result).to.be.a('${ lowerName }')` + '\n'
197
+ expect += `${ I._( baseIndent + 1 ) }expect(result).to.be.a('${ lowerName }')` + '\n'
208
198
  }
209
199
 
210
200
  its += '' +
211
- `${ I( 1 + 1 + 1 ) }it( 'return type is ${ lowerName }', () => {` + '\n' +
201
+ `${ I._( baseIndent ) }it( 'should return value of type ${ lowerName }', async function() {` + '\n' +
212
202
  '\n' +
213
203
  `${ result }` +
214
204
  `${ expect }` +
215
205
  '\n' +
216
- `${ I( 1 + 1 + 1 ) }} )` + '\n'
206
+ `${ I._( baseIndent ) }} )` + '\n'
217
207
 
218
208
  } else {
219
209
 
220
- const result = `${ I( 1 + 1 + 1 + 1 ) }const result = ${ nsName }.${ docData.name }()` + '\n'
210
+ const result = `${ I._( baseIndent + 1 ) }const result = ${ nsName }.${ docData.name }()` + '\n'
221
211
 
222
212
  let returnTypesLabel = []
223
- let expects = []
213
+ let oneOf = []
224
214
  for ( let returnType of returns ) {
225
215
 
226
216
  const lowerName = returnType.toLowerCase()
227
217
  returnTypesLabel.push( lowerName )
228
218
 
229
219
  if ( lowerName.startsWith( 'array' ) ) {
230
- expects.push( `expect(result).to.be.a('array')` )
231
220
  //todo array of...
221
+ oneOf.push( 'array' )
232
222
  } else {
233
- expects.push( `expect(result).to.be.a('${ lowerName }')` )
223
+ oneOf.push( `'${ lowerName }'` )
234
224
  }
235
225
 
236
226
  }
237
227
 
238
- let indent = 1 + 1 + 1 + 1
239
- let openTry = ''
240
- let closeTry = ''
241
- for ( let expect of expects ) {
242
- openTry += '' +
243
- `${ I( indent ) }try {` + '\n' +
244
- `${ I( indent + 1 ) }${ expect }` + '\n' +
245
- `${ I( indent ) }} catch(e) {` + '\n'
246
-
247
- closeTry = `${ I( indent ) }}` + '\n' + `${ closeTry }`
248
-
249
- indent++
250
- }
251
- const _expect = '' +
252
- `${ openTry }` +
253
- `${ I( indent ) }expect.fail("expect result to be of type ${ returnTypesLabel.join( ' or ' ) }")` + '\n' +
254
- `${ closeTry }`
228
+ const underlyingType = `${ I._( baseIndent + 1 ) }const resultType = (result === null) ? 'null' : typeof result` + '\n'
229
+ const expect = `${ I._( baseIndent + 1 ) }expect(resultType).to.be.oneOf([${ oneOf.join( ',' ) }])` + '\n'
255
230
 
256
231
  its += '' +
257
- `${ I( 1 + 1 + 1 ) }it( 'return type is ${ returnTypesLabel.join( ' or ' ) }', () => {` + '\n' +
232
+ `${ I._( baseIndent ) }it( 'should return value where type is ${ returnTypesLabel.join( ' or ' ) }', async function() {` + '\n' +
258
233
  '\n' +
259
234
  `${ result }` +
260
- `${ _expect }` +
235
+ `${ underlyingType }` +
236
+ `${ expect }` +
261
237
  '\n' +
262
- `${ I( 1 + 1 + 1 ) }} )` + '\n'
238
+ `${ I._( baseIndent ) }} )` + '\n'
263
239
 
264
240
  }
265
241
 
@@ -269,7 +245,7 @@ function computeUnitTests( done ) {
269
245
 
270
246
  let itDeclaration = []
271
247
  let index = 0
272
- let indent = 1 + 1 + 1 + 1
248
+ let indent = baseIndent + 1
273
249
  let localIndent = indent
274
250
  let dataSets = ''
275
251
  let forLoopOpens = ''
@@ -280,21 +256,22 @@ function computeUnitTests( done ) {
280
256
  const parameterType = parameter.types[ 0 ]
281
257
  itDeclaration.push( `${ parameter.name } is of type ${ parameterType }` )
282
258
 
283
- dataSets += `${ I( indent ) }const dataSet${ index } = this._dataMap[ '${ parameterType }s' ]` + '\n'
259
+ dataSets += `${ I._( indent ) }const dataSet${ index } = _dataMap[ '${ parameterType }s' ]` + '\n'
260
+ // dataSets += `${ I._( indent ) }const dataSet${ index } = this._dataMap[ '${ parameterType }s' ]` + '\n'
284
261
  forLoopOpens += '' + '\n' +
285
- `${ I( localIndent ) }for ( let key${ index } in dataSet${ index } ) {` + '\n' +
286
- `${ I( localIndent + 1 ) }const dataSetValue${ index } = dataSet${ index }[ key${ index } ]` + '\n'
262
+ `${ I._( localIndent ) }for ( let key${ index } in dataSet${ index } ) {` + '\n' +
263
+ `${ I._( localIndent + 1 ) }const dataSetValue${ index } = dataSet${ index }[ key${ index } ]` + '\n'
287
264
 
288
265
  args.push( `dataSetValue${ index }` )
289
266
 
290
- forLoopCloses = `${ I( localIndent ) }}` + '\n' + `${ forLoopCloses }`
267
+ forLoopCloses = `${ I._( localIndent ) }}` + '\n' + `${ forLoopCloses }`
291
268
 
292
269
  index++
293
270
  localIndent++
294
271
  }
295
272
 
296
- const result = `${ I( localIndent ) }const result = ${ nsName }.${ docData.name }( ${ args.join( ', ' ) } )` + '\n'
297
- const expect = `${ I( localIndent ) }expect(result).to.be.a('undefined')` + '\n'
273
+ const result = `${ I._( localIndent ) }const result = ${ nsName }.${ docData.name }( ${ args.join( ', ' ) } )` + '\n'
274
+ const expect = `${ I._( localIndent ) }expect(result).to.be.a('undefined')` + '\n'
298
275
 
299
276
  const param = '' +
300
277
  `${ dataSets }` +
@@ -304,11 +281,11 @@ function computeUnitTests( done ) {
304
281
  `${ forLoopCloses }`
305
282
 
306
283
  its += '' +
307
- `${ I( 1 + 1 + 1 ) }it( 'return type is undefined when ${ itDeclaration.join( ' and ' ) }', () => {` + '\n' +
284
+ `${ I._( baseIndent ) }it( 'should return undefined value when ${ itDeclaration.join( ' and ' ) }', async function() {` + '\n' +
308
285
  '\n' +
309
286
  `${ param }` +
310
287
  '\n' +
311
- `${ I( 1 + 1 + 1 ) }} )` + '\n'
288
+ `${ I._( baseIndent ) }} )` + '\n'
312
289
 
313
290
  } else if ( returns.length === 1 ) {
314
291
 
@@ -317,7 +294,7 @@ function computeUnitTests( done ) {
317
294
 
318
295
  let itDeclaration = []
319
296
  let index = 0
320
- let indent = 1 + 1 + 1 + 1
297
+ let indent = baseIndent + 1
321
298
  let localIndent = indent
322
299
  let dataSets = ''
323
300
  let forLoopOpens = ''
@@ -334,31 +311,33 @@ function computeUnitTests( done ) {
334
311
 
335
312
  if ( isAnyType ) {
336
313
 
337
- dataSets += `${ I( indent ) }const dataMap${ index } = this._dataMap` + '\n' +
338
- `${ I( localIndent ) }for ( let dataSetKey${ index } in dataMap${ index } ) {` + '\n'
314
+ dataSets += `${ I._( indent ) }const dataMap${ index } = _dataMap` + '\n' +
315
+ // dataSets += `${ I._( indent ) }const dataMap${ index } = this._dataMap` + '\n' +
316
+ `${ I._( localIndent ) }for ( let dataSetKey${ index } in dataMap${ index } ) {` + '\n'
339
317
 
340
318
  localIndent++
341
- dataSets += `${ I( indent + 1 ) }const dataSet${ index } = dataMap${ index }[ dataSetKey${ index } ]` + '\n'
319
+ dataSets += `${ I._( indent + 1 ) }const dataSet${ index } = dataMap${ index }[ dataSetKey${ index } ]` + '\n'
342
320
  forLoopOpens += '' + '\n' +
343
- `${ I( localIndent ) }for ( let key${ index } in dataSet${ index } ) {` + '\n' +
344
- `${ I( localIndent + 1 ) }const dataSetValue${ index } = dataSet${ index }[ key${ index } ]` + '\n'
321
+ `${ I._( localIndent ) }for ( let key${ index } in dataSet${ index } ) {` + '\n' +
322
+ `${ I._( localIndent + 1 ) }const dataSetValue${ index } = dataSet${ index }[ key${ index } ]` + '\n'
345
323
 
346
324
  args.push( `dataSetValue${ index }` )
347
325
 
348
- forLoopCloses = `${ I( localIndent ) }}` + '\n' +
349
- `${ I( localIndent - 1 ) }}` + '\n' +
326
+ forLoopCloses = `${ I._( localIndent ) }}` + '\n' +
327
+ `${ I._( localIndent - 1 ) }}` + '\n' +
350
328
  `${ forLoopCloses }`
351
329
 
352
330
  } else {
353
331
 
354
- dataSets += `${ I( indent ) }const dataSet${ index } = this._dataMap[ '${ parameterType }s' ]` + '\n'
332
+ dataSets += `${ I._( indent ) }const dataSet${ index } = _dataMap[ '${ parameterType }s' ]` + '\n'
333
+ // dataSets += `${ I._( indent ) }const dataSet${ index } = this._dataMap[ '${ parameterType }s' ]` + '\n'
355
334
  forLoopOpens += '' + '\n' +
356
- `${ I( localIndent ) }for ( let key${ index } in dataSet${ index } ) {` + '\n' +
357
- `${ I( localIndent + 1 ) }const dataSetValue${ index } = dataSet${ index }[ key${ index } ]` + '\n'
335
+ `${ I._( localIndent ) }for ( let key${ index } in dataSet${ index } ) {` + '\n' +
336
+ `${ I._( localIndent + 1 ) }const dataSetValue${ index } = dataSet${ index }[ key${ index } ]` + '\n'
358
337
 
359
338
  args.push( `dataSetValue${ index }` )
360
339
 
361
- forLoopCloses = `${ I( localIndent ) }}` + '\n' + `${ forLoopCloses }`
340
+ forLoopCloses = `${ I._( localIndent ) }}` + '\n' + `${ forLoopCloses }`
362
341
 
363
342
  }
364
343
 
@@ -367,14 +346,14 @@ function computeUnitTests( done ) {
367
346
  localIndent++
368
347
  }
369
348
 
370
- const result = `${ I( localIndent ) }const result = ${ nsName }.${ docData.name }( ${ args.join( ', ' ) } )` + '\n'
349
+ const result = `${ I._( localIndent ) }const result = ${ nsName }.${ docData.name }( ${ args.join( ', ' ) } )` + '\n'
371
350
 
372
351
  let expect = ''
373
352
  if ( lowerName.startsWith( 'array' ) ) {
374
- expect = `${ I( localIndent ) }expect(result).to.be.a('array')` + '\n'
353
+ expect = `${ I._( localIndent ) }expect(result).to.be.a('array')` + '\n'
375
354
  //todo array of...
376
355
  } else {
377
- expect = `${ I( localIndent ) }expect(result).to.be.a('${ lowerName }')` + '\n'
356
+ expect = `${ I._( localIndent ) }expect(result).to.be.a('${ lowerName }')` + '\n'
378
357
  }
379
358
 
380
359
  const param = '' +
@@ -385,17 +364,17 @@ function computeUnitTests( done ) {
385
364
  `${ forLoopCloses }`
386
365
 
387
366
  its += '' +
388
- `${ I( 1 + 1 + 1 ) }it( 'return type is ${ lowerName } when ${ itDeclaration.join( ' and ' ) }', () => {` + '\n' +
367
+ `${ I._( baseIndent ) }it( 'should return value of type ${ lowerName } when ${ itDeclaration.join( ' and ' ) }', async function() {` + '\n' +
389
368
  '\n' +
390
369
  `${ param }` +
391
370
  '\n' +
392
- `${ I( 1 + 1 + 1 ) }} )` + '\n'
371
+ `${ I._( baseIndent ) }} )` + '\n'
393
372
 
394
373
  } else {
395
374
 
396
375
  let itDeclaration = []
397
376
  let index = 0
398
- let indent = 1 + 1 + 1 + 1
377
+ let indent = baseIndent + 1
399
378
  let localIndent = indent
400
379
  let dataSets = ''
401
380
  let forLoopOpens = ''
@@ -406,83 +385,72 @@ function computeUnitTests( done ) {
406
385
  const parameterType = parameter.types[ 0 ]
407
386
  itDeclaration.push( `${ parameter.name } is of type ${ parameterType }` )
408
387
 
409
- dataSets += `${ I( indent ) }const dataSet${ index } = this._dataMap[ '${ parameterType }s' ]` + '\n'
388
+ dataSets += `${ I._( localIndent ) }const dataSet${ index } = _dataMap[ '${ parameterType }s' ]` + '\n'
389
+ // dataSets += `${ I._( indent ) }const dataSet${ index } = this._dataMap[ '${ parameterType }s' ]` + '\n'
410
390
  forLoopOpens += '' + '\n' +
411
- `${ I( localIndent ) }for ( let key${ index } in dataSet${ index } ) {` + '\n' +
412
- `${ I( localIndent + 1 ) }const dataSetValue${ index } = dataSet${ index }[ key${ index } ]` + '\n'
391
+ `${ I._( localIndent ) }for ( let key${ index } in dataSet${ index } ) {` + '\n' +
392
+ `${ I._( localIndent + 1 ) }const dataSetValue${ index } = dataSet${ index }[ key${ index } ]` + '\n'
413
393
 
414
394
  args.push( `dataSetValue${ index }` )
415
395
 
416
- forLoopCloses = `${ I( localIndent ) }}` + '\n' + `${ forLoopCloses }`
396
+ forLoopCloses = `${ I._( localIndent ) }}` + '\n' + `${ forLoopCloses }`
417
397
 
418
398
  index++
419
399
  localIndent++
420
400
  }
421
401
 
422
- const result = `${ I( localIndent ) }const result = ${ nsName }.${ docData.name }( ${ args.join( ', ' ) } )` + '\n'
402
+ const result = `${ I._( localIndent + 1 ) }const result = ${ nsName }.${ docData.name }( ${ args.join( ', ' ) } )` + '\n'
423
403
 
424
404
  let returnTypesLabel = []
425
- let expects = []
405
+ let oneOf = []
426
406
  for ( let returnType of returns ) {
427
407
 
428
408
  const lowerName = returnType.toLowerCase()
429
409
  returnTypesLabel.push( lowerName )
430
410
 
431
411
  if ( lowerName.startsWith( 'array' ) ) {
432
- expects.push( `expect(result).to.be.a('array')` )
433
412
  //todo array of...
413
+ oneOf.push( 'array' )
434
414
  } else {
435
- expects.push( `expect(result).to.be.a('${ lowerName }')` )
415
+ oneOf.push( `'${ lowerName }'` )
436
416
  }
437
417
 
438
418
  }
439
- let openTry = ''
440
- let closeTry = ''
441
- for ( let expect of expects ) {
442
- openTry += '' +
443
- `${ I( localIndent ) }try {` + '\n' +
444
- `${ I( localIndent + 1 ) }${ expect }` + '\n' +
445
- `${ I( localIndent ) }} catch(e) {` + '\n'
446
-
447
- closeTry = `${ I( localIndent ) }}` + '\n' + `${ closeTry }`
448
419
 
449
- localIndent++
450
- }
451
- const _expect = '' +
452
- `${ openTry }` +
453
- `${ I( localIndent ) }expect.fail("expect result to be of type ${ returnTypesLabel.join( ' or ' ) }")` + '\n' +
454
- `${ closeTry }`
420
+ const underlyingType = `${ I._( localIndent + 1 ) }const resultType = (result === null) ? 'null' : typeof result` + '\n'
421
+ const expect = `${ I._( localIndent + 1 ) }expect(resultType).to.be.oneOf([${ oneOf.join( ',' ) }])` + '\n'
455
422
 
456
423
  const param = '' +
457
424
  `${ dataSets }` +
458
425
  `${ forLoopOpens }` +
459
426
  `${ result }` +
460
- `${ _expect }` +
427
+ `${ underlyingType }` +
428
+ `${ expect }` +
461
429
  `${ forLoopCloses }`
462
430
 
463
431
  its += '' +
464
- `${ I( 1 + 1 + 1 ) }it( 'return type is ${ returnTypesLabel.join( ' or ' ) } when ${ itDeclaration.join( ' and ' ) }', () => {` + '\n' +
432
+ `${ I._( baseIndent ) }it( 'should return value of type ${ returnTypesLabel.join( ' or ' ) } when ${ itDeclaration.join( ' and ' ) }', async function() {` + '\n' +
465
433
  '\n' +
466
434
  `${ param }` +
467
435
  '\n' +
468
- `${ I( 1 + 1 + 1 ) }} )` + '\n'
436
+ `${ I._( baseIndent ) }} )` + '\n'
469
437
 
470
438
  }
471
439
 
472
440
  }
473
441
 
474
442
  describes += '' +
475
- `${ I.__ }describe( '${ docData.name }()', () => {` + '\n' +
443
+ `${ I_ }describe( '${ docData.name }()', function () {` + '\n' +
476
444
  '\n' +
477
- `${ I.___ }it( 'is bundlable', () => {` + '\n' +
445
+ `${ I__ }it( 'should be bundlable', async function () {` + '\n' +
478
446
  '\n' +
479
- `${ I.____ }expect(${ nsName }.${ docData.name }).to.exist` + '\n' +
447
+ `${ I___ }expect(${ nsName }.${ docData.name }).to.exist` + '\n' +
480
448
  '\n' +
481
- `${ I.___ }} )` + '\n' +
449
+ `${ I__ }} )` + '\n' +
482
450
  '\n' +
483
451
  `${ its }` +
484
452
  '\n' +
485
- `${ I.__ }} )` + '\n' +
453
+ `${ I_ }} )` + '\n' +
486
454
  '\n'
487
455
 
488
456
  } catch ( error ) {
@@ -495,34 +463,19 @@ function computeUnitTests( done ) {
495
463
 
496
464
  const template = '' +
497
465
  `import { expect } from 'chai'` + '\n' +
498
- `import { beforeEach, afterEach, describe, it } from 'mocha'` + '\n' +
499
- `import { Testing } from 'itee-utils'` + '\n' +
466
+ `import { Testing } from 'itee-utils/sources/testings/benchmarks.js'` + '\n' +
500
467
  `import * as ${ nsName } from '${ importFilePath }'` + '\n' +
501
468
  '\n' +
502
- `function ${ unitName } () {` + '\n' +
503
- '\n' +
504
- `${ I( 1 ) }beforeEach( () => {` + '\n' +
469
+ `describe( '${ unitName }', function () {` + '\n' +
505
470
  '\n' +
506
- `${ I( 1 + 1 ) }this._dataMap = Testing.createDataMap()` + '\n' +
507
- '\n' +
508
- `${ I( 1 ) }} )` + '\n' +
509
- '\n' +
510
- `${ I( 1 ) }afterEach( () => {` + '\n' +
511
- '\n' +
512
- `${ I( 1 + 1 ) }delete this._dataMap` + '\n' +
513
- '\n' +
514
- `${ I( 1 ) }} )` + '\n' +
515
- '\n' +
516
- `${ I( 1 ) }describe( '${ unitName }', () => {` + '\n' +
471
+ `${ I_ }let _dataMap` + '\n' +
472
+ `${ I_ }before( function() {` + '\n' +
473
+ `${ I__ }_dataMap = Testing.createDataMap()` + '\n' +
474
+ `${ I_ }} )` + '\n' +
517
475
  '\n' +
518
476
  `${ describes }` +
519
477
  '' +
520
- `${ I( 1 ) }} )` + '\n' +
521
- '\n' +
522
- '}' + '\n' +
523
- '\n' +
524
- `export { ${ unitName } }` + '\n' +
525
- '\n'
478
+ `} )` + '\n'
526
479
 
527
480
  const importUnitFilePath = relative( unitsDir, unitFilePath )
528
481
  unitsImportMap.push( {
@@ -530,9 +483,13 @@ function computeUnitTests( done ) {
530
483
  path: importUnitFilePath.replace( /\\/g, '/' )
531
484
  } )
532
485
 
533
- log( green( `Create ${ unitFilePath }` ) )
534
- fs.mkdirSync( unitDirPath, { recursive: true } )
535
- fs.writeFileSync( unitFilePath, template )
486
+ if ( !existsSync( unitDirPath ) ) {
487
+ log( 'Creating', green( unitDirPath ) )
488
+ mkdirSync( unitDirPath, { recursive: true } )
489
+ }
490
+
491
+ log( 'Creating', green( unitFilePath ) )
492
+ writeFileSync( unitFilePath, template )
536
493
 
537
494
  } catch ( error ) {
538
495
 
@@ -542,37 +499,39 @@ function computeUnitTests( done ) {
542
499
 
543
500
  }
544
501
 
545
- // Global units file
546
- let computedImports = ''
547
- let computedUnitCalls = ''
548
- for ( let entry of unitsImportMap ) {
549
- computedImports += `import { ${ entry.exportName } } from './${ entry.path }'` + '\n'
550
- computedUnitCalls += ` ${ entry.exportName }.call( root )` + '\n'
502
+ // If some tests to import generate global units file
503
+ let unitsTemplate
504
+ if ( isNotEmptyArray( unitsImportMap ) ) {
505
+
506
+ let computedImports = []
507
+ for ( let entry of unitsImportMap ) {
508
+ // computedImports.push(`import { ${ entry.exportName } } from './${ entry.path }'`)
509
+ computedImports.push( `export * from './${ entry.path }'` )
510
+ }
511
+
512
+ unitsTemplate = computedImports.join( '\n' )
513
+
514
+ } else {
515
+
516
+ log( yellow( 'No tests were generated. Create fallback global root import file.' ) )
517
+
518
+ unitsTemplate = '' +
519
+ 'import { describe } from \'mocha\'' + '\n' +
520
+ '\n' +
521
+ 'describe( \'Itee#Validators\', () => {} )' + '\n'
522
+
551
523
  }
552
524
 
553
- const unitsTemplate = '' +
554
- 'import { describe } from \'mocha\'' + '\n' +
555
- `${ computedImports }` +
556
- '\n' +
557
- 'const root = typeof window === \'undefined\'' + '\n' +
558
- ' ? typeof global === \'undefined\'' + '\n' +
559
- ' ? Function( \'return this\' )() ' + '\n' +
560
- ' : global ' + '\n' +
561
- ' : window' + '\n' +
562
- '\n' +
563
- 'describe( \'Itee#Validators\', () => {' + '\n' +
564
- '\n' +
565
- `${ computedUnitCalls }` +
566
- '\n' +
567
- '} )' + '\n'
568
-
569
- const unitsFilePath = join( unitsDir, `${ packageInfos.name }.units.js` )
570
-
571
- log( green( `Create ${ unitsFilePath }` ) )
572
- fs.writeFileSync( unitsFilePath, unitsTemplate )
525
+ const unitsFilePath = join( unitsDir, `${ packageName }.units.mjs` )
526
+
527
+ log( 'Creating', green( unitsFilePath ) )
528
+ writeFileSync( unitsFilePath, unitsTemplate )
573
529
 
574
530
  done()
575
531
 
576
532
  }
533
+ computeUnitTestsTask.displayName = 'compute-unit-tests'
534
+ computeUnitTestsTask.description = 'Will generate unit test files from source code using type inference from comments'
535
+ computeUnitTestsTask.flags = null
577
536
 
578
- export { computeUnitTests }
537
+ export { computeUnitTestsTask }