mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-06 10:20:09 +02:00
refactor(v2): simplify & faster last updated logic for docs (#1832)
* refactor(v2): simplify last updated logic for faster dev * Update packages/docusaurus-plugin-content-docs/src/__tests__/lastUpdate.test.ts * Update packages/docusaurus-plugin-content-docs/src/__tests__/lastUpdate.test.ts
This commit is contained in:
parent
3b143c2671
commit
48db8b8e09
6 changed files with 56 additions and 74 deletions
|
@ -7,7 +7,6 @@
|
|||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import shell from 'shelljs';
|
||||
|
||||
import lastUpdate from '../lastUpdate';
|
||||
|
||||
|
@ -45,43 +44,4 @@ describe('lastUpdate', () => {
|
|||
expect(lastUpdate(tempFilePath)).toBeNull();
|
||||
fs.unlinkSync(tempFilePath);
|
||||
});
|
||||
|
||||
test('test renaming and moving file', () => {
|
||||
const mock = jest.spyOn(shell, 'exec');
|
||||
mock
|
||||
.mockImplementationOnce(() => ({
|
||||
stdout:
|
||||
'1539502055, Yangshun Tay\n' +
|
||||
'\n' +
|
||||
' create mode 100644 v1/lib/core/__tests__/__fixtures__/.temp2\n',
|
||||
}))
|
||||
.mockImplementationOnce(() => ({
|
||||
stdout:
|
||||
'1539502056, Joel Marcey\n' +
|
||||
'\n' +
|
||||
' rename v1/lib/core/__tests__/__fixtures__/{.temp2 => test/.temp3} (100%)\n' +
|
||||
'1539502055, Yangshun Tay\n' +
|
||||
'\n' +
|
||||
' create mode 100644 v1/lib/core/__tests__/__fixtures__/.temp2\n',
|
||||
}));
|
||||
const tempFilePath2 = path.join(__dirname, '__fixtures__', '.temp2');
|
||||
const tempFilePath3 = path.join(
|
||||
__dirname,
|
||||
'__fixtures__',
|
||||
'test',
|
||||
'.temp3',
|
||||
);
|
||||
|
||||
// Create new file.
|
||||
const createData = lastUpdate(tempFilePath2);
|
||||
expect(createData.timestamp).not.toBeNull();
|
||||
|
||||
// Rename/move the file.
|
||||
const updateData = lastUpdate(tempFilePath3);
|
||||
expect(updateData.timestamp).not.toBeNull();
|
||||
// Should only consider file content change.
|
||||
expect(updateData.timestamp).toEqual(createData.timestamp);
|
||||
|
||||
mock.mockRestore();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue