@vitronai/themis 0.1.0-beta.0 → 0.1.0-beta.2
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/CHANGELOG.md +16 -1
- package/README.md +173 -11
- package/docs/api.md +272 -4
- package/docs/schemas/agent-result.v1.json +7 -4
- package/docs/schemas/fix-handoff.v1.json +105 -0
- package/docs/schemas/generate-backlog.v1.json +117 -0
- package/docs/schemas/generate-handoff.v1.json +191 -0
- package/docs/schemas/generate-map.v1.json +95 -0
- package/docs/schemas/generate-result.v1.json +341 -0
- package/docs/vscode-extension.md +6 -0
- package/docs/why-themis.md +1 -1
- package/globals.d.ts +31 -1
- package/index.d.ts +405 -2
- package/index.js +14 -0
- package/package.json +1 -1
- package/src/artifacts.js +180 -2
- package/src/assets/exampleThemisReport.png +0 -0
- package/src/cli.js +390 -11
- package/src/config.js +21 -3
- package/src/discovery.js +32 -3
- package/src/expect.js +33 -4
- package/src/generate.js +5313 -0
- package/src/migrate.js +280 -0
- package/src/module-loader.js +22 -3
- package/src/reporter.js +4 -3
- package/src/runner.js +74 -13
- package/src/runtime.js +175 -66
- package/src/test-utils.js +607 -1
- package/src/watch.js +9 -0
- package/src/worker.js +1 -2
- package/src/snapshots.js +0 -90
package/src/snapshots.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const util = require('util');
|
|
4
|
-
|
|
5
|
-
function createSnapshotState(filePath, options = {}) {
|
|
6
|
-
const snapshotDir = path.join(path.dirname(filePath), '__snapshots__');
|
|
7
|
-
const snapshotFile = path.join(snapshotDir, `${path.basename(filePath)}.snapshots.json`);
|
|
8
|
-
const existing = readSnapshotFile(snapshotFile);
|
|
9
|
-
const nextSnapshots = { ...existing };
|
|
10
|
-
const counters = new Map();
|
|
11
|
-
let dirty = false;
|
|
12
|
-
let currentTestName = null;
|
|
13
|
-
|
|
14
|
-
return {
|
|
15
|
-
setCurrentTestName(testName) {
|
|
16
|
-
currentTestName = testName;
|
|
17
|
-
},
|
|
18
|
-
clearCurrentTestName() {
|
|
19
|
-
currentTestName = null;
|
|
20
|
-
},
|
|
21
|
-
matchSnapshot(received, snapshotName) {
|
|
22
|
-
if (!currentTestName) {
|
|
23
|
-
throw new Error('toMatchSnapshot() must be called while a test is running');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const baseKey = snapshotName
|
|
27
|
-
? `${currentTestName}: ${String(snapshotName)}`
|
|
28
|
-
: currentTestName;
|
|
29
|
-
const nextIndex = (counters.get(baseKey) || 0) + 1;
|
|
30
|
-
counters.set(baseKey, nextIndex);
|
|
31
|
-
const snapshotKey = nextIndex === 1 ? baseKey : `${baseKey} (${nextIndex})`;
|
|
32
|
-
const serialized = serializeSnapshot(received);
|
|
33
|
-
|
|
34
|
-
if (!Object.prototype.hasOwnProperty.call(existing, snapshotKey)) {
|
|
35
|
-
nextSnapshots[snapshotKey] = serialized;
|
|
36
|
-
dirty = true;
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (existing[snapshotKey] !== serialized) {
|
|
41
|
-
if (options.updateSnapshots) {
|
|
42
|
-
nextSnapshots[snapshotKey] = serialized;
|
|
43
|
-
dirty = true;
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
throw new Error(
|
|
48
|
-
`Snapshot mismatch for ${snapshotKey}\n\nExpected:\n${existing[snapshotKey]}\n\nReceived:\n${serialized}`
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
save() {
|
|
53
|
-
if (!dirty) {
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
fs.mkdirSync(snapshotDir, { recursive: true });
|
|
58
|
-
fs.writeFileSync(snapshotFile, `${JSON.stringify(nextSnapshots, null, 2)}\n`, 'utf8');
|
|
59
|
-
return snapshotFile;
|
|
60
|
-
},
|
|
61
|
-
path: snapshotFile
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function readSnapshotFile(snapshotFile) {
|
|
66
|
-
if (!fs.existsSync(snapshotFile)) {
|
|
67
|
-
return {};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return JSON.parse(fs.readFileSync(snapshotFile, 'utf8'));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function serializeSnapshot(value) {
|
|
74
|
-
if (typeof value === 'string') {
|
|
75
|
-
return value;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return util.inspect(value, {
|
|
79
|
-
depth: 20,
|
|
80
|
-
colors: false,
|
|
81
|
-
sorted: true,
|
|
82
|
-
compact: false,
|
|
83
|
-
breakLength: 80,
|
|
84
|
-
maxArrayLength: null
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
module.exports = {
|
|
89
|
-
createSnapshotState
|
|
90
|
-
};
|