From 0f20708a3cbcba9bdb26e4b6946ab708cab47428 Mon Sep 17 00:00:00 2001 From: endiliey Date: Sat, 25 Aug 2018 11:55:14 +0800 Subject: [PATCH] rewrite failing test --- lib/core/__tests__/utils.test.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/core/__tests__/utils.test.js b/lib/core/__tests__/utils.test.js index b1a6e4154a278..52ed7609db1f4 100644 --- a/lib/core/__tests__/utils.test.js +++ b/lib/core/__tests__/utils.test.js @@ -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); }); });