kryptheon 0.1.41 → 0.1.43

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/bin/kryptheon.js CHANGED
@@ -19,6 +19,7 @@ const secrets = require(require('path').join(__dirname, '..', 'kryptheon-secrets
19
19
  const replay = require('../kryptheon-replay.js');
20
20
  const selectors = require('../kryptheon-selectors.js');
21
21
  const recordings = require('../kryptheon-recordings.js');
22
+ const testfiles = require('../kryptheon-testfiles.js');
22
23
  const cleanup = require('../kryptheon-cleanup.js');
23
24
  const baselines = require('../kryptheon-baselines.js');
24
25
  const project = require('../kryptheon-project.js');
@@ -184,21 +185,11 @@ function ensureBrowser() {
184
185
  return true;
185
186
  }
186
187
 
188
+ // Only Kryptheon's recordings: the project's own unit tests in tests/ are not
189
+ // ours to run, count or call "not a real recording" (kryptheon-testfiles.js).
187
190
  function listSpecFiles() {
188
191
  if (!fs.existsSync(TESTS_DIR)) return [];
189
- let entries = [];
190
- try {
191
- entries = fs.readdirSync(TESTS_DIR, { recursive: true });
192
- } catch (err) {
193
- try {
194
- entries = fs.readdirSync(TESTS_DIR);
195
- } catch (err2) {
196
- return [];
197
- }
198
- }
199
- return entries
200
- .map(String)
201
- .filter((name) => /\.(spec|test)\.(c|m)?[jt]sx?$/.test(name));
192
+ return testfiles.recordingNames(TESTS_DIR);
202
193
  }
203
194
 
204
195
  // A plain GET on Node's own http/https, deliberately NOT fetch. fetch keeps
@@ -405,7 +396,7 @@ function timestampName() {
405
396
  'recorded-' +
406
397
  d.getFullYear() + pad(d.getMonth() + 1) + pad(d.getDate()) +
407
398
  '-' + pad(d.getHours()) + pad(d.getMinutes()) + pad(d.getSeconds()) +
408
- '.spec.js'
399
+ testfiles.recordingExtension(USER_DIR)
409
400
  );
410
401
  }
411
402
 
@@ -550,11 +541,12 @@ async function nameRecording(relativeFile) {
550
541
  const safeName = name.replace(/'/g, "\\'");
551
542
  const updated = src.replace(/\btest\(\s*(['"])test\1/, "test('" + safeName + "'");
552
543
 
553
- let target = path.join('tests', slugify(name) + '.spec.js');
544
+ const ext = testfiles.recordingExtension(USER_DIR);
545
+ let target = path.join('tests', slugify(name) + ext);
554
546
  let attempt = 1;
555
547
  while (fs.existsSync(path.join(USER_DIR, target)) && path.join(USER_DIR, target) !== full) {
556
548
  attempt += 1;
557
- target = path.join('tests', slugify(name) + '-' + attempt + '.spec.js');
549
+ target = path.join('tests', slugify(name) + '-' + attempt + ext);
558
550
  }
559
551
 
560
552
  try {
@@ -1837,6 +1829,21 @@ function check(options) {
1837
1829
  }
1838
1830
  }
1839
1831
 
1832
+ // A recording named *.spec.js in a project whose own test runner collects
1833
+ // *.spec.js too: that runner tries to run it and fails. Said, with the name
1834
+ // that only Kryptheon runs - the file is the person's, so not renamed here.
1835
+ const runner = testfiles.unitRunnerOf(USER_DIR);
1836
+ const clashing = runner ? triage.runnable.filter((name) => !/\.kryptheon\.js$/.test(name)) : [];
1837
+ if (clashing.length) {
1838
+ console.log('');
1839
+ console.log(' Your own tests (' + runner + ') also pick up ' + recordings.plural(clashing.length, 'recording') + ' here, and fail on ' +
1840
+ (clashing.length === 1 ? 'it' : 'them') + '.');
1841
+ console.log(' Rename ' + (clashing.length === 1 ? 'it' : 'each') + ' to end in .kryptheon.js - only Kryptheon runs those:');
1842
+ for (const name of clashing) {
1843
+ console.log(' ' + path.join('tests', name) + ' -> ' + path.join('tests', testfiles.bareName(name.replace(/\.(spec|test)\.[cm]?[jt]sx?$/, '')) + '.kryptheon.js'));
1844
+ }
1845
+ }
1846
+
1840
1847
  for (const name of triage.notRecordings) {
1841
1848
  console.log('');
1842
1849
  console.log(' Skipped ' + path.join('tests', name));
@@ -2425,6 +2432,23 @@ const NIGHT_WORDS = {
2425
2432
 
2426
2433
  const NIGHT_SAYS = { 0: 'nothing got through', 1: 'something got through - see Findings', 2: 'it could not check' };
2427
2434
 
2435
+ /**
2436
+ * The one line the dashboard shows for a database check. Exit 0 is "nothing
2437
+ * got through" only when everything was tested: found on blind round 13, the
2438
+ * page said "Result: nothing got through" while kryptheon-night itself said 7
2439
+ * tables could not be acted on at all. What it printed says how many.
2440
+ */
2441
+ function scanSummary(code, printed) {
2442
+ const said = NIGHT_SAYS[code] || 'it ended with exit ' + code;
2443
+ if (code === 2) return said;
2444
+ const text = String(printed || '').replace(/\s+/g, ' ');
2445
+ const m = /(\d+) (tables? (?:was|were) NOT checked|parts? of your app (?:was|were) not tested)/.exec(text);
2446
+ if (!m) return said;
2447
+ const n = Number(m[1]);
2448
+ return said + ' - but ' + n + (/^table/.test(m[2]) ? (n === 1 ? ' table was' : ' tables were') : (n === 1 ? ' part was' : ' parts were')) +
2449
+ ' not tested, so that is not a green light. See what it printed.';
2450
+ }
2451
+
2428
2452
  function runFromDashboard(id, opened, say) {
2429
2453
  if (id === 'frontend') {
2430
2454
  say('Reading the code in ' + USER_DIR + ' ...');
@@ -2486,9 +2510,11 @@ function recordFromDashboard(address, say, options) {
2486
2510
 
2487
2511
  /** One database action, through kryptheon-night, with the string in its environment only. */
2488
2512
  function databaseFromDashboard(action, connection, say) {
2489
- return nightChild(NIGHT_WORDS[action], childEnv({ KN_DATABASE_URL: connection }), say).then(({ code }) => {
2513
+ const heard = [];
2514
+ const listen = (line) => { heard.push(String(line)); say(line); };
2515
+ return nightChild(NIGHT_WORDS[action], childEnv({ KN_DATABASE_URL: connection }), listen).then(({ code }) => {
2490
2516
  if (code === null || code === undefined) return { ok: false, why: 'kryptheon-night could not be started' };
2491
- if (action === 'scan') return { ok: code !== 2, exit: code, summary: NIGHT_SAYS[code] || 'it ended with exit ' + code };
2517
+ if (action === 'scan') return { ok: code !== 2, exit: code, summary: scanSummary(code, heard.join('\n')) };
2492
2518
  return code === 2 && action !== 'night'
2493
2519
  ? { ok: false, exit: code, why: 'it could not do that - the lines above say why' }
2494
2520
  : code === 2 ? { ok: false, exit: code, why: 'nothing to read back - the lines above say why' }