eyeling 1.28.5 → 1.28.7

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.
@@ -6,20 +6,7 @@ const os = require('node:os');
6
6
  const path = require('node:path');
7
7
  const cp = require('node:child_process');
8
8
 
9
- const TTY = process.stdout.isTTY;
10
- const C = TTY
11
- ? { g: '\x1b[32m', r: '\x1b[31m', y: '\x1b[33m', dim: '\x1b[2m', n: '\x1b[0m' }
12
- : { g: '', r: '', y: '', dim: '', n: '' };
13
-
14
- function info(msg) {
15
- console.log(`${C.y}==${C.n} ${msg}`);
16
- }
17
- function ok(msg) {
18
- console.log(`${C.g}OK${C.n} ${msg}`);
19
- }
20
- function fail(msg) {
21
- console.error(`${C.r}FAIL${C.n} ${msg}`);
22
- }
9
+ const { C, detail, failResult, info, pass } = require('./report');
23
10
 
24
11
  function isWin() {
25
12
  return process.platform === 'win32';
@@ -158,6 +145,7 @@ function packTarball(root) {
158
145
 
159
146
  function main() {
160
147
  const suiteStart = Date.now();
148
+ let sequence = 0;
161
149
  const root = path.resolve(__dirname, '..');
162
150
 
163
151
  const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'eyeling-smoke-'));
@@ -167,15 +155,19 @@ function main() {
167
155
 
168
156
  try {
169
157
  info('Building tarball (npm pack)');
158
+ let stepStart = Date.now();
170
159
  tgzInRoot = packTarball(root);
171
160
  const srcTgz = path.join(root, tgzInRoot);
172
161
  const dstTgz = path.join(tmp, tgzInRoot);
173
162
 
174
163
  fs.renameSync(srcTgz, dstTgz);
164
+ pass(++sequence, `packed ${tgzInRoot}`, Date.now() - stepStart);
175
165
 
176
166
  info('Creating temp project + installing tarball');
167
+ stepStart = Date.now();
177
168
  runChecked(npmCmd(), ['init', '-y'], { cwd: tmp, stdio: 'ignore' });
178
169
  runChecked(npmCmd(), ['install', `./${tgzInRoot}`, '--no-audit', '--no-fund'], { cwd: tmp, stdio: 'inherit' });
170
+ pass(++sequence, 'created temp project and installed tarball', Date.now() - stepStart);
179
171
 
180
172
  info('API smoke test');
181
173
  // Run a tiny API check via node -e
@@ -193,17 +185,18 @@ function main() {
193
185
  console.error('Unexpected output:\\n' + out);
194
186
  process.exit(1);
195
187
  }
196
- console.log('OK: API works');
197
188
  `;
189
+ stepStart = Date.now();
198
190
  runChecked(process.execPath, ['-e', apiCode], { cwd: tmp, stdio: 'inherit' });
199
- ok('API works');
191
+ pass(++sequence, 'API works', Date.now() - stepStart);
200
192
 
201
193
  info('CLI smoke test');
202
194
  const bin = isWin()
203
195
  ? path.join(tmp, 'node_modules', '.bin', 'eyeling.cmd')
204
196
  : path.join(tmp, 'node_modules', '.bin', 'eyeling');
197
+ stepStart = Date.now();
205
198
  runChecked(bin, ['-v'], { cwd: tmp, stdio: 'inherit' });
206
- ok('CLI works');
199
+ pass(++sequence, 'CLI works', Date.now() - stepStart);
207
200
 
208
201
  info('Examples smoke test (installed package)');
209
202
  const pkgRoot = path.join(tmp, 'node_modules', 'eyeling');
@@ -220,11 +213,10 @@ function main() {
220
213
  const SMOKE_EXAMPLES = ['age.n3', 'basic-monadic.n3', 'family-cousins.n3', 'backward.n3', 'context-association.n3'];
221
214
 
222
215
  const tmpExamplesOut = fs.mkdtempSync(path.join(os.tmpdir(), 'eyeling-pkg-examples-'));
223
- let smokeIdx = 1;
224
- const smokePad2 = (n) => String(n).padStart(2, '0');
225
- const smokeOk = (n, msg) => console.log(`${C.g}OK${C.n} ${smokePad2(n)} ${msg}`);
216
+ stepStart = Date.now();
226
217
  try {
227
218
  for (const file of SMOKE_EXAMPLES) {
219
+ const smokeStart = Date.now();
228
220
  const inputPath = path.join(examplesDir, file);
229
221
  const expectedPath = resolveExpectedPath(outputDir, file);
230
222
 
@@ -275,20 +267,21 @@ Output differs for ${file}:`);
275
267
  throw new Error(`Example ${file}: output differs from golden`);
276
268
  }
277
269
 
278
- smokeOk(smokeIdx++, `Example smoke: ${file}`);
270
+ pass(++sequence, `Example smoke: ${file}`, Date.now() - smokeStart);
279
271
  }
280
272
  } finally {
281
273
  rmrf(tmpExamplesOut);
282
274
  }
283
- smokeOk(smokeIdx++, 'Installed examples smoke test passed');
275
+ pass(++sequence, 'Installed examples smoke test passed', Date.now() - stepStart);
284
276
 
285
277
  const suiteMs = Date.now() - suiteStart;
286
278
  console.log('');
287
- ok(`Packaged install smoke test passed ${C.dim}(${suiteMs} ms, ${(suiteMs / 1000).toFixed(2)} s)${C.n}`);
279
+ info(`Packaged install smoke test passed (${suiteMs} ms, ${(suiteMs / 1000).toFixed(2)} s)`);
288
280
  process.exit(0);
289
281
  } catch (e) {
290
282
  console.log('');
291
- fail(e && e.stack ? e.stack : String(e));
283
+ failResult(++sequence, 'packaged install smoke test failed', Date.now() - suiteStart);
284
+ detail(e && e.stack ? e.stack : String(e));
292
285
  process.exit(1);
293
286
  } finally {
294
287
  // If rename failed and the tarball still exists in root, try to delete it
@@ -4,19 +4,9 @@ const assert = require('node:assert/strict');
4
4
  const cp = require('node:child_process');
5
5
  const fs = require('node:fs');
6
6
 
7
- const TTY = process.stdout.isTTY;
8
- const C = TTY ? { g: '\x1b[32m', r: '\x1b[31m', y: '\x1b[33m', n: '\x1b[0m' } : { g: '', r: '', y: '', n: '' };
9
-
10
- function ok(msg) {
11
- console.log(`${C.g}OK ${C.n} ${msg}`);
12
- }
13
- function info(msg) {
14
- console.log(`${C.y}${msg}${C.n}`);
15
- }
16
- function fail(msg) {
17
- console.error(`${C.r}FAIL${C.n} ${msg}`);
18
- }
7
+ const { detail, failResult, info, pass } = require('./report');
19
8
 
9
+ const start = Date.now();
20
10
  try {
21
11
  info('Checking packlist + metadata…');
22
12
 
@@ -65,8 +55,9 @@ try {
65
55
  'missing from npm pack: examples/output/*',
66
56
  );
67
57
 
68
- ok('packlist + metadata sanity checks passed');
58
+ pass(1, 'packlist + metadata sanity checks passed', Date.now() - start);
69
59
  } catch (e) {
70
- fail(e && e.stack ? e.stack : String(e));
60
+ failResult(1, 'packlist + metadata sanity checks failed', Date.now() - start);
61
+ detail(e && e.stack ? e.stack : String(e));
71
62
  process.exit(1);
72
63
  }
@@ -18,45 +18,29 @@ const { setTimeout: sleep } = require('node:timers/promises');
18
18
 
19
19
  const ROOT = path.resolve(__dirname, '..');
20
20
 
21
- const TTY = process.stdout.isTTY;
22
- const C = TTY
23
- ? { g: '\x1b[32m', r: '\x1b[31m', y: '\x1b[33m', dim: '\x1b[2m', n: '\x1b[0m' }
24
- : { g: '', r: '', y: '', dim: '', n: '' };
25
- const msTag = (ms) => `${C.dim}(${ms} ms)${C.n}`;
21
+ const { detail, failResult, info, pass } = require('./report');
26
22
 
27
23
  const TOTAL_TESTS = (fs.readFileSync(__filename, 'utf8').match(/^\s*beginTest\(/gm) || []).length;
28
- const idxWidth = String(Math.max(1, TOTAL_TESTS)).length;
29
24
  let passed = 0;
30
25
  let failed = 0;
31
26
  let currentTest = null;
32
27
  let nonTestFailure = false;
33
28
  const suiteStart = Date.now();
34
29
 
35
- function ok(msg) {
36
- console.log(`${C.g}OK${C.n} ${msg}`);
37
- }
38
- function info(msg) {
39
- console.log(`${C.y}==${C.n} ${msg}`);
40
- }
41
- function fail(msg) {
42
- console.error(`${C.r}FAIL${C.n} ${msg}`);
43
- }
44
30
  function beginTest(msg) {
45
31
  currentTest = { msg, start: Date.now() };
46
32
  }
47
33
  function endTest() {
48
34
  const tc = currentTest;
49
35
  if (!tc) return;
50
- const idx = String(passed + failed + 1).padStart(idxWidth, '0');
51
- ok(`${idx} ${tc.msg} ${msTag(Date.now() - tc.start)}`);
36
+ pass(passed + failed + 1, tc.msg, Date.now() - tc.start);
52
37
  passed += 1;
53
38
  currentTest = null;
54
39
  }
55
40
  function recordCurrentFailure() {
56
41
  const tc = currentTest;
57
42
  if (!tc) return false;
58
- const idx = String(passed + failed + 1).padStart(idxWidth, '0');
59
- fail(`${idx} ${tc.msg} ${msTag(Date.now() - tc.start)}`);
43
+ failResult(passed + failed + 1, tc.msg, Date.now() - tc.start);
60
44
  failed += 1;
61
45
  currentTest = null;
62
46
  return true;
@@ -66,9 +50,9 @@ function printSummary() {
66
50
  const suiteMs = Date.now() - suiteStart;
67
51
  info(`Total elapsed: ${suiteMs} ms (${(suiteMs / 1000).toFixed(2)} s)`);
68
52
  if (failed === 0 && !nonTestFailure) {
69
- ok(`All playground tests passed (${passed}/${TOTAL_TESTS})`);
53
+ info(`All playground tests passed (${passed}/${TOTAL_TESTS})`);
70
54
  } else {
71
- fail(`Some playground tests failed (${passed}/${TOTAL_TESTS})`);
55
+ info(`Some playground tests failed (${passed}/${TOTAL_TESTS})`);
72
56
  }
73
57
  }
74
58
 
@@ -1269,6 +1253,6 @@ ${JSON.stringify(last, null, 2)}`);
1269
1253
  main().catch((e) => {
1270
1254
  if (!recordCurrentFailure()) nonTestFailure = true;
1271
1255
  printSummary();
1272
- fail(e && e.stack ? e.stack : String(e));
1256
+ detail(e && e.stack ? e.stack : String(e));
1273
1257
  process.exit(1);
1274
1258
  });
@@ -3,44 +3,7 @@
3
3
 
4
4
  const cp = require('node:child_process');
5
5
 
6
- const USE_COLOR = !process.env.NO_COLOR && (
7
- process.stdout.isTTY ||
8
- (process.env.FORCE_COLOR && process.env.FORCE_COLOR !== '0')
9
- );
10
- const C = USE_COLOR
11
- ? { g: '\x1b[32m', r: '\x1b[31m', y: '\x1b[33m', gray: '\x1b[90m', dim: '\x1b[2m', n: '\x1b[0m' }
12
- : { g: '', r: '', y: '', gray: '', dim: '', n: '' };
13
-
14
- function formatDuration(ms) {
15
- if (!Number.isFinite(ms) || ms < 0) return '0 ms';
16
- if (ms < 1000) return `${Math.round(ms)} ms`;
17
- if (ms < 10000) return `${(ms / 1000).toFixed(2)} s`;
18
- if (ms < 60000) return `${(ms / 1000).toFixed(1)} s`;
19
-
20
- const minutes = Math.floor(ms / 60000);
21
- const seconds = ((ms % 60000) / 1000).toFixed(1).padStart(4, '0');
22
- return `${minutes}m ${seconds}s`;
23
- }
24
-
25
- function durationSuffix(ms) {
26
- return ms == null ? '' : ` ${C.gray}${formatDuration(ms)}${C.n}`;
27
- }
28
-
29
- function ok(msg, ms) {
30
- console.log(`${C.g}OK${C.n} ${msg}${durationSuffix(ms)}`);
31
- }
32
-
33
- function fail(msg, ms) {
34
- console.error(`${C.r}FAIL${C.n} ${msg}${durationSuffix(ms)}`);
35
- }
36
-
37
- function info(msg, ms) {
38
- console.log(`${C.y}==${C.n} ${msg}${durationSuffix(ms)}`);
39
- }
40
-
41
- function detail(msg) {
42
- console.log(`${C.dim}${msg}${C.n}`);
43
- }
6
+ const { C, detail, failResult, formatDuration, info, pass } = require('./report');
44
7
 
45
8
  function nowMs() {
46
9
  return Number(process.hrtime.bigint()) / 1e6;
@@ -143,9 +106,6 @@ function resolveSuiteKeys(args) {
143
106
  return keys;
144
107
  }
145
108
 
146
- function sequenceLabel(n) {
147
- return String(n).padStart(3, '0');
148
- }
149
109
 
150
110
  function createLineReader(onLine) {
151
111
  let buffer = '';
@@ -177,12 +137,12 @@ function printEvent(suiteResult, event, totals) {
177
137
  const caseElapsedMs = now - suiteResult.lastCaseAt;
178
138
  suiteResult.lastCaseAt = now;
179
139
 
180
- const message = `${sequenceLabel(totals.sequence)} ${suiteResult.suite.label}: ${event.message}`;
140
+ const message = `${suiteResult.suite.label}: ${event.message}`;
181
141
  if (event.kind === 'ok') {
182
- ok(message, caseElapsedMs);
142
+ pass(totals.sequence, message, caseElapsedMs);
183
143
  totals.passed++;
184
144
  } else {
185
- fail(message, caseElapsedMs);
145
+ failResult(totals.sequence, message, caseElapsedMs);
186
146
  totals.failed++;
187
147
  suiteResult.failedCount++;
188
148
  }
@@ -236,11 +196,11 @@ function runSuite(key, totals) {
236
196
  suiteResult.error = e;
237
197
  if (!sawCase) {
238
198
  totals.sequence++;
239
- fail(`${sequenceLabel(totals.sequence)} ${suite.label}: rdf-test-suite could not start: ${e.message || String(e)}`, elapsedMs);
199
+ failResult(totals.sequence, `${suite.label}: rdf-test-suite could not start: ${e.message || String(e)}`, elapsedMs);
240
200
  totals.failed++;
241
201
  suiteResult.caseCount++;
242
202
  }
243
- console.log(`${C.gray}Suite elapsed ${formatDuration(elapsedMs)}${C.n}`);
203
+ console.log(`${C.dim}Suite elapsed ${formatDuration(elapsedMs)}${C.n}`);
244
204
  console.log('');
245
205
  resolve({ ...suiteResult, status: 1, elapsedMs });
246
206
  return;
@@ -273,21 +233,21 @@ function runSuite(key, totals) {
273
233
  : `${suite.label}: rdf-test-suite exited with ${suiteResult.status === 0 ? 'success' : exitText}`;
274
234
 
275
235
  if (suiteResult.status === 0) {
276
- ok(`${sequenceLabel(totals.sequence)} ${message}`, elapsedMs);
236
+ pass(totals.sequence, message, elapsedMs);
277
237
  totals.passed++;
278
238
  } else {
279
- fail(`${sequenceLabel(totals.sequence)} ${message}`, elapsedMs);
239
+ failResult(totals.sequence, message, elapsedMs);
280
240
  totals.failed++;
281
241
  }
282
242
  suiteResult.caseCount++;
283
243
  } else if (suiteResult.status !== 0 && suiteResult.failedCount === 0) {
284
244
  totals.sequence++;
285
- fail(`${sequenceLabel(totals.sequence)} ${suite.label}: rdf-test-suite exited with status ${suiteResult.status}`, elapsedMs);
245
+ failResult(totals.sequence, `${suite.label}: rdf-test-suite exited with status ${suiteResult.status}`, elapsedMs);
286
246
  totals.failed++;
287
247
  suiteResult.caseCount++;
288
248
  }
289
249
 
290
- console.log(`${C.gray}Suite elapsed ${formatDuration(elapsedMs)}${C.n}`);
250
+ console.log(`${C.dim}Suite elapsed ${formatDuration(elapsedMs)}${C.n}`);
291
251
  console.log('');
292
252
  resolve(suiteResult);
293
253
  });
@@ -299,7 +259,7 @@ async function main() {
299
259
  try {
300
260
  keys = resolveSuiteKeys(process.argv.slice(2));
301
261
  } catch (e) {
302
- fail(e && e.message ? e.message : String(e));
262
+ failResult(1, e && e.message ? e.message : String(e), 0);
303
263
  process.exit(1);
304
264
  return;
305
265
  }
@@ -322,16 +282,17 @@ async function main() {
322
282
  info(`Grand total: ${totals.passed} OK, ${totals.failed} FAIL, ${totals.sequence} RDF 1.2 tests`, grandElapsedMs);
323
283
 
324
284
  if (totals.failed === 0 && results.every((suiteResult) => suiteResult.status === 0)) {
325
- ok(`All RDF 1.2 syntax tests passed (${totals.passed}/${totals.sequence})`);
285
+ info(`All RDF 1.2 syntax tests passed (${totals.passed}/${totals.sequence})`);
326
286
  process.exit(0);
327
287
  return;
328
288
  }
329
289
 
330
- fail(`Some RDF 1.2 syntax tests failed (${totals.passed}/${totals.sequence})`);
290
+ info(`Some RDF 1.2 syntax tests failed (${totals.passed}/${totals.sequence})`);
331
291
  process.exit(1);
332
292
  }
333
293
 
334
294
  main().catch((e) => {
335
- fail(e && e.stack ? e.stack : String(e));
295
+ failResult(1, 'RDF 1.2 syntax test runner failed', 0);
296
+ detail(e && e.stack ? e.stack : String(e));
336
297
  process.exit(1);
337
298
  });
package/test/report.js ADDED
@@ -0,0 +1,67 @@
1
+ 'use strict';
2
+
3
+ const USE_COLOR = !process.env.NO_COLOR && (
4
+ process.stdout.isTTY ||
5
+ (process.env.FORCE_COLOR && process.env.FORCE_COLOR !== '0')
6
+ );
7
+
8
+ const C = USE_COLOR
9
+ ? { g: '\x1b[32m', r: '\x1b[31m', y: '\x1b[33m', dim: '\x1b[2m', n: '\x1b[0m' }
10
+ : { g: '', r: '', y: '', dim: '', n: '' };
11
+
12
+ function formatDuration(ms) {
13
+ if (!Number.isFinite(ms) || ms < 0) return '0 ms';
14
+ if (ms < 1000) return `${Math.round(ms)} ms`;
15
+ if (ms < 10000) return `${(ms / 1000).toFixed(2)} s`;
16
+ if (ms < 60000) return `${(ms / 1000).toFixed(1)} s`;
17
+
18
+ const minutes = Math.floor(ms / 60000);
19
+ const seconds = ((ms % 60000) / 1000).toFixed(1).padStart(4, '0');
20
+ return `${minutes}m ${seconds}s`;
21
+ }
22
+
23
+ function durationSuffix(ms) {
24
+ return ms == null ? '' : ` ${C.dim}(${formatDuration(ms)})${C.n}`;
25
+ }
26
+
27
+ function sequenceLabel(n) {
28
+ return String(n).padStart(3, '0');
29
+ }
30
+
31
+ function result(status, n, description, ms) {
32
+ const color = status === 'OK' ? C.g : C.r;
33
+ const stream = status === 'OK' ? console.log : console.error;
34
+ stream(`${color}${status}${C.n} ${sequenceLabel(n)} ${description}${durationSuffix(ms)}`);
35
+ }
36
+
37
+ function pass(n, description, ms) {
38
+ result('OK', n, description, ms);
39
+ }
40
+
41
+ function failResult(n, description, ms) {
42
+ result('FAIL', n, description, ms);
43
+ }
44
+
45
+ function info(msg, ms) {
46
+ console.log(`${C.y}==${C.n} ${msg}${durationSuffix(ms)}`);
47
+ }
48
+
49
+ function warn(msg) {
50
+ console.log(`${C.y}SKIP${C.n} ${msg}`);
51
+ }
52
+
53
+ function detail(msg) {
54
+ console.log(`${C.dim}${msg}${C.n}`);
55
+ }
56
+
57
+ module.exports = {
58
+ C,
59
+ detail,
60
+ durationSuffix,
61
+ failResult,
62
+ formatDuration,
63
+ info,
64
+ pass,
65
+ sequenceLabel,
66
+ warn,
67
+ };
@@ -9,23 +9,7 @@ const path = require('node:path');
9
9
  const root = path.resolve(__dirname, '..');
10
10
  const eyelingJsPath = path.join(root, 'eyeling.js');
11
11
 
12
- const TTY = process.stdout.isTTY;
13
- const C = TTY
14
- ? { g: '\x1b[32m', r: '\x1b[31m', y: '\x1b[33m', dim: '\x1b[2m', n: '\x1b[0m' }
15
- : { g: '', r: '', y: '', dim: '', n: '' };
16
-
17
- function ok(msg) {
18
- console.log(`${C.g}OK ${C.n} ${msg}`);
19
- }
20
- function info(msg) {
21
- console.log(`${C.y}==${C.n} ${msg}`);
22
- }
23
- function fail(msg) {
24
- console.error(`${C.r}FAIL${C.n} ${msg}`);
25
- }
26
- function numberedName(index, name) {
27
- return `${String(index + 1).padStart(3, '0')} ${name}`;
28
- }
12
+ const { detail, failResult, info, pass } = require('./report');
29
13
  function msNow() {
30
14
  return Date.now();
31
15
  }
@@ -354,15 +338,16 @@ const cases = [
354
338
  let failed = 0;
355
339
  for (const [index, tc] of cases.entries()) {
356
340
  const tmp = mkTmpDir();
357
- const testName = numberedName(index, tc.name);
341
+ const testNr = index + 1;
342
+ const testName = tc.name;
358
343
  const start = msNow();
359
344
  try {
360
345
  await tc.run(tmp);
361
- ok(`${testName} ${C.dim}(${msNow() - start} ms)${C.n}`);
346
+ pass(testNr, testName, msNow() - start);
362
347
  passed++;
363
348
  } catch (e) {
364
- fail(`${testName} ${C.dim}(${msNow() - start} ms)${C.n}`);
365
- fail(e && e.stack ? e.stack : String(e));
349
+ failResult(testNr, testName, msNow() - start);
350
+ detail(e && e.stack ? e.stack : String(e));
366
351
  failed++;
367
352
  } finally {
368
353
  rmrf(tmp);
@@ -370,14 +355,15 @@ const cases = [
370
355
  }
371
356
  console.log('');
372
357
  const suiteMs = msNow() - suiteStart;
373
- console.log(`${C.y}==${C.n} Total elapsed: ${suiteMs} ms (${(suiteMs / 1000).toFixed(2)} s)`);
358
+ info(`Total elapsed: ${suiteMs} ms (${(suiteMs / 1000).toFixed(2)} s)`);
374
359
  if (failed === 0) {
375
- ok(`All stream-message tests passed (${passed}/${cases.length})`);
360
+ info(`All stream-message tests passed (${passed}/${cases.length})`);
376
361
  process.exit(0);
377
362
  }
378
- fail(`Some stream-message tests failed (${passed}/${cases.length})`);
363
+ info(`Some stream-message tests failed (${passed}/${cases.length})`);
379
364
  process.exit(1);
380
365
  })().catch((e) => {
381
- fail(e && e.stack ? e.stack : String(e));
366
+ failResult(1, 'stream-message test runner failed', 0);
367
+ detail(e && e.stack ? e.stack : String(e));
382
368
  process.exit(1);
383
369
  });