Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dugite tests #4

Merged
merged 6 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
steps:
- name: Checkout the latest code
uses: actions/checkout@v3
with:
fetch-depth: 0
# Make sure we get all commits, since testing uses the local git info
- name: Setup Node
uses: actions/setup-node@v3
with:
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/getDiff.artifact.fixture.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DO NOT CHANGE THIS FILE
7 changes: 7 additions & 0 deletions test/fixtures/getDiff.fixture.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
diff --git a/test/fixtures/getDiff.artifact.fixture.txt b/test/fixtures/getDiff.artifact.fixture.txt
index 6b08561..88e9a2c 100644
--- a/test/fixtures/getDiff.artifact.fixture.txt
+++ b/test/fixtures/getDiff.artifact.fixture.txt
@@ -1 +1 @@
-Never Change this File
+DO NOT CHANGE THIS FILE
File renamed without changes.
13 changes: 11 additions & 2 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { deepEqual } = require("assert");
const { translateLinesGivenDiff, diffPositionToFilePosition } = require("../src/index.js");
const { translateLinesGivenDiff, diffPositionToFilePosition, getDiff } = require("../src/index.js");
const { readFileSync } = require("fs");

const fixture = require('js-yaml').safeLoad(readFileSync(require.resolve('./index.fixture.yaml')))
const fixture = require('js-yaml').safeLoad(readFileSync(require.resolve('./fixtures/index.fixture.yaml')))

describe('translateLinesGivenDiff', () => {
it('translates rows after applying a diff', () => {
Expand Down Expand Up @@ -64,3 +64,12 @@ describe('diffPositionToFilePosition', () => {
})
})
})

describe('getDiff', () => {
it('returns accurate getDiff', async () => {
// Use this repo's git info, checking the artifact fixture file
const diff = await getDiff('./', 'test/fixtures/getDiff.artifact.fixture.txt', '286ccffe38885e731ed4894989dbc6d2c0f85f72');
const diffFixture = readFileSync(require.resolve('./fixtures/getDiff.fixture.txt'), "utf8");
deepEqual(diff, diffFixture);
});
});