@regressionproof/snapshotter 0.5.1 → 0.5.3

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/git.js CHANGED
@@ -33,16 +33,43 @@ export function gitCommit(mirrorPath, log) {
33
33
  export function gitPush(mirrorPath, remote, log) {
34
34
  return __awaiter(this, void 0, void 0, function* () {
35
35
  const authedUrl = remote.url.replace('://', `://${remote.token}@`);
36
- try {
37
- yield execOrThrow(`git -C "${mirrorPath}" remote get-url origin`, log);
36
+ const originExists = yield remoteExists(mirrorPath, 'origin');
37
+ if (originExists) {
38
38
  yield execOrThrow(`git -C "${mirrorPath}" remote set-url origin "${authedUrl}"`);
39
39
  }
40
- catch (_a) {
40
+ else {
41
41
  yield execOrThrow(`git -C "${mirrorPath}" remote add origin "${authedUrl}"`);
42
42
  }
43
+ yield execOrThrow(`git -C "${mirrorPath}" fetch origin`, log);
44
+ if (yield hasRemoteHead(mirrorPath)) {
45
+ yield execOrThrow(`git -C "${mirrorPath}" rebase origin/HEAD`, log);
46
+ }
43
47
  yield execOrThrow(`git -C "${mirrorPath}" push -u origin HEAD`, log);
44
48
  });
45
49
  }
50
+ function remoteExists(mirrorPath, remoteName) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ try {
53
+ const { stdout } = yield execAsync(`git -C "${mirrorPath}" remote`);
54
+ const remotes = stdout.trim().split('\n');
55
+ return remotes.includes(remoteName);
56
+ }
57
+ catch (_a) {
58
+ return false;
59
+ }
60
+ });
61
+ }
62
+ function hasRemoteHead(mirrorPath) {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ try {
65
+ yield execAsync(`git -C "${mirrorPath}" symbolic-ref -q refs/remotes/origin/HEAD`);
66
+ return true;
67
+ }
68
+ catch (_a) {
69
+ return false;
70
+ }
71
+ });
72
+ }
46
73
  function execOrThrow(command, log) {
47
74
  return __awaiter(this, void 0, void 0, function* () {
48
75
  var _a, _b;
@@ -27,7 +27,7 @@ class Snapshotter {
27
27
  this.log.info('Files synced', mirrorPath);
28
28
  const snapshotterDir = path.join(mirrorPath, '.snapshotter');
29
29
  mkdirSync(snapshotterDir, { recursive: true });
30
- writeFileSync(path.join(snapshotterDir, 'testResults.json'), JSON.stringify(testResults, null, 2));
30
+ writeFileSync(path.join(snapshotterDir, 'testResults.json'), JSON.stringify(sortTestResults(testResults), null, 2));
31
31
  this.log.info('Test results saved', snapshotterDir);
32
32
  const committed = yield gitCommit(mirrorPath, this.log);
33
33
  if (!committed) {
@@ -52,3 +52,8 @@ export function snapshot(options) {
52
52
  return new Snapshotter().snapshot(options);
53
53
  });
54
54
  }
55
+ function sortTestResults(testResults) {
56
+ const suites = [...testResults.suites].map((suite) => (Object.assign(Object.assign({}, suite), { tests: [...suite.tests].sort((left, right) => left.name.localeCompare(right.name)) })));
57
+ suites.sort((left, right) => left.path.localeCompare(right.path));
58
+ return Object.assign(Object.assign({}, testResults), { suites });
59
+ }
package/build/git.js CHANGED
@@ -28,15 +28,38 @@ async function gitCommit(mirrorPath, log) {
28
28
  }
29
29
  async function gitPush(mirrorPath, remote, log) {
30
30
  const authedUrl = remote.url.replace('://', `://${remote.token}@`);
31
- try {
32
- await execOrThrow(`git -C "${mirrorPath}" remote get-url origin`, log);
31
+ const originExists = await remoteExists(mirrorPath, 'origin');
32
+ if (originExists) {
33
33
  await execOrThrow(`git -C "${mirrorPath}" remote set-url origin "${authedUrl}"`);
34
34
  }
35
- catch {
35
+ else {
36
36
  await execOrThrow(`git -C "${mirrorPath}" remote add origin "${authedUrl}"`);
37
37
  }
38
+ await execOrThrow(`git -C "${mirrorPath}" fetch origin`, log);
39
+ if (await hasRemoteHead(mirrorPath)) {
40
+ await execOrThrow(`git -C "${mirrorPath}" rebase origin/HEAD`, log);
41
+ }
38
42
  await execOrThrow(`git -C "${mirrorPath}" push -u origin HEAD`, log);
39
43
  }
44
+ async function remoteExists(mirrorPath, remoteName) {
45
+ try {
46
+ const { stdout } = await execAsync(`git -C "${mirrorPath}" remote`);
47
+ const remotes = stdout.trim().split('\n');
48
+ return remotes.includes(remoteName);
49
+ }
50
+ catch {
51
+ return false;
52
+ }
53
+ }
54
+ async function hasRemoteHead(mirrorPath) {
55
+ try {
56
+ await execAsync(`git -C "${mirrorPath}" symbolic-ref -q refs/remotes/origin/HEAD`);
57
+ return true;
58
+ }
59
+ catch {
60
+ return false;
61
+ }
62
+ }
40
63
  async function execOrThrow(command, log) {
41
64
  try {
42
65
  return await execAsync(command);
package/build/snapshot.js CHANGED
@@ -22,7 +22,7 @@ class Snapshotter {
22
22
  this.log.info('Files synced', mirrorPath);
23
23
  const snapshotterDir = path_1.default.join(mirrorPath, '.snapshotter');
24
24
  (0, fs_1.mkdirSync)(snapshotterDir, { recursive: true });
25
- (0, fs_1.writeFileSync)(path_1.default.join(snapshotterDir, 'testResults.json'), JSON.stringify(testResults, null, 2));
25
+ (0, fs_1.writeFileSync)(path_1.default.join(snapshotterDir, 'testResults.json'), JSON.stringify(sortTestResults(testResults), null, 2));
26
26
  this.log.info('Test results saved', snapshotterDir);
27
27
  const committed = await (0, git_js_1.gitCommit)(mirrorPath, this.log);
28
28
  if (!committed) {
@@ -44,3 +44,14 @@ class Snapshotter {
44
44
  async function snapshot(options) {
45
45
  return new Snapshotter().snapshot(options);
46
46
  }
47
+ function sortTestResults(testResults) {
48
+ const suites = [...testResults.suites].map((suite) => ({
49
+ ...suite,
50
+ tests: [...suite.tests].sort((left, right) => left.name.localeCompare(right.name)),
51
+ }));
52
+ suites.sort((left, right) => left.path.localeCompare(right.path));
53
+ return {
54
+ ...testResults,
55
+ suites,
56
+ };
57
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@regressionproof/snapshotter",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
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": "5628058a784a7bbf4f9f2c80ecd69a49c8be1088"
97
+ "gitHead": "d54c041a4d6b4cd88d35025ef1ee6d9acb6ad664"
98
98
  }