@regressionproof/snapshotter 0.6.4 → 0.6.5
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/build/esm/snapshot.d.ts +1 -1
- package/build/esm/snapshot.js +8 -64
- package/build/snapshot.d.ts +1 -1
- package/build/snapshot.js +7 -63
- package/package.json +2 -2
package/build/esm/snapshot.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { SnapshotOptions } from './snapshotter.types.js';
|
|
2
|
-
export declare function snapshot(options: SnapshotOptions):
|
|
2
|
+
export declare function snapshot(options: SnapshotOptions): Promise<boolean>;
|
package/build/esm/snapshot.js
CHANGED
|
@@ -7,52 +7,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import {
|
|
10
|
+
import { mkdirSync, writeFileSync } from 'fs';
|
|
11
11
|
import path from 'path';
|
|
12
12
|
import { buildLog } from '@sprucelabs/spruce-skill-utils';
|
|
13
13
|
import { gitCommit, gitPush } from './git.js.js';
|
|
14
14
|
import { syncFiles } from './sync.js.js';
|
|
15
|
-
const ERROR_FILE_NAME = 'lastError.json';
|
|
16
15
|
class Snapshotter {
|
|
17
16
|
constructor() {
|
|
18
17
|
this.log = buildLog('Snapshotter');
|
|
19
|
-
this.queue = [];
|
|
20
|
-
this.isProcessing = false;
|
|
21
18
|
}
|
|
22
19
|
snapshot(options) {
|
|
23
|
-
this.checkForPreviousFailure(options.mirrorPath);
|
|
24
|
-
this.enqueue(options);
|
|
25
|
-
}
|
|
26
|
-
checkForPreviousFailure(mirrorPath) {
|
|
27
|
-
const errorPath = this.getErrorFilePath(mirrorPath);
|
|
28
|
-
if (existsSync(errorPath)) {
|
|
29
|
-
const errorData = JSON.parse(readFileSync(errorPath, 'utf-8'));
|
|
30
|
-
unlinkSync(errorPath);
|
|
31
|
-
throw new Error(`Previous snapshot failed: ${errorData.message}\n` +
|
|
32
|
-
`Timestamp: ${errorData.timestamp}\n` +
|
|
33
|
-
`This error was from a background snapshot that failed. ` +
|
|
34
|
-
`The snapshot has been retried - if this error persists, check your configuration.`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
enqueue(options) {
|
|
38
|
-
this.queue.push(options);
|
|
39
|
-
this.log.info('Snapshot queued', options.mirrorPath);
|
|
40
|
-
void this.processQueue();
|
|
41
|
-
}
|
|
42
|
-
processQueue() {
|
|
43
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
if (this.isProcessing || this.queue.length === 0) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
this.isProcessing = true;
|
|
48
|
-
while (this.queue.length > 0) {
|
|
49
|
-
const options = this.queue.shift();
|
|
50
|
-
yield this.executeSnapshot(options);
|
|
51
|
-
}
|
|
52
|
-
this.isProcessing = false;
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
executeSnapshot(options) {
|
|
56
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
21
|
var _a;
|
|
58
22
|
const sourcePath = (_a = options.sourcePath) !== null && _a !== void 0 ? _a : process.cwd();
|
|
@@ -68,45 +32,25 @@ class Snapshotter {
|
|
|
68
32
|
const committed = yield gitCommit(mirrorPath, this.log);
|
|
69
33
|
if (!committed) {
|
|
70
34
|
this.log.info('No changes to commit', mirrorPath);
|
|
71
|
-
|
|
72
|
-
return;
|
|
35
|
+
return false;
|
|
73
36
|
}
|
|
74
37
|
this.log.info('Commit created, pushing', remote.url);
|
|
75
38
|
yield gitPush(mirrorPath, remote, this.log);
|
|
76
39
|
this.log.info('Push completed', remote.url);
|
|
77
|
-
|
|
40
|
+
return true;
|
|
78
41
|
}
|
|
79
42
|
catch (err) {
|
|
80
43
|
const message = err instanceof Error ? err.message : String(err);
|
|
81
|
-
this.log.error('Snapshot failed
|
|
82
|
-
|
|
44
|
+
this.log.error('Snapshot failed', message);
|
|
45
|
+
throw err;
|
|
83
46
|
}
|
|
84
47
|
});
|
|
85
48
|
}
|
|
86
|
-
persistError(mirrorPath, err) {
|
|
87
|
-
const snapshotterDir = path.join(mirrorPath, '.snapshotter');
|
|
88
|
-
mkdirSync(snapshotterDir, { recursive: true });
|
|
89
|
-
const errorPath = this.getErrorFilePath(mirrorPath);
|
|
90
|
-
const errorData = {
|
|
91
|
-
message: err instanceof Error ? err.message : String(err),
|
|
92
|
-
stack: err instanceof Error ? err.stack : undefined,
|
|
93
|
-
timestamp: new Date().toISOString(),
|
|
94
|
-
};
|
|
95
|
-
writeFileSync(errorPath, JSON.stringify(errorData, null, 2));
|
|
96
|
-
}
|
|
97
|
-
clearError(mirrorPath) {
|
|
98
|
-
const errorPath = this.getErrorFilePath(mirrorPath);
|
|
99
|
-
if (existsSync(errorPath)) {
|
|
100
|
-
unlinkSync(errorPath);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
getErrorFilePath(mirrorPath) {
|
|
104
|
-
return path.join(mirrorPath, '.snapshotter', ERROR_FILE_NAME);
|
|
105
|
-
}
|
|
106
49
|
}
|
|
107
|
-
const snapshotter = new Snapshotter();
|
|
108
50
|
export function snapshot(options) {
|
|
109
|
-
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
return new Snapshotter().snapshot(options);
|
|
53
|
+
});
|
|
110
54
|
}
|
|
111
55
|
function sortTestResults(testResults) {
|
|
112
56
|
const suites = [...testResults.suites].map((suite) => (Object.assign(Object.assign({}, suite), { tests: [...suite.tests].sort((left, right) => left.name.localeCompare(right.name)) })));
|
package/build/snapshot.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { SnapshotOptions } from './snapshotter.types.js';
|
|
2
|
-
export declare function snapshot(options: SnapshotOptions):
|
|
2
|
+
export declare function snapshot(options: SnapshotOptions): Promise<boolean>;
|
package/build/snapshot.js
CHANGED
|
@@ -9,45 +9,11 @@ const path_1 = __importDefault(require("path"));
|
|
|
9
9
|
const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
|
|
10
10
|
const git_js_1 = require("./git.js");
|
|
11
11
|
const sync_js_1 = require("./sync.js");
|
|
12
|
-
const ERROR_FILE_NAME = 'lastError.json';
|
|
13
12
|
class Snapshotter {
|
|
14
13
|
constructor() {
|
|
15
14
|
this.log = (0, spruce_skill_utils_1.buildLog)('Snapshotter');
|
|
16
|
-
this.queue = [];
|
|
17
|
-
this.isProcessing = false;
|
|
18
15
|
}
|
|
19
|
-
snapshot(options) {
|
|
20
|
-
this.checkForPreviousFailure(options.mirrorPath);
|
|
21
|
-
this.enqueue(options);
|
|
22
|
-
}
|
|
23
|
-
checkForPreviousFailure(mirrorPath) {
|
|
24
|
-
const errorPath = this.getErrorFilePath(mirrorPath);
|
|
25
|
-
if ((0, fs_1.existsSync)(errorPath)) {
|
|
26
|
-
const errorData = JSON.parse((0, fs_1.readFileSync)(errorPath, 'utf-8'));
|
|
27
|
-
(0, fs_1.unlinkSync)(errorPath);
|
|
28
|
-
throw new Error(`Previous snapshot failed: ${errorData.message}\n` +
|
|
29
|
-
`Timestamp: ${errorData.timestamp}\n` +
|
|
30
|
-
`This error was from a background snapshot that failed. ` +
|
|
31
|
-
`The snapshot has been retried - if this error persists, check your configuration.`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
enqueue(options) {
|
|
35
|
-
this.queue.push(options);
|
|
36
|
-
this.log.info('Snapshot queued', options.mirrorPath);
|
|
37
|
-
void this.processQueue();
|
|
38
|
-
}
|
|
39
|
-
async processQueue() {
|
|
40
|
-
if (this.isProcessing || this.queue.length === 0) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
this.isProcessing = true;
|
|
44
|
-
while (this.queue.length > 0) {
|
|
45
|
-
const options = this.queue.shift();
|
|
46
|
-
await this.executeSnapshot(options);
|
|
47
|
-
}
|
|
48
|
-
this.isProcessing = false;
|
|
49
|
-
}
|
|
50
|
-
async executeSnapshot(options) {
|
|
16
|
+
async snapshot(options) {
|
|
51
17
|
const sourcePath = options.sourcePath ?? process.cwd();
|
|
52
18
|
const { mirrorPath, testResults, remote } = options;
|
|
53
19
|
this.log.info('Starting snapshot', sourcePath, mirrorPath);
|
|
@@ -61,44 +27,22 @@ class Snapshotter {
|
|
|
61
27
|
const committed = await (0, git_js_1.gitCommit)(mirrorPath, this.log);
|
|
62
28
|
if (!committed) {
|
|
63
29
|
this.log.info('No changes to commit', mirrorPath);
|
|
64
|
-
|
|
65
|
-
return;
|
|
30
|
+
return false;
|
|
66
31
|
}
|
|
67
32
|
this.log.info('Commit created, pushing', remote.url);
|
|
68
33
|
await (0, git_js_1.gitPush)(mirrorPath, remote, this.log);
|
|
69
34
|
this.log.info('Push completed', remote.url);
|
|
70
|
-
|
|
35
|
+
return true;
|
|
71
36
|
}
|
|
72
37
|
catch (err) {
|
|
73
38
|
const message = err instanceof Error ? err.message : String(err);
|
|
74
|
-
this.log.error('Snapshot failed
|
|
75
|
-
|
|
39
|
+
this.log.error('Snapshot failed', message);
|
|
40
|
+
throw err;
|
|
76
41
|
}
|
|
77
42
|
}
|
|
78
|
-
persistError(mirrorPath, err) {
|
|
79
|
-
const snapshotterDir = path_1.default.join(mirrorPath, '.snapshotter');
|
|
80
|
-
(0, fs_1.mkdirSync)(snapshotterDir, { recursive: true });
|
|
81
|
-
const errorPath = this.getErrorFilePath(mirrorPath);
|
|
82
|
-
const errorData = {
|
|
83
|
-
message: err instanceof Error ? err.message : String(err),
|
|
84
|
-
stack: err instanceof Error ? err.stack : undefined,
|
|
85
|
-
timestamp: new Date().toISOString(),
|
|
86
|
-
};
|
|
87
|
-
(0, fs_1.writeFileSync)(errorPath, JSON.stringify(errorData, null, 2));
|
|
88
|
-
}
|
|
89
|
-
clearError(mirrorPath) {
|
|
90
|
-
const errorPath = this.getErrorFilePath(mirrorPath);
|
|
91
|
-
if ((0, fs_1.existsSync)(errorPath)) {
|
|
92
|
-
(0, fs_1.unlinkSync)(errorPath);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
getErrorFilePath(mirrorPath) {
|
|
96
|
-
return path_1.default.join(mirrorPath, '.snapshotter', ERROR_FILE_NAME);
|
|
97
|
-
}
|
|
98
43
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
snapshotter.snapshot(options);
|
|
44
|
+
async function snapshot(options) {
|
|
45
|
+
return new Snapshotter().snapshot(options);
|
|
102
46
|
}
|
|
103
47
|
function sortTestResults(testResults) {
|
|
104
48
|
const suites = [...testResults.suites].map((suite) => ({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regressionproof/snapshotter",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.5",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -94,5 +94,5 @@
|
|
|
94
94
|
"@sprucelabs/spruce-core-schemas": "^42.1.3",
|
|
95
95
|
"@sprucelabs/spruce-skill-utils": "^34.0.3"
|
|
96
96
|
},
|
|
97
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "352f13a4d1696f99936450a1ae88c195457b22ad"
|
|
98
98
|
}
|