datagrok-tools 4.14.36 → 4.14.38

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.
@@ -36,8 +36,8 @@ async function test(args) {
36
36
  if (!args.package) packageJsonData = JSON.parse(_fs.default.readFileSync(_path.default.join(curDir, 'package.json'), {
37
37
  encoding: 'utf-8'
38
38
  }));
39
- let packageName = args.package ? utils.kebabToCamelCase(args.package) : utils.kebabToCamelCase(utils.removeScope(packageJsonData.name));
40
- let packagesDir = _path.default.basename(curDir) === "packages" ? curDir : _path.default.dirname(curDir);
39
+ const packageName = args.package ? utils.kebabToCamelCase(args.package) : utils.kebabToCamelCase(utils.removeScope(packageJsonData.name));
40
+ const packagesDir = _path.default.basename(curDir) === 'packages' ? curDir : _path.default.dirname(curDir);
41
41
  console.log('Environment variable `TARGET_PACKAGE` is set to', packageName);
42
42
  if (args.platform && packageName !== 'ApiTests') color.warn('--platform flag can only be used in the ApiTests package');
43
43
  // if (args.core && packageName !== 'DevTools')
@@ -47,7 +47,7 @@ async function test(args) {
47
47
  await testUtils.loadPackages(packagesDir, packageName, args.host, args['skip-publish'], args['skip-build'], args.link);
48
48
  }
49
49
  process.env.TARGET_PACKAGE = packageName;
50
- let res = await runTesting(args);
50
+ const res = await runTesting(args);
51
51
  if (args.csv) (0, _testUtils.saveCsvResults)([res.csv], csvReportDir);
52
52
  (0, _testUtils.printBrowsersResult)(res, args.verbose);
53
53
  if (res.failed) {
@@ -66,23 +66,25 @@ async function runTesting(args) {
66
66
  const loadedTests = await (0, _testUtils.loadTestsList)([process.env.TARGET_PACKAGE ?? ''], args.core);
67
67
  let testsObj = [];
68
68
  if (args['stress-test'] || args.benchmark) {
69
- for (let element of loadedTests) {
69
+ for (const element of loadedTests) {
70
70
  if (args.benchmark && !element.options.benchmark || args['stress-test'] && !element.options.stressTest) continue;
71
71
  testsObj.push(element);
72
72
  }
73
73
  } else testsObj = loadedTests;
74
74
  const parsed = (0, _orderFunctions.setAlphabeticalOrder)(testsObj, 1, 1);
75
- if (parsed.length == 0) return {
76
- failed: true,
77
- error: '',
78
- verbosePassed: 'Package not found',
79
- verboseSkipped: 'Package not found',
80
- verboseFailed: 'Package not found',
81
- passedAmount: 0,
82
- skippedAmount: 0,
83
- failedAmount: 0,
84
- csv: ''
85
- };
75
+ if (parsed.length == 0) {
76
+ return {
77
+ failed: true,
78
+ error: '',
79
+ verbosePassed: 'Package not found',
80
+ verboseSkipped: 'Package not found',
81
+ verboseFailed: 'Package not found',
82
+ passedAmount: 0,
83
+ skippedAmount: 0,
84
+ failedAmount: 0,
85
+ csv: ''
86
+ };
87
+ }
86
88
  let organized = parsed[0].map(testObj => ({
87
89
  package: testObj.packageName,
88
90
  params: {
@@ -94,10 +96,10 @@ async function runTesting(args) {
94
96
  }
95
97
  }
96
98
  }));
97
- let filtered = [];
98
- let categoryRegex = new RegExp(`${args.category?.replaceAll(' ', '')}.*`);
99
+ const filtered = [];
100
+ const categoryRegex = new RegExp(`${args.category?.replaceAll(' ', '')}.*`);
99
101
  if (args.category) {
100
- for (let element of organized) {
102
+ for (const element of organized) {
101
103
  if (categoryRegex.test(element.params.category.replaceAll(' ', ''))) {
102
104
  if (element.params.test === args.test || !args.test) filtered.push(element);
103
105
  }
@@ -109,7 +111,7 @@ async function runTesting(args) {
109
111
  console.log(`Tests total: ${organized.length}`);
110
112
  }
111
113
  color.info('Starting tests...');
112
- let testsResults = [];
114
+ const testsResults = [];
113
115
  let r;
114
116
  let browserId = 1;
115
117
  await (0, _testUtils.timeout)(async () => {
@@ -126,23 +128,21 @@ async function runTesting(args) {
126
128
  stopOnTimeout: true,
127
129
  debug: args['debug'] ?? false
128
130
  }, browserId, testInvocationTimeout);
129
- let testsLeft = [];
130
- let testsToReproduce = [];
131
- for (let testData of organized) {
131
+ const testsLeft = [];
132
+ const testsToReproduce = [];
133
+ for (const testData of organized) {
132
134
  if (!r.verbosePassed.includes(`${testData.params.category}: ${testData.params.test}`) && !r.verboseSkipped.includes(`${testData.params.category}: ${testData.params.test}`) && !r.verboseFailed.includes(`${testData.params.category}: ${testData.params.test}`) && !new RegExp(`${testUtils.escapeRegex(testData.params.category.trim())}[^\n]*: *?(before|after)(\\(\\))?`).test(r.verboseFailed)) testsLeft.push(testData);
133
- if (r.verboseFailed.includes(`${testData.params.category}: ${testData.params.test} : Error:`)) {
134
- testsToReproduce.push(testData);
135
- }
135
+ if (r.verboseFailed.includes(`${testData.params.category}: ${testData.params.test} : Error:`)) testsToReproduce.push(testData);
136
136
  }
137
137
  if (testsToReproduce.length > 0) {
138
- let reproduced = await reproducedTest(args, testsToReproduce);
139
- for (let test of testsToReproduce) {
140
- let reproducedTest = reproduced.get(test);
138
+ const reproduced = await reproducedTest(args, testsToReproduce);
139
+ for (const test of testsToReproduce) {
140
+ const reproducedTest = reproduced.get(test);
141
141
  if (reproducedTest && !reproducedTest.failed) r = await updateResultsByReproduced(r, reproducedTest, test);
142
142
  }
143
143
  }
144
- r.csv = await (0, _testUtils.addColumnToCsv)(r.csv, "stress_test", args['stress-test'] ?? false);
145
- r.csv = await (0, _testUtils.addColumnToCsv)(r.csv, "benchmark", args.benchmark ?? false);
144
+ r.csv = await (0, _testUtils.addColumnToCsv)(r.csv, 'stress_test', args['stress-test'] ?? false);
145
+ r.csv = await (0, _testUtils.addColumnToCsv)(r.csv, 'benchmark', args.benchmark ?? false);
146
146
  testsResults.push(r);
147
147
  organized = testsLeft;
148
148
  browserId++;
@@ -157,8 +157,8 @@ async function runTesting(args) {
157
157
  }
158
158
  async function reproducedTest(args, testsToReproduce) {
159
159
  const res = new Map();
160
- for (let test of testsToReproduce) {
161
- let r = await (0, _testUtils.runBrowser)([test], {
160
+ for (const test of testsToReproduce) {
161
+ const r = await (0, _testUtils.runBrowser)([test], {
162
162
  benchmark: args.benchmark ?? false,
163
163
  catchUnhandled: false,
164
164
  gui: false,
@@ -175,8 +175,8 @@ async function reproducedTest(args, testsToReproduce) {
175
175
  }
176
176
  async function updateResultsByReproduced(curentResult, reproducedResult, testsParams) {
177
177
  const table2Dict = {};
178
- let table1 = readCSVResultData(curentResult.csv);
179
- let table2 = readCSVResultData(reproducedResult.csv);
178
+ const table1 = readCSVResultData(curentResult.csv);
179
+ const table2 = readCSVResultData(reproducedResult.csv);
180
180
  const flakingMap = {};
181
181
  table2.rows.forEach(row => {
182
182
  const key = `${row['category']},${row['name']}`;
@@ -184,9 +184,7 @@ async function updateResultsByReproduced(curentResult, reproducedResult, testsPa
184
184
  });
185
185
  table1.rows.forEach(row => {
186
186
  const key = `${row['category']},${row['name']}`;
187
- if (key in flakingMap) {
188
- row['flaking'] = flakingMap[key];
189
- }
187
+ if (key in flakingMap) row['flaking'] = flakingMap[key];
190
188
  });
191
189
  curentResult.csv = Papa.unparse(table1.rows, {
192
190
  columns: table1.headers
@@ -200,9 +198,7 @@ function readCSVResultData(data) {
200
198
  header: true,
201
199
  skipEmptyLines: true
202
200
  });
203
- if (parsed.errors.length > 0) {
204
- throw new Error(`Error parsing CSV file: ${parsed.errors[0].message}`);
205
- }
201
+ if (parsed.errors.length > 0) throw new Error(`Error parsing CSV file: ${parsed.errors[0].message}`);
206
202
  return {
207
203
  headers: parsed.meta.fields || [],
208
204
  rows: parsed.data
@@ -20,7 +20,7 @@ let pseudoParams = exports.pseudoParams = /*#__PURE__*/function (pseudoParams) {
20
20
  pseudoParams["INPUT_TYPE"] = "inputType";
21
21
  return pseudoParams;
22
22
  }({});
23
- const nonMetaData = ['sidebar', 'editor', 'friendlyName', 'helpUrl', 'condition', 'top-menu', 'cache', 'cache.invalidateOn'];
23
+ const nonMetaData = ['sidebar', 'editor', 'friendlyName', 'helpUrl', 'help-url', 'condition', 'top-menu', 'cache', 'cache.invalidateOn', 'test'];
24
24
  const decoratorOptionToAnnotation = new Map([['initialValue', 'default']]);
25
25
  const dgAnnotationTypes = exports.dgAnnotationTypes = {
26
26
  INT: 'int',
@@ -126,7 +126,7 @@ function getFuncAnnotation(data, comment = '//', sep = '\n') {
126
126
  const isFileViewer = data.tags?.includes(FUNC_TYPES.FILE_VIEWER) ?? false;
127
127
  const isFileImporter = data.tags?.includes(FUNC_TYPES.FILE_HANDLER) ?? false;
128
128
  let s = '';
129
- if (data.name) s += `${comment}name: ${data.name}${sep}`;
129
+ if (data.name && (!data.tags?.includes('init') || data.name !== 'init' && data.name !== '_init')) s += `${comment}name: ${data.name}${sep}`;
130
130
  if (pseudoParams.EXTENSION in data && data.tags != null && data.tags.includes(FUNC_TYPES.FILE_EXPORTER)) s += `${comment}description: Save as ${data[pseudoParams.EXTENSION]}${sep}`;else if (data.description) s += `${comment}description: ${data.description}${sep}`;
131
131
  if (data.tags && data.tags?.length > 0) {
132
132
  s += `${comment}tags: ${isFileViewer && data[pseudoParams.EXTENSIONS] ? data.tags.concat(data[pseudoParams.EXTENSIONS].map(ext => 'fileViewer-' + ext)).join(', ') : data.tags.join(', ')}${sep}`;
@@ -170,11 +170,13 @@ function getFuncAnnotation(data, comment = '//', sep = '\n') {
170
170
  }
171
171
  }
172
172
  if (data.test) {
173
- for (const entry of Object.entries(data.test)) {
174
- if (entry[0] === 'test' || entry[0] === 'wait') s += `${comment}`;else s += `, `;
175
- s += `${entry[0]}: ${entry[1]} `;
173
+ if (typeof data.test === 'string') s += `${comment}test: ${data.test}${sep}`;else {
174
+ for (const entry of Object.entries(data.test)) {
175
+ if (entry[0] === 'test' || entry[0] === 'wait') s += `${comment}`;else s += `, `;
176
+ s += `${entry[0]}: ${entry[1]} `;
177
+ }
178
+ s += `${sep}`;
176
179
  }
177
- s += `${sep}`;
178
180
  }
179
181
  return s;
180
182
  }
@@ -438,7 +440,7 @@ const primitives = new Set(['string', 'string[]', 'number', 'number[]', 'boolean
438
440
  /** Generates a DG function. */
439
441
  function generateFunc(annotation, funcName, sep = '\n', className = '', inputs = [], isAsync = false) {
440
442
  // eslint-disable-next-line max-len
441
- const funcSigNature = inputs.map(e => `${e.name}: ${primitives.has(e.type ?? '') && !typesToAny.includes(e.type ?? '') ? e.type : typesToAnnotation[e.type?.replace('[]', '') ?? ''] && !typesToAny.includes(e.type ?? '') ? e.type : 'any'}`).join(', ');
443
+ const funcSigNature = inputs.map(e => `${e.name}${e.optional ? '?' : ''}: ${primitives.has(e.type ?? '') && !typesToAny.includes(e.type ?? '') ? e.type : typesToAnnotation[e.type?.replace('[]', '') ?? ''] && !typesToAny.includes(e.type ?? '') ? e.type : 'any'}`).join(', ');
442
444
  const funcArguments = inputs.map(e => e.name).join(', ');
443
445
 
444
446
  // eslint-disable-next-line max-len
@@ -329,16 +329,28 @@ async function runTests(testsParams, stopOnFail) {
329
329
  let resultDF = undefined;
330
330
  let lastTest = null;
331
331
  let res = '';
332
+
333
+ // function addColumn(columnName: string, column: any, df : any) {
334
+ // if (!df.getCol(columnName))
335
+ // df.columns.add(column);
336
+ // }
337
+
332
338
  try {
333
339
  for (const testParam of testsParams) {
334
340
  lastTest = testParam;
335
341
  const df = await window.grok.functions.call(testParam.package + ':test', testParam.params);
336
- const flakingCol = window.DG.Column.fromType(window.DG.COLUMN_TYPE.BOOL, 'flaking', df.rowCount);
337
- df.columns.add(flakingCol);
338
- if (!df.getCol('package')) {
339
- const packageNameCol = window.DG.Column.fromList(window.DG.COLUMN_TYPE.STRING, 'package', Array(df.rowCount).fill(testParam.package));
340
- df.columns.add(packageNameCol);
341
- }
342
+ df.columns.setOrder(['date', 'category', 'name', 'success', 'result', 'ms', 'skipped', 'logs', 'owner', 'package', 'widgetsDifference', 'flaking']);
343
+ // addColumn('flaking', (<any>window).DG.Column.fromType((<any>window).DG.COLUMN_TYPE.BOOL, 'flaking', df.rowCount), df);
344
+ // addColumn('package', (<any>window).DG.Column.fromType((<any>window).DG.COLUMN_TYPE.BOOL, 'flaking', df.rowCount), df);
345
+ // if (!df.getCol('flaking')) {
346
+ // const flakingCol = (<any>window).DG.Column.fromType((<any>window).DG.COLUMN_TYPE.BOOL, 'flaking', df.rowCount);
347
+ // df.columns.add(flakingCol);
348
+ // }
349
+ // if (!df.getCol('package')) {
350
+ // const packageNameCol =
351
+ // (<any>window).DG.Column.fromList((<any>window).DG.COLUMN_TYPE.STRING, 'package', Array(df.rowCount).fill(testParam.package));
352
+ // df.columns.add(packageNameCol);
353
+ // }
342
354
  if (df.rowCount === 0) {
343
355
  verboseFailed += `Test result : Invocation Fail : ${testParam.params.category}: ${testParam.params.test}\n`;
344
356
  countFailed += 1;
@@ -10,7 +10,7 @@
10
10
  "@datagrok-libraries/utils": "^4.6.0"
11
11
  },
12
12
  "devDependencies": {
13
- "datagrok-tools": "^4.14.34",
13
+ "datagrok-tools": "^4.14.38",
14
14
  "webpack": "^5.95.0",
15
15
  "webpack-cli": "^5.1.4"
16
16
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datagrok-tools",
3
- "version": "4.14.36",
3
+ "version": "4.14.38",
4
4
  "description": "Utility to upload and publish packages to Datagrok",
5
5
  "homepage": "https://github.com/datagrok-ai/public/tree/master/tools#readme",
6
6
  "dependencies": {
@@ -237,6 +237,7 @@ class FuncGeneratorPlugin {
237
237
  // defaultValue = baseParam?.right?.raw;
238
238
  baseParam = baseParam?.left;
239
239
  }
240
+ const optional = param.optional;
240
241
 
241
242
  if (baseParam.type === 'RestElement' || baseParam.type === 'Identifier') {
242
243
  let name =
@@ -258,8 +259,7 @@ class FuncGeneratorPlugin {
258
259
  baseParam.typeAnnotation.typeAnnotation.typeArguments?.params;
259
260
  if (type !== 'any' && params && params.length > 0)
260
261
  type += `<${params.map((e) => e.typeName?.name ?? 'any').join(',')}>`;
261
-
262
- return {name: name, type: type, options: options};
262
+ return {name: name, type: type, options: options, optional: optional};
263
263
  }
264
264
  // Commented code belove sets more strong types for ObjectPatterns and ArrayPatterns
265
265
  // else if (baseParam.type === 'ObjectPattern' || baseParam.type === 'ArrayPattern') {
@@ -294,7 +294,7 @@ class FuncGeneratorPlugin {
294
294
 
295
295
  // return { name: name, type: type, options: options };
296
296
  // }
297
- return {name: 'value', type: 'any', options: undefined};
297
+ return {name: 'value', type: 'any', options: undefined, optional: optional};
298
298
  });
299
299
  return params;
300
300
  }
@@ -346,13 +346,13 @@ class FuncGeneratorPlugin {
346
346
  }
347
347
 
348
348
  _readReturnType(annotation) {
349
- let resultType = 'dynamic';
349
+ let resultType = 'void';
350
350
  let nodeAnnotation = annotation;
351
351
  let isArray = false;
352
352
  if (nodeAnnotation?.type === 'TSUnionType' &&
353
353
  nodeAnnotation?.types?.length === 2 &&
354
- nodeAnnotation?.types?.some((e)=> e?.type === 'TSNullKeyword'))
355
- nodeAnnotation = nodeAnnotation.types.filter((e)=> e.type !== 'TSNullKeyword')[0];
354
+ nodeAnnotation?.types?.some((e)=> e?.type === 'TSNullKeyword' || e?.type === 'TSVoidKeyword'))
355
+ nodeAnnotation = nodeAnnotation.types.filter((e)=> e.type !== 'TSNullKeyword' || e?.type === 'TSVoidKeyword')[0];
356
356
 
357
357
 
358
358
  if (
@@ -398,9 +398,8 @@ class FuncGeneratorPlugin {
398
398
  results = this._readOutputsFromReturnTypeObject(annotation);
399
399
  else {
400
400
  const resultType = this._readReturnType(annotation);
401
- results.push({name: 'result', type: resultType});
402
- if (resultType === 'void')
403
- results = [];
401
+ if (resultType !== 'void')
402
+ results.push({name: 'result', type: resultType});
404
403
  }
405
404
  return results;
406
405
  }