refactor: unify log format with new logger utility (#5994)

Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
This commit is contained in:
Joshua Chen 2021-12-21 00:24:59 +08:00 committed by GitHub
parent faef753730
commit 770418f8d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
66 changed files with 717 additions and 650 deletions

View file

@ -221,7 +221,11 @@ describe('docsVersion', () => {
getVersionsFilePath(simpleSiteDir, DEFAULT_PLUGIN_ID),
);
expect(versions).toEqual(['1.0.0']);
expect(consoleMock).toHaveBeenCalledWith('[docs]: version 1.0.0 created!');
expect(consoleMock).toHaveBeenCalledWith(
expect.stringMatching(
/.*\[SUCCESS\].* .*\[docs\].*: version .*1\.0\.0.* created!.*/,
),
);
copyMock.mockRestore();
writeMock.mockRestore();
@ -274,7 +278,11 @@ describe('docsVersion', () => {
getVersionsFilePath(versionedSiteDir, DEFAULT_PLUGIN_ID),
);
expect(versions).toEqual(['2.0.0', '1.0.1', '1.0.0', 'withSlugs']);
expect(consoleMock).toHaveBeenCalledWith('[docs]: version 2.0.0 created!');
expect(consoleMock).toHaveBeenCalledWith(
expect.stringMatching(
/.*\[SUCCESS\].* .*\[docs\].*: version .*2\.0\.0.* created!.*/,
),
);
copyMock.mockRestore();
writeMock.mockRestore();
@ -326,7 +334,9 @@ describe('docsVersion', () => {
);
expect(versions).toEqual(['2.0.0', '1.0.0']);
expect(consoleMock).toHaveBeenCalledWith(
'[community]: version 2.0.0 created!',
expect.stringMatching(
/.*\[SUCCESS\].* .*\[community\].*: version .*2.0.0.* created!.*/,
),
);
copyMock.mockRestore();

View file

@ -29,8 +29,7 @@ describe('lastUpdate', () => {
});
test('non-existing file', async () => {
const consoleMock = jest.spyOn(console, 'error');
consoleMock.mockImplementation();
const consoleMock = jest.spyOn(console, 'error').mockImplementation();
const nonExistingFileName = '.nonExisting';
const nonExistingFilePath = path.join(
__dirname,
@ -39,8 +38,8 @@ describe('lastUpdate', () => {
);
expect(await getFileLastUpdate(nonExistingFilePath)).toBeNull();
expect(consoleMock).toHaveBeenCalledTimes(1);
expect(consoleMock.mock.calls[0][0].message).toContain(
' with exit code 128',
expect(consoleMock).toHaveBeenLastCalledWith(
expect.stringMatching(/with exit code 128/),
);
expect(await getFileLastUpdate(null)).toBeNull();
expect(await getFileLastUpdate(undefined)).toBeNull();
@ -60,7 +59,9 @@ describe('lastUpdate', () => {
const lastUpdateData = await getFileLastUpdate(existingFilePath);
expect(lastUpdateData).toBeNull();
expect(consoleMock).toHaveBeenLastCalledWith(
'Sorry, the docs plugin last update options require Git.',
expect.stringMatching(
/.*\[WARNING\].* Sorry, the docs plugin last update options require Git\..*/,
),
);
consoleMock.mockRestore();