Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests to fileDatesEqual function in fs module
- Loading branch information
Showing
2 changed files
with
70 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* @flow */ | ||
|
||
import {fileDatesEqual} from '../../src/util/fs.js'; | ||
|
||
describe('fileDatesEqual', () => { | ||
const realPlatform = process.platform; | ||
|
||
describe('!win32', () => { | ||
beforeAll(() => { | ||
process.platform = 'notWin32'; | ||
}); | ||
|
||
afterAll(() => { | ||
process.platform = realPlatform; | ||
}); | ||
|
||
test('Same dates equal', () => { | ||
expect(fileDatesEqual(new Date(1491393798834), new Date(1491393798834))).toBeTruthy(); | ||
expect(fileDatesEqual(new Date(1491393798000), new Date(1491393798000))).toBeTruthy(); | ||
}); | ||
|
||
test('Different dates differ', () => { | ||
expect(fileDatesEqual(new Date(1491393798834), new Date(1491393798835))).toBeFalsy(); | ||
expect(fileDatesEqual(new Date(1491393700834), new Date(1491393798834))).toBeFalsy(); | ||
expect(fileDatesEqual(new Date(1491393798000), new Date(1491393798835))).toBeFalsy(); | ||
}); | ||
}); | ||
describe('win32', () => { | ||
beforeAll(() => { | ||
process.platform = 'win32'; | ||
}); | ||
|
||
afterAll(() => { | ||
process.platform = realPlatform; | ||
}); | ||
|
||
test('Same dates equal', () => { | ||
expect(fileDatesEqual(new Date(1491393798834), new Date(1491393798834))).toBeTruthy(); | ||
}); | ||
|
||
test('Different dates differ', () => { | ||
expect(fileDatesEqual(new Date(1491393798834), new Date(1491393798835))).toBeFalsy(); | ||
expect(fileDatesEqual(new Date(1491393700834), new Date(1491393798834))).toBeFalsy(); | ||
}); | ||
|
||
test('Milliseconds are ignored when one date has zero milliseconds', () => { | ||
expect(fileDatesEqual(new Date(1491393798000), new Date(1491393798835))).toBeTruthy(); | ||
expect(fileDatesEqual(new Date(1491393798834), new Date(1491393798000))).toBeTruthy(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters