Skip to content

Commit

Permalink
add nanoseconds test
Browse files Browse the repository at this point in the history
  • Loading branch information
jayree committed Jun 20, 2023
1 parent ace42f9 commit e6c277a
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions __tests__/__fixtures__/test-GitIndex-timestamp.git/HEAD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ref: refs/heads/main
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
866e7d65b24e0cdb9d0630c0fb4c43f69f8dc420
1 change: 1 addition & 0 deletions __tests__/__fixtures__/test-GitIndex-timestamp/nano.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
validate nanoseconds
25 changes: 25 additions & 0 deletions __tests__/test-GitIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const path = require('path')

const { GitIndex, GitIndexManager } = require('isomorphic-git/internal-apis')

const { normalizeStats } = require('../src/utils/normalizeStats.js')

const { makeFixture } = require('./__helpers__/FixtureFS.js')

describe('GitIndex', () => {
Expand Down Expand Up @@ -128,4 +130,27 @@ describe('GitIndex', () => {
expect(ctimeSeconds).not.toBeNull()
expect(ctimeNanoseconds).not.toBeNull()
})

it('ensure nanoseconds of files are equal with index', async () => {
const { fs, gitdir } = await makeFixture('test-GitIndex-timestamp')
const buffer = await fs.read(path.join(gitdir, 'index'))
const index = await GitIndex.from(buffer)

const stats = normalizeStats(
await fs.lstat('__tests__/__fixtures__/test-GitIndex-timestamp/nano.txt')
)

expect(index.entriesMap.get('nano.txt').ctimeSeconds).toEqual(
stats.ctimeSeconds
)
expect(index.entriesMap.get('nano.txt').ctimeNanoseconds).toEqual(
stats.ctimeNanoseconds
)
expect(index.entriesMap.get('nano.txt').mtimeSeconds).toEqual(
stats.mtimeSeconds
)
expect(index.entriesMap.get('nano.txt').mtimeNanoseconds).toEqual(
stats.mtimeNanoseconds
)
})
})

0 comments on commit e6c277a

Please sign in to comment.