kryptheon 0.1.40 → 0.1.42
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 +102 -21
- package/kryptheon-dashboard.js +33 -4
- package/kryptheon-recordings.js +1 -1
- package/kryptheon-testfiles.js +98 -0
- package/package.json +5 -3
- package/playwright.config.js +3 -0
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 +
|
|
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
|
-
|
|
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:
|
|
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' }
|
|
@@ -2632,9 +2658,12 @@ function dashboardAlreadyRunning(port) {
|
|
|
2632
2658
|
res.on('data', (chunk) => { if (body.length < 5000000) body += chunk; });
|
|
2633
2659
|
res.on('end', () => {
|
|
2634
2660
|
try {
|
|
2635
|
-
const
|
|
2661
|
+
const state = JSON.parse(body);
|
|
2662
|
+
const root = state.project.root;
|
|
2636
2663
|
const same = (a) => (process.platform === 'win32' ? path.resolve(a).toLowerCase() : path.resolve(a));
|
|
2637
|
-
|
|
2664
|
+
if (res.statusCode !== 200 || typeof root !== 'string' || same(root) !== same(USER_DIR)) return resolve(false);
|
|
2665
|
+
// Before 0.1.41 a dashboard did not say which it was: an old one.
|
|
2666
|
+
resolve({ version: typeof state.kryptheon === 'string' ? state.kryptheon : null });
|
|
2638
2667
|
} catch (err) {
|
|
2639
2668
|
resolve(false);
|
|
2640
2669
|
}
|
|
@@ -2645,6 +2674,49 @@ function dashboardAlreadyRunning(port) {
|
|
|
2645
2674
|
});
|
|
2646
2675
|
}
|
|
2647
2676
|
|
|
2677
|
+
/** The process listening on 127.0.0.1:port, or null. */
|
|
2678
|
+
function listenerOn(port) {
|
|
2679
|
+
try {
|
|
2680
|
+
if (process.platform === 'win32') {
|
|
2681
|
+
const out = spawnSync('netstat', ['-ano', '-p', 'TCP'], { encoding: 'utf8', windowsHide: true, timeout: 10000 }).stdout || '';
|
|
2682
|
+
for (const line of out.split(/\r?\n/)) {
|
|
2683
|
+
const m = line.trim().split(/\s+/);
|
|
2684
|
+
if (m.length >= 5 && m[1] === '127.0.0.1:' + port && m[3] === 'LISTENING' && /^\d+$/.test(m[4])) return Number(m[4]);
|
|
2685
|
+
}
|
|
2686
|
+
return null;
|
|
2687
|
+
}
|
|
2688
|
+
const out = spawnSync('lsof', ['-nP', '-iTCP@127.0.0.1:' + port, '-sTCP:LISTEN', '-t'], { encoding: 'utf8', timeout: 10000 }).stdout || '';
|
|
2689
|
+
const pid = Number(out.trim().split(/\s+/)[0]);
|
|
2690
|
+
return pid > 0 ? pid : null;
|
|
2691
|
+
} catch (err) {
|
|
2692
|
+
return null;
|
|
2693
|
+
}
|
|
2694
|
+
}
|
|
2695
|
+
|
|
2696
|
+
/**
|
|
2697
|
+
* An older dashboard for this same folder, still running - from yesterday's
|
|
2698
|
+
* Win+R, or started at sign-in - is stopped so this version takes its place.
|
|
2699
|
+
* Found when the first paying user ran the new version and kept getting the
|
|
2700
|
+
* old page: npx fetched the new one, which then only opened the old one.
|
|
2701
|
+
* Only the process that answered as this folder's Kryptheon dashboard is
|
|
2702
|
+
* stopped. Whether the port came free is the answer.
|
|
2703
|
+
*/
|
|
2704
|
+
async function replaceOldDashboard(port) {
|
|
2705
|
+
const pid = listenerOn(port);
|
|
2706
|
+
if (!pid || pid === process.pid) return false;
|
|
2707
|
+
try {
|
|
2708
|
+
if (process.platform === 'win32') spawnSync('taskkill', ['/PID', String(pid), '/F'], { windowsHide: true, timeout: 10000 });
|
|
2709
|
+
else process.kill(pid, 'SIGTERM');
|
|
2710
|
+
} catch (err) {
|
|
2711
|
+
return false;
|
|
2712
|
+
}
|
|
2713
|
+
for (let i = 0; i < 50; i++) {
|
|
2714
|
+
if (listenerOn(port) === null) return true;
|
|
2715
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
2716
|
+
}
|
|
2717
|
+
return false;
|
|
2718
|
+
}
|
|
2719
|
+
|
|
2648
2720
|
/**
|
|
2649
2721
|
* The dashboard, started from the home folder: kept in a kryptheon-tests
|
|
2650
2722
|
* folder there, the one record already uses - set up the first time, asked
|
|
@@ -2732,7 +2804,16 @@ async function dashboardCommand() {
|
|
|
2732
2804
|
}
|
|
2733
2805
|
// Running already: open that one rather than a second, which would watch
|
|
2734
2806
|
// the same project twice. Exit code 0 is how the launcher knows.
|
|
2735
|
-
|
|
2807
|
+
const running = await dashboardAlreadyRunning(DASHBOARD_PORT);
|
|
2808
|
+
const mine = require(path.join(PACKAGE_DIR, 'package.json')).version;
|
|
2809
|
+
if (running && running.version !== mine) {
|
|
2810
|
+
const was = running.version || 'from before 0.1.41';
|
|
2811
|
+
console.log('');
|
|
2812
|
+
console.log(await replaceOldDashboard(DASHBOARD_PORT)
|
|
2813
|
+
? ' An older Kryptheon dashboard (' + was + ') was running for this folder.\n It was closed, and ' + mine + ' starts in its place.'
|
|
2814
|
+
: ' An older Kryptheon dashboard (' + was + ') is still running and could not be\n closed. This one starts at another address; close the old window when you can.');
|
|
2815
|
+
}
|
|
2816
|
+
if (running && running.version === mine) {
|
|
2736
2817
|
const address = 'http://127.0.0.1:' + DASHBOARD_PORT + '/';
|
|
2737
2818
|
const shown = openInBrowser(address);
|
|
2738
2819
|
console.log('');
|
package/kryptheon-dashboard.js
CHANGED
|
@@ -25,6 +25,7 @@ const { spawnSync } = require('child_process');
|
|
|
25
25
|
const store = require('./kryptheon-store.js');
|
|
26
26
|
const changes = require('./kryptheon-changes.js');
|
|
27
27
|
const autostart = require('./kryptheon-autostart.js');
|
|
28
|
+
const VERSION = require('./package.json').version;
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
* Every check the dashboard knows the name of, in the order the person asked
|
|
@@ -179,7 +180,8 @@ function flowPrompt(t, lastPass) {
|
|
|
179
180
|
|
|
180
181
|
function countRecordings(root) {
|
|
181
182
|
try {
|
|
182
|
-
|
|
183
|
+
// Recordings only - not the project's own unit tests in tests/.
|
|
184
|
+
return require('./kryptheon-testfiles.js').recordingNames(path.join(root, 'tests')).length;
|
|
183
185
|
} catch (err) {
|
|
184
186
|
return 0;
|
|
185
187
|
}
|
|
@@ -543,6 +545,9 @@ function buildState(root, env) {
|
|
|
543
545
|
|
|
544
546
|
return {
|
|
545
547
|
project: { name: path.basename(root), root: root, storeDir: paths.dir },
|
|
548
|
+
// Which kryptheon this dashboard is: a newer `dashboard` asks, and takes
|
|
549
|
+
// the place of an older one still running, instead of opening it.
|
|
550
|
+
kryptheon: VERSION,
|
|
546
551
|
looks: looks,
|
|
547
552
|
proven: proven,
|
|
548
553
|
checks: checks,
|
|
@@ -663,7 +668,30 @@ function appAddress(value) {
|
|
|
663
668
|
const text = value.trim();
|
|
664
669
|
if (!text || text.length > 2000 || /[\s\x00-\x1f]/.test(text) || text.startsWith('-')) return null;
|
|
665
670
|
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(text)) return /^https?:\/\/[^/]/i.test(text) ? text : null;
|
|
666
|
-
|
|
671
|
+
// A path never starts with "//": "http//localhost:3000" is a mistyped
|
|
672
|
+
// scheme, not a host called "http".
|
|
673
|
+
return /^[a-z0-9.-]+(:\d{1,5})?(\/(?!\/)\S*)?$/i.test(text) ? text : null;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
/**
|
|
677
|
+
* What was meant, when an address was typed with its start mistyped:
|
|
678
|
+
* "ttp://127.0.0.1:4180" (blind round 13, the first letter lost), "htp://",
|
|
679
|
+
* "http//", "http:/", "htps://". Null when it does not look like that.
|
|
680
|
+
*/
|
|
681
|
+
function meantAddress(value) {
|
|
682
|
+
const text = String(value || '').trim();
|
|
683
|
+
const m = /^(h?t{1,3}p{1,2}(s?)|htps|hhttps?)(:\/{0,3}|\/{1,3}|:)(?!\/)(\S+)$/i.exec(text);
|
|
684
|
+
if (!m) return null;
|
|
685
|
+
const secure = /s$/i.test(m[1]);
|
|
686
|
+
const fixed = (secure ? 'https://' : 'http://') + m[4];
|
|
687
|
+
return fixed !== text && appAddress(fixed) ? fixed : null;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
function notAnAddress(value, example) {
|
|
691
|
+
const meant = meantAddress(value);
|
|
692
|
+
return meant
|
|
693
|
+
? 'that is not a web address - did you mean ' + meant + '?'
|
|
694
|
+
: 'that is not a web address - it should look like ' + example;
|
|
667
695
|
}
|
|
668
696
|
|
|
669
697
|
/** The connection string as given, or null when there is none or it is absurd. */
|
|
@@ -869,7 +897,7 @@ function createServer(root, options) {
|
|
|
869
897
|
}
|
|
870
898
|
if (url.pathname === '/api/record' && typeof opts.record === 'function') {
|
|
871
899
|
const address = appAddress(input.url);
|
|
872
|
-
if (!address) return json(res, 400, { ok: false, why: '
|
|
900
|
+
if (!address) return json(res, 400, { ok: false, why: notAnAddress(input.url, 'http://localhost:3000') });
|
|
873
901
|
const phone = input.phone === true;
|
|
874
902
|
return begin('record', 'Recording ' + address + (phone ? ' at phone size' : ''),
|
|
875
903
|
'npx kryptheon record ' + address + (phone ? ' --phone' : ''), (say) => opts.record(address, say, { phone: phone }));
|
|
@@ -909,7 +937,7 @@ function createServer(root, options) {
|
|
|
909
937
|
// outside check start from it. Empty clears it.
|
|
910
938
|
const raw = typeof input.address === 'string' ? input.address.trim() : '';
|
|
911
939
|
const address = raw ? appAddress(raw) : '';
|
|
912
|
-
if (address === null) return json(res, 400, { ok: false, why: '
|
|
940
|
+
if (address === null) return json(res, 400, { ok: false, why: notAnAddress(raw, 'https://my-app.lovable.app') });
|
|
913
941
|
const full = address && !/^https?:\/\//i.test(address) ? 'https://' + address : address;
|
|
914
942
|
return saveAppAddress(store.pathsFor(root, env), full)
|
|
915
943
|
? json(res, 200, { ok: true, address: full })
|
|
@@ -965,6 +993,7 @@ module.exports = {
|
|
|
965
993
|
buildState: buildState,
|
|
966
994
|
flowPrompt: flowPrompt,
|
|
967
995
|
appAddress: appAddress,
|
|
996
|
+
meantAddress: meantAddress,
|
|
968
997
|
secretsOf: secretsOf,
|
|
969
998
|
hideSecrets: hideSecrets,
|
|
970
999
|
hideSecretsIn: hideSecretsIn,
|
package/kryptheon-recordings.js
CHANGED
|
@@ -113,7 +113,7 @@ function chooseFromList(names, answer) {
|
|
|
113
113
|
const lower = said.toLowerCase();
|
|
114
114
|
const matches = list.filter((name) => {
|
|
115
115
|
const n = String(name).toLowerCase();
|
|
116
|
-
return n === lower || n === lower + '.spec.js' || n.replace(/\.spec\.js$/, '') === lower;
|
|
116
|
+
return n === lower || n === lower + '.spec.js' || n.replace(/\.(spec|kryptheon)\.js$/, '') === lower;
|
|
117
117
|
});
|
|
118
118
|
if (matches.length === 1) return { action: 'remove', names: matches };
|
|
119
119
|
if (matches.length > 1) {
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// Which files in tests/ are Kryptheon's recordings, and what a new one is
|
|
2
|
+
// called.
|
|
3
|
+
//
|
|
4
|
+
// Found in blind round 13 (a TypeScript service with vitest): its own unit
|
|
5
|
+
// test, tests/incidents.test.ts, was taken for a recording - check said it
|
|
6
|
+
// "only opens a page and stops", and the dashboard showed "Record your main
|
|
7
|
+
// flows: Done, 1 recording held" before anything was recorded. Then the
|
|
8
|
+
// first real recording, saved as tests/<name>.spec.js, was picked up by the
|
|
9
|
+
// project's own `npm test` (vitest), which failed on it: "Playwright Test did
|
|
10
|
+
// not expect test() to be called here". A tool that breaks the app's own
|
|
11
|
+
// tests is one nobody keeps.
|
|
12
|
+
//
|
|
13
|
+
// So: a recording is a file that uses Playwright or Kryptheon's fixture -
|
|
14
|
+
// anything else in tests/ belongs to the project and is left alone. And in a
|
|
15
|
+
// project whose unit-test runner collects *.spec.js / *.test.js, a new
|
|
16
|
+
// recording is saved as <name>.kryptheon.js, which only Kryptheon runs.
|
|
17
|
+
|
|
18
|
+
const fs = require('fs');
|
|
19
|
+
const path = require('path');
|
|
20
|
+
|
|
21
|
+
const SPEC_NAME = /\.(spec|test)\.[cm]?[jt]sx?$/;
|
|
22
|
+
const OWN_NAME = /\.kryptheon\.js$/;
|
|
23
|
+
// What a recording imports: Playwright directly (older or hand-made ones,
|
|
24
|
+
// repaired by check) or the fixture - by package name, or by any path that
|
|
25
|
+
// ends in kryptheon-fixture(.js), relative or absolute.
|
|
26
|
+
const USES_PLAYWRIGHT = /(['"`])(?:@playwright\/test|[^'"`\r\n]*kryptheon-fixture(?:\.js)?)\1/;
|
|
27
|
+
|
|
28
|
+
/** Whether this file in tests/ is one of Kryptheon's recordings. */
|
|
29
|
+
function isRecordingFile(name, source) {
|
|
30
|
+
if (!SPEC_NAME.test(name) && !OWN_NAME.test(name)) return false;
|
|
31
|
+
return USES_PLAYWRIGHT.test(String(source || ''));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The recordings in a tests folder, as paths relative to it. */
|
|
35
|
+
function recordingNames(testsDir) {
|
|
36
|
+
let entries = [];
|
|
37
|
+
try {
|
|
38
|
+
entries = fs.readdirSync(testsDir, { recursive: true });
|
|
39
|
+
} catch (err) {
|
|
40
|
+
try {
|
|
41
|
+
entries = fs.readdirSync(testsDir);
|
|
42
|
+
} catch (err2) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return entries.map(String).filter((name) => {
|
|
47
|
+
if (!SPEC_NAME.test(name) && !OWN_NAME.test(name)) return false;
|
|
48
|
+
try {
|
|
49
|
+
return isRecordingFile(name, fs.readFileSync(path.join(testsDir, name), 'utf8'));
|
|
50
|
+
} catch (err) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The unit-test runner this project uses that would also collect
|
|
58
|
+
* tests/*.spec.js or tests/*.test.js: 'vitest', 'jest', 'mocha' - or null.
|
|
59
|
+
*/
|
|
60
|
+
function unitRunnerOf(projectDir) {
|
|
61
|
+
let pkg = {};
|
|
62
|
+
try {
|
|
63
|
+
pkg = JSON.parse(fs.readFileSync(path.join(projectDir, 'package.json'), 'utf8'));
|
|
64
|
+
} catch (err) {
|
|
65
|
+
pkg = {};
|
|
66
|
+
}
|
|
67
|
+
const deps = Object.assign({}, pkg.dependencies, pkg.devDependencies);
|
|
68
|
+
const script = String((pkg.scripts && pkg.scripts.test) || '');
|
|
69
|
+
let files = [];
|
|
70
|
+
try {
|
|
71
|
+
files = fs.readdirSync(projectDir);
|
|
72
|
+
} catch (err) {
|
|
73
|
+
files = [];
|
|
74
|
+
}
|
|
75
|
+
const has = (re) => files.some((f) => re.test(f));
|
|
76
|
+
if (deps.vitest || /\bvitest\b/.test(script) || has(/^vitest\.config\./)) return 'vitest';
|
|
77
|
+
if (deps.jest || pkg.jest || /\bjest\b/.test(script) || has(/^jest\.config\./)) return 'jest';
|
|
78
|
+
if (deps.mocha || /\bmocha\b/.test(script) || has(/^\.mocharc/)) return 'mocha';
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** What a new recording's file name ends in, in this project. */
|
|
83
|
+
function recordingExtension(projectDir) {
|
|
84
|
+
return unitRunnerOf(projectDir) ? '.kryptheon.js' : '.spec.js';
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** A recording's name without its ending: "login" for login.spec.js or login.kryptheon.js. */
|
|
88
|
+
function bareName(name) {
|
|
89
|
+
return String(name).replace(OWN_NAME, '').replace(/\.spec\.js$/, '');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
module.exports = {
|
|
93
|
+
isRecordingFile: isRecordingFile,
|
|
94
|
+
recordingNames: recordingNames,
|
|
95
|
+
unitRunnerOf: unitRunnerOf,
|
|
96
|
+
recordingExtension: recordingExtension,
|
|
97
|
+
bareName: bareName,
|
|
98
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kryptheon",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.42",
|
|
4
4
|
"description": "Record what you do in your app and get plain-language reports when it breaks.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"kryptheon-heal.js",
|
|
29
29
|
"kryptheon-selectors.js",
|
|
30
30
|
"kryptheon-recordings.js",
|
|
31
|
+
"kryptheon-testfiles.js",
|
|
31
32
|
"kryptheon-cleanup.js",
|
|
32
33
|
"kryptheon-baselines.js",
|
|
33
34
|
"kryptheon-project.js",
|
|
@@ -52,7 +53,7 @@
|
|
|
52
53
|
"@playwright/test": "^1.62.1"
|
|
53
54
|
},
|
|
54
55
|
"scripts": {
|
|
55
|
-
"check": "node kryptheon-store.check.js && node kryptheon-code.check.js && node kryptheon-constdata.check.js && node kryptheon-accept.check.js && node kryptheon-keys.check.js && node kryptheon-dashboard.check.js && node kryptheon-autostart.check.js && node kryptheon-changes.check.js && node kryptheon-look.check.js && node kryptheon-verify.check.js && node kryptheon-recheck.check.js && node kryptheon-reporter.check.js && node kryptheon-signature.check.js && node kryptheon-signature.stream.check.js && node kryptheon-signature.baseline.check.js && node kryptheon-signature.settle.check.js && node kryptheon-signature.number.check.js && node kryptheon-env.check.js && node kryptheon-watchdog.check.js && node kryptheon-phone.check.js && node kryptheon-homedash.check.js && node kryptheon-record.check.js && node kryptheon-selectors.check.js && node kryptheon-recordings.check.js && node kryptheon-cleanup.check.js && node kryptheon-orphan.check.js && node kryptheon-project.check.js && node kryptheon-setup.check.js && node kryptheon-browser.check.js && node kryptheon-heal.check.js && node kryptheon-load.check.js && node kryptheon-package.check.js",
|
|
56
|
+
"check": "node kryptheon-store.check.js && node kryptheon-code.check.js && node kryptheon-constdata.check.js && node kryptheon-accept.check.js && node kryptheon-keys.check.js && node kryptheon-dashboard.check.js && node kryptheon-autostart.check.js && node kryptheon-changes.check.js && node kryptheon-look.check.js && node kryptheon-verify.check.js && node kryptheon-recheck.check.js && node kryptheon-reporter.check.js && node kryptheon-signature.check.js && node kryptheon-signature.stream.check.js && node kryptheon-signature.baseline.check.js && node kryptheon-signature.settle.check.js && node kryptheon-signature.number.check.js && node kryptheon-env.check.js && node kryptheon-watchdog.check.js && node kryptheon-phone.check.js && node kryptheon-homedash.check.js && node kryptheon-record.check.js && node kryptheon-selectors.check.js && node kryptheon-recordings.check.js && node kryptheon-testfiles.check.js && node kryptheon-cleanup.check.js && node kryptheon-orphan.check.js && node kryptheon-project.check.js && node kryptheon-setup.check.js && node kryptheon-browser.check.js && node kryptheon-heal.check.js && node kryptheon-load.check.js && node kryptheon-package.check.js",
|
|
56
57
|
"check:store": "node kryptheon-store.check.js",
|
|
57
58
|
"check:code": "node kryptheon-code.check.js",
|
|
58
59
|
"check:constdata": "node kryptheon-constdata.check.js",
|
|
@@ -81,7 +82,8 @@
|
|
|
81
82
|
"check:heal": "node kryptheon-heal.check.js",
|
|
82
83
|
"check:load": "node kryptheon-load.check.js",
|
|
83
84
|
"check:package": "node kryptheon-package.check.js",
|
|
84
|
-
"prepublishOnly": "node kryptheon-package.check.js"
|
|
85
|
+
"prepublishOnly": "node kryptheon-package.check.js",
|
|
86
|
+
"check:testfiles": "node kryptheon-testfiles.check.js"
|
|
85
87
|
},
|
|
86
88
|
"keywords": [
|
|
87
89
|
"playwright",
|
package/playwright.config.js
CHANGED
|
@@ -41,6 +41,9 @@ loadEnv(path.join(USER_DIR, '.env'));
|
|
|
41
41
|
module.exports = defineConfig({
|
|
42
42
|
// The tests belong to the user, so they are found in their folder.
|
|
43
43
|
testDir: path.join(USER_DIR, 'tests'),
|
|
44
|
+
// Playwright's own pattern, plus <name>.kryptheon.js: the name a recording
|
|
45
|
+
// gets in a project whose unit-test runner would also collect *.spec.js.
|
|
46
|
+
testMatch: ['**/*.@(spec|test).?(c|m)[jt]s?(x)', '**/*.kryptheon.js'],
|
|
44
47
|
// Screenshots and other artefacts default to sitting next to the config,
|
|
45
48
|
// which once installed means inside node_modules. They belong to the user's
|
|
46
49
|
// project, so they go to its store - outside the project, where a commit of
|