Skip to content

Commit

Permalink
rewrite failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
endiliey committed Aug 25, 2018
1 parent 5f41816 commit 0f20708
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions lib/core/__tests__/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,26 @@ describe('utils', () => {
});

test('getGitUpdateTime', () => {
const filepath =
'/home/shubham/Documents/Docusaurus/lib/core/__tests__/__fixtures__/test-doc.md';
expect(utils.getGitLastUpdated(filepath)).toBe('8/24/2018, 11:56:00 PM');
expect(utils.getGitLastUpdated(filepath + 'random')).toBeNull(); // Modify filepath to make it any invalid path
// existing test file in repository with git timestamp
const existingFilePath = path.join(__dirname, '__fixtures__', 'test.md');
expect(utils.getGitLastUpdated(existingFilePath)).toMatchInlineSnapshot(
`"8/25/2018, 11:42:20 AM"`
);

// non existing file
const nonExistingFilePath = path.join(
__dirname,
'__fixtures__',
'.nonExisting'
);
expect(utils.getGitLastUpdated(null)).toBeNull();
expect(utils.getGitLastUpdated(undefined)).toBeNull();
expect(utils.getGitLastUpdated(nonExistingFilePath)).toBeNull();

// temporary created file that has no git timestamp
const tempFilePath = path.join(__dirname, '__fixtures__', '.temp');
fs.writeFileSync(tempFilePath, 'Lorem ipsum :)');
expect(utils.getGitLastUpdated(tempFilePath)).toBeNull();
fs.unlinkSync(tempFilePath);
});
});

0 comments on commit 0f20708

Please sign in to comment.