mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-11 16:17:25 +02:00
fix(content-docs): warn when files are not tracked (#6937)
* fix(docs): warn when files are not tracked * chore(devcontainer): use non-root user * test: fix jest in vscode * test(docs): improve existing test * chore(devcontainer): fix jest error on startup * chore: fix comments * chore: remove "probably" from error message
This commit is contained in:
parent
e8a2f66a0f
commit
e19a4e23e7
10 changed files with 77 additions and 13 deletions
|
@ -47,7 +47,7 @@ describe('getFileLastUpdate', () => {
|
|||
|
||||
it('non-existing file', async () => {
|
||||
const consoleMock = jest
|
||||
.spyOn(console, 'error')
|
||||
.spyOn(console, 'warn')
|
||||
.mockImplementation(() => {});
|
||||
const nonExistingFileName = '.nonExisting';
|
||||
const nonExistingFilePath = path.join(
|
||||
|
@ -65,10 +65,17 @@ describe('getFileLastUpdate', () => {
|
|||
consoleMock.mockRestore();
|
||||
});
|
||||
|
||||
it('temporary created file that has no git timestamp', async () => {
|
||||
it('temporary created file that is not tracked by git', async () => {
|
||||
const consoleMock = jest
|
||||
.spyOn(console, 'warn')
|
||||
.mockImplementation(() => {});
|
||||
const tempFilePath = path.join(__dirname, '__fixtures__', '.temp');
|
||||
await fs.writeFile(tempFilePath, 'Lorem ipsum :)');
|
||||
await expect(getFileLastUpdate(tempFilePath)).resolves.toBeNull();
|
||||
expect(consoleMock).toHaveBeenCalledTimes(1);
|
||||
expect(consoleMock).toHaveBeenLastCalledWith(
|
||||
expect.stringMatching(/not tracked by git./),
|
||||
);
|
||||
await fs.unlink(tempFilePath);
|
||||
});
|
||||
|
||||
|
|
|
@ -6,11 +6,16 @@
|
|||
*/
|
||||
|
||||
import logger from '@docusaurus/logger';
|
||||
import {getFileCommitDate, GitNotFoundError} from '@docusaurus/utils';
|
||||
import {
|
||||
getFileCommitDate,
|
||||
FileNotTrackedError,
|
||||
GitNotFoundError,
|
||||
} from '@docusaurus/utils';
|
||||
|
||||
type FileLastUpdateData = {timestamp?: number; author?: string};
|
||||
|
||||
let showedGitRequirementError = false;
|
||||
let showedFileNotTrackedError = false;
|
||||
|
||||
export async function getFileLastUpdate(
|
||||
filePath?: string,
|
||||
|
@ -31,8 +36,16 @@ export async function getFileLastUpdate(
|
|||
if (err instanceof GitNotFoundError && !showedGitRequirementError) {
|
||||
logger.warn('Sorry, the docs plugin last update options require Git.');
|
||||
showedGitRequirementError = true;
|
||||
} else if (
|
||||
err instanceof FileNotTrackedError &&
|
||||
!showedFileNotTrackedError
|
||||
) {
|
||||
logger.warn(
|
||||
'Cannot infer the update date for some files, as they are not tracked by git.',
|
||||
);
|
||||
showedFileNotTrackedError = true;
|
||||
} else {
|
||||
logger.error(err);
|
||||
logger.warn(err);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue