diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 555f910..23ccfdf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: diff --git a/test/fixtures/getDiff.artifact.fixture.txt b/test/fixtures/getDiff.artifact.fixture.txt new file mode 100644 index 0000000..88e9a2c --- /dev/null +++ b/test/fixtures/getDiff.artifact.fixture.txt @@ -0,0 +1 @@ +DO NOT CHANGE THIS FILE diff --git a/test/fixtures/getDiff.fixture.txt b/test/fixtures/getDiff.fixture.txt new file mode 100644 index 0000000..a8e2bb2 --- /dev/null +++ b/test/fixtures/getDiff.fixture.txt @@ -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 diff --git a/test/index.fixture.yaml b/test/fixtures/index.fixture.yaml similarity index 100% rename from test/index.fixture.yaml rename to test/fixtures/index.fixture.yaml diff --git a/test/index.test.js b/test/index.test.js index ff1b005..5b365d2 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -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', () => { @@ -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); + }); +});