Skip to content

Commit

Permalink
fix: restore from history (#148)
Browse files Browse the repository at this point in the history
fix: restore from history

chore: bump gha coverage version

test: migrate from ava to tap
<!-- GITHUB_RELEASE PR BODY: canary-version -->
<details>
  <summary>📦 Published PR as canary version: <code>Canary Versions</code></summary>
  <br />

  ✨ Test out this PR locally via:
  
  ```bash
  npm install @dotinc/[email protected]
  npm install @dotinc/[email protected]
  # or 
  yarn add @dotinc/[email protected]
  yarn add @dotinc/[email protected]
  ```
</details>
<!-- GITHUB_RELEASE PR BODY: canary-version -->
  • Loading branch information
nadilas authored Feb 23, 2024
2 parents 30718bd + f644c52 commit 1dd4066
Show file tree
Hide file tree
Showing 14 changed files with 13,967 additions and 8,130 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- run: npm ci
- run: npm run test

- uses: codecov/codecov-action@v2
- uses: codecov/codecov-action@v3
with:
# token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
fail_ci_if_error: true # optional (default = false)
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ yarn-error.log*

# jetbrains
.idea
packages/ogre/.tap
21,500 changes: 13,629 additions & 7,871 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
},
"license": "MIT",
"devDependencies": {
"@auto-it/conventional-commits": "^10.34.1",
"@auto-it/microsoft-teams": "^10.37.1",
"@auto-it/npm": "^10.34.1",
"@auto-it/released": "^10.37.1",
"auto": "^10.34.1",
"@auto-it/conventional-commits": "^11.0.7",
"@auto-it/microsoft-teams": "^11.0.7",
"@auto-it/npm": "^11.0.7",
"@auto-it/released": "^11.0.7",
"auto": "^11.0.7",
"dotenv-cli": "^7.3.0",
"prettier": "^3.2.5",
"turbo": "latest"
Expand Down
18 changes: 2 additions & 16 deletions packages/ogre/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,9 @@
"types": "lib/index.d.ts",
"scripts": {
"build": "tsc -p tsconfig.build.json",
"test": "nyc --reporter=lcov ava",
"test.watch": "ava --watch",
"test": "nyc --reporter=lcov tap --coverage-report=none --allow-incomplete-coverage",
"coverage:html": "nyc report --reporter=html"
},
"ava": {
"timeout": "60s",
"files": [
"./src/**/*.test.ts"
],
"extensions": [
"ts"
],
"require": [
"ts-node/register"
]
},
"author": "János Veres @nadilas",
"license": "MIT",
"dependencies": {
Expand All @@ -36,10 +23,9 @@
"fflate": "^0.8.2"
},
"devDependencies": {
"@ava/typescript": "^3.0.1",
"tap": "^18.7.0",
"@types/node": "^17.0.45",
"@types/uuid": "^8.3.4",
"ava": "^4.3.3",
"nyc": "^15.1.0",
"ts-node": "^10.8.1",
"typescript": "^4.7.4",
Expand Down
34 changes: 17 additions & 17 deletions packages/ogre/src/branch.test.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
import test from "ava";
import { test } from "tap";
import { getBaseline, sumChanges, testAuthor } from "./test.utils";

test("current branch on empty repo is HEAD", async (t) => {
const [repo] = await getBaseline();

t.is(repo.branch(), "HEAD", "invalid current branch");
t.equal(repo.branch(), "HEAD", "invalid current branch");
});

test("first commit goes onto default 'main' branch", async (t) => {
const [repo] = await getBaseline();
repo.data.name = "new name";
await repo.commit("initial commit", testAuthor);

t.is(repo.branch(), "main", "invalid current branch");
t.is(repo.head(), "refs/heads/main", "invalid HEAD");
t.equal(repo.branch(), "main", "invalid current branch");
t.equal(repo.head(), "refs/heads/main", "invalid HEAD");
});

test("fails to create a branch with empty repo", async (t) => {
const [repo] = await getBaseline();
let history = repo.getHistory();
t.is(history.commits.length, 0, "incorrect # of commits");
t.is(
t.equal(history.commits.length, 0, "incorrect # of commits");
t.equal(
sumChanges(history?.commits),
0,
"new branch w/ incorrect # of changelog entries"
"new branch w/ incorrect # of changelog entries",
);

t.throws(
() => {
// cannot point new branch to nothing on empty repo
repo.createBranch("new_feature");
},
{ message: "fatal: not a valid object name: 'main'" }
{ message: "fatal: not a valid object name: 'main'" },
);
});

test("checkout new branch with empty repo", async (t) => {
const [repo] = await getBaseline();

repo.checkout("new_feature", true);
t.is(
t.equal(
repo.head(),
"refs/heads/new_feature",
"HEAD did not move to new branch"
"HEAD did not move to new branch",
);
t.is(
t.equal(
repo.ref("/refs/heads/main"),
undefined,
"main should not be pointing to anything"
"main should not be pointing to anything",
);
t.is(
t.equal(
repo.ref("refs/heads/new_feature"),
undefined,
"new_feature should not be pointing to anything"
"new_feature should not be pointing to anything",
);
});

Expand All @@ -61,8 +61,8 @@ test("creating a valid branch on a baseline", async (t) => {
repo.data.name = "new name";
const commit = await repo.commit("simple change", testAuthor);
const ref = repo.createBranch("new_feature");
t.is(ref, "refs/heads/new_feature", "invalid branch ref created");
t.is(repo.ref(ref), commit, "new branch is pointing to wrong commit");
t.equal(ref, "refs/heads/new_feature", "invalid branch ref created");
t.equal(repo.ref(ref), commit, "new branch is pointing to wrong commit");
});

test("cannot create new branch with invalid name", async (t) => {
Expand All @@ -73,7 +73,7 @@ test("cannot create new branch with invalid name", async (t) => {
() => {
repo.createBranch(name);
},
{ message: "invalid ref name" }
{ message: "invalid ref name" },
);
}
});
55 changes: 29 additions & 26 deletions packages/ogre/src/checkout.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import test from "ava";
import { test } from "tap";
import {
addOneStep,
ComplexObject,
Expand All @@ -21,14 +21,14 @@ test("checkout prev commit", async (t) => {
repo.checkout(headerDataHash);
const head = repo.head();
const history = repo.getHistory();
t.is(sumChanges(history.commits), 3, `incorrect # of changelog entries`);
t.is(history.commits.length, 1, "incorrect # of commits");
t.is(head, headerDataHash, `points to wrong commit`);
t.is(repo.branch(), "HEAD", "repo is not in detached state");
t.deepEqual(
t.equal(sumChanges(history.commits), 3, `incorrect # of changelog entries`);
t.equal(history.commits.length, 1, "incorrect # of commits");
t.equal(head, headerDataHash, `points to wrong commit`);
t.equal(repo.branch(), "HEAD", "repo is not in detached state");
t.equal(
obj.nested.length,
0,
`has a nested object when it shouldn't: ${JSON.stringify(obj)}`
`has a nested object when it shouldn't: ${JSON.stringify(obj)}`,
);
});

Expand All @@ -39,7 +39,7 @@ test("checkout new branch with simple name", async (t) => {

const ref = repo.createBranch("new_feature");
repo.checkout("new_feature");
t.is(repo.head(), ref, "HEAD is not moved to target branch");
t.equal(repo.head(), ref, "HEAD is not moved to target branch");
});

test("checkout new branch with full ref name", async (t) => {
Expand All @@ -49,7 +49,7 @@ test("checkout new branch with full ref name", async (t) => {

const ref = repo.createBranch("new_feature");
repo.checkout(ref);
t.is(repo.head(), ref, "HEAD is not moved to target branch");
t.equal(repo.head(), ref, "HEAD is not moved to target branch");
});

test("checkout commit which has two refs pointing leaves HEAD detached", async (t) => {
Expand All @@ -59,14 +59,14 @@ test("checkout commit which has two refs pointing leaves HEAD detached", async (

repo.createBranch("new_feature");
repo.checkout(commit);
t.is(repo.ref("refs/heads/main"), commit, "main does not point to commit");
t.is(
t.equal(repo.ref("refs/heads/main"), commit, "main does not point to commit");
t.equal(
repo.ref("refs/heads/new_feature"),
commit,
"new_feature does not point to commit"
"new_feature does not point to commit",
);
t.is(repo.branch(), "HEAD", "HEAD is not detached at commit");
t.is(repo.head(), commit, "HEAD is not pointing to commit");
t.equal(repo.branch(), "HEAD", "HEAD is not detached at commit");
t.equal(repo.head(), commit, "HEAD is not pointing to commit");
});

test("checkout new branch moves head to new branch", async (t) => {
Expand All @@ -76,19 +76,19 @@ test("checkout new branch moves head to new branch", async (t) => {

const ref = repo.createBranch("new_feature");
repo.checkout("new_feature");
t.is(repo.head(), ref, "HEAD is not moved to target branch");
t.equal(repo.head(), ref, "HEAD is not moved to target branch");
});

test("checkout and create new branch on empty main", async (t) => {
const [repo] = await getBaseline();

repo.checkout("new_feature", true);
t.is(
t.equal(
repo.head(),
"refs/heads/new_feature",
"HEAD should point to empty branch"
"HEAD should point to empty branch",
);
t.is(repo.branch(), "HEAD", "branch still should be empty");
t.equal(repo.branch(), "HEAD", "branch still should be empty");
});

test("checkout and create new branch with at least 1 commit", async (t) => {
Expand All @@ -97,29 +97,32 @@ test("checkout and create new branch with at least 1 commit", async (t) => {
const commit = await repo.commit("simple change", testAuthor);

repo.checkout("new_feature", true);
t.is(
t.equal(
repo.head(),
"refs/heads/new_feature",
"HEAD should point to new branch"
"HEAD should point to new branch",
);
t.is(
t.equal(
repo.ref("refs/heads/new_feature"),
commit,
"branch is not pointing to last HEAD commit"
"branch is not pointing to last HEAD commit",
);
});

test("replacing default branch on empty master removes main", async (t) => {
const repo = new Repository(new ComplexObject(), {});
const cx: ComplexObject = {
nested: [],
};
const repo = new Repository(cx, {});

// replacing default main branch by moving HEAD to new branch
// is OK even on empty repo
repo.checkout("new_feature", true);
const history = repo.getHistory();
t.is(
t.equal(
sumChanges(history?.commits),
0,
"new branch w/ incorrect # of changelog entries"
"new branch w/ incorrect # of changelog entries",
);

repo.data.name = "name changed";
Expand All @@ -130,6 +133,6 @@ test("replacing default branch on empty master removes main", async (t) => {
() => {
repo.checkout("main");
},
{ message: `pathspec 'main' did not match any known refs` }
{ message: `pathspec 'main' did not match any known refs` },
);
});
Loading

0 comments on commit 1dd4066

Please sign in to comment.