ci(docs-infra): improve preview-server logging
This commit is contained in:

committed by
Miško Hevery

parent
f7b041c7f5
commit
e5018c4d77
@ -14,13 +14,17 @@ const EXISTING_DOWNLOADS = [
|
||||
'downloads/20-1234567-build.zip',
|
||||
];
|
||||
const OPEN_PRS = [10, 40];
|
||||
const ANY_DATE = jasmine.any(String);
|
||||
|
||||
// Tests
|
||||
describe('BuildCleaner', () => {
|
||||
let cleaner: BuildCleaner;
|
||||
|
||||
beforeEach(() => cleaner = new BuildCleaner('/foo/bar', 'baz', 'qux', '12345', 'downloads', 'build.zip'));
|
||||
|
||||
beforeEach(() => {
|
||||
spyOn(console, 'error');
|
||||
spyOn(console, 'log');
|
||||
cleaner = new BuildCleaner('/foo/bar', 'baz', 'qux', '12345', 'downloads', 'build.zip');
|
||||
});
|
||||
|
||||
describe('constructor()', () => {
|
||||
|
||||
@ -78,7 +82,6 @@ describe('BuildCleaner', () => {
|
||||
cleanerRemoveUnnecessaryBuildsSpy = spyOn(cleaner, 'removeUnnecessaryBuilds');
|
||||
cleanerRemoveUnnecessaryDownloadsSpy = spyOn(cleaner, 'removeUnnecessaryDownloads');
|
||||
|
||||
spyOn(console, 'log');
|
||||
});
|
||||
|
||||
|
||||
@ -276,7 +279,7 @@ describe('BuildCleaner', () => {
|
||||
|
||||
it('should log the number of open PRs', () => {
|
||||
promise.then(prNumbers => {
|
||||
expect(console.log).toHaveBeenCalledWith(`Open pull requests: ${prNumbers}`);
|
||||
expect(console.log).toHaveBeenCalledWith(ANY_DATE, 'BuildCleaner: ', `Open pull requests: ${prNumbers}`);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -373,7 +376,6 @@ describe('BuildCleaner', () => {
|
||||
|
||||
|
||||
it('should catch errors and log them', () => {
|
||||
const consoleErrorSpy = spyOn(console, 'error');
|
||||
shellRmSpy.and.callFake(() => {
|
||||
// tslint:disable-next-line: no-string-throw
|
||||
throw 'Test';
|
||||
@ -381,9 +383,8 @@ describe('BuildCleaner', () => {
|
||||
|
||||
cleaner.removeDir('/foo/bar');
|
||||
|
||||
expect(consoleErrorSpy).toHaveBeenCalled();
|
||||
expect(consoleErrorSpy.calls.argsFor(0)[0]).toContain('Unable to remove \'/foo/bar\'');
|
||||
expect(consoleErrorSpy.calls.argsFor(0)[1]).toBe('Test');
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
jasmine.any(String), 'BuildCleaner: ', 'ERROR: Unable to remove \'/foo/bar\' due to:', 'Test');
|
||||
});
|
||||
|
||||
});
|
||||
@ -393,7 +394,6 @@ describe('BuildCleaner', () => {
|
||||
let cleanerRemoveDirSpy: jasmine.Spy;
|
||||
|
||||
beforeEach(() => {
|
||||
spyOn(console, 'log');
|
||||
cleanerRemoveDirSpy = spyOn(cleaner, 'removeDir');
|
||||
});
|
||||
|
||||
@ -401,8 +401,8 @@ describe('BuildCleaner', () => {
|
||||
it('should log the number of existing builds and builds to be removed', () => {
|
||||
cleaner.removeUnnecessaryBuilds([1, 2, 3], [3, 4, 5, 6]);
|
||||
|
||||
expect(console.log).toHaveBeenCalledWith('Existing builds: 3');
|
||||
expect(console.log).toHaveBeenCalledWith('Removing 2 build(s): 1, 2');
|
||||
expect(console.log).toHaveBeenCalledWith(ANY_DATE, 'BuildCleaner: ', 'Existing builds: 3');
|
||||
expect(console.log).toHaveBeenCalledWith(ANY_DATE, 'BuildCleaner: ', 'Removing 2 build(s): 1, 2');
|
||||
});
|
||||
|
||||
|
||||
@ -455,7 +455,6 @@ describe('BuildCleaner', () => {
|
||||
|
||||
describe('removeUnnecessaryDownloads()', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(console, 'log');
|
||||
spyOn(shell, 'rm');
|
||||
});
|
||||
|
||||
@ -471,8 +470,8 @@ describe('BuildCleaner', () => {
|
||||
it('should log the number of existing builds and builds to be removed', () => {
|
||||
cleaner.removeUnnecessaryDownloads(EXISTING_DOWNLOADS, OPEN_PRS);
|
||||
|
||||
expect(console.log).toHaveBeenCalledWith('Existing downloads: 4');
|
||||
expect(console.log).toHaveBeenCalledWith(
|
||||
expect(console.log).toHaveBeenCalledWith(ANY_DATE, 'BuildCleaner: ', 'Existing downloads: 4');
|
||||
expect(console.log).toHaveBeenCalledWith(ANY_DATE, 'BuildCleaner: ',
|
||||
'Removing 2 download(s): downloads/20-ABCDEF0-build.zip, downloads/20-1234567-build.zip');
|
||||
});
|
||||
});
|
||||
|
@ -511,7 +511,8 @@ describe('BuildCreator', () => {
|
||||
|
||||
it('should log (as a warning) any stderr output if extracting succeeded', done => {
|
||||
(bc as any).extractArchive('foo', 'bar').
|
||||
then(() => expect(consoleWarnSpy).toHaveBeenCalledWith('This is stderr')).
|
||||
then(() => expect(consoleWarnSpy)
|
||||
.toHaveBeenCalledWith(jasmine.any(String), 'BuildCreator: ', 'This is stderr')).
|
||||
then(done);
|
||||
|
||||
cpExecCbs[0](null, 'This is stdout', 'This is stderr');
|
||||
|
@ -43,6 +43,11 @@ describe('uploadServerFactory', () => {
|
||||
const createUploadServer = (partialConfig: Partial<UploadServerConfig> = {}) =>
|
||||
UploadServerFactory.create({...defaultConfig, ...partialConfig});
|
||||
|
||||
beforeEach(() => {
|
||||
spyOn(console, 'error');
|
||||
spyOn(console, 'info');
|
||||
spyOn(console, 'log');
|
||||
});
|
||||
|
||||
describe('create()', () => {
|
||||
let usfCreateMiddlewareSpy: jasmine.Spy;
|
||||
@ -132,14 +137,14 @@ describe('uploadServerFactory', () => {
|
||||
|
||||
|
||||
it('should log the server address info on \'listening\'', () => {
|
||||
const consoleInfoSpy = spyOn(console, 'info');
|
||||
const server = createUploadServer();
|
||||
server.address = () => ({address: 'foo', family: '', port: 1337});
|
||||
|
||||
expect(consoleInfoSpy).not.toHaveBeenCalled();
|
||||
expect(console.info).not.toHaveBeenCalled();
|
||||
|
||||
server.emit('listening');
|
||||
expect(consoleInfoSpy).toHaveBeenCalledWith('Up and running (and listening on foo:1337)...');
|
||||
expect(console.info).toHaveBeenCalledWith(
|
||||
jasmine.any(String), 'UploadServer: ', 'Up and running (and listening on foo:1337)...');
|
||||
});
|
||||
|
||||
});
|
||||
@ -254,8 +259,6 @@ describe('uploadServerFactory', () => {
|
||||
const middleware = UploadServerFactory.createMiddleware(buildRetriever, buildVerifier, buildCreator,
|
||||
defaultConfig);
|
||||
agent = supertest.agent(middleware);
|
||||
|
||||
spyOn(console, 'error');
|
||||
});
|
||||
|
||||
describe('GET /health-check', () => {
|
||||
@ -364,12 +367,11 @@ describe('uploadServerFactory', () => {
|
||||
});
|
||||
|
||||
it('should respond with 204 if the build did not affect any significant files', async () => {
|
||||
spyOn(console, 'log');
|
||||
AFFECTS_SIGNIFICANT_FILES = false;
|
||||
await agent.post(URL).send(BASIC_PAYLOAD).expect(204);
|
||||
expect(getGithubInfoSpy).toHaveBeenCalledWith(BUILD_NUM);
|
||||
expect(getSignificantFilesChangedSpy).toHaveBeenCalledWith(PR, jasmine.any(RegExp));
|
||||
expect(console.log).toHaveBeenCalledWith(
|
||||
expect(console.log).toHaveBeenCalledWith(jasmine.any(String), 'UploadServer: ',
|
||||
'PR:777, Build:12345 - Skipping preview processing because this PR did not touch any significant files.');
|
||||
expect(downloadBuildArtifactSpy).not.toHaveBeenCalled();
|
||||
expect(getPrIsTrustedSpy).not.toHaveBeenCalled();
|
||||
|
@ -16,20 +16,14 @@ describe('upload-server/utils', () => {
|
||||
|
||||
it('should set the status on the response', () => {
|
||||
respondWithError(response, new UploadError(505, 'TEST MESSAGE'));
|
||||
|
||||
expect(statusSpy).toHaveBeenCalledWith(505);
|
||||
expect(endSpy).toHaveBeenCalledWith('TEST MESSAGE', jasmine.any(Function));
|
||||
expect(console.error).toHaveBeenCalledWith('Upload error: 505 - HTTP Version Not Supported');
|
||||
expect(console.error).toHaveBeenCalledWith('TEST MESSAGE');
|
||||
});
|
||||
|
||||
it('should convert non-UploadError errors to 500 UploadErrors', () => {
|
||||
respondWithError(response, new Error('OTHER MESSAGE'));
|
||||
|
||||
expect(statusSpy).toHaveBeenCalledWith(500);
|
||||
expect(endSpy).toHaveBeenCalledWith('OTHER MESSAGE', jasmine.any(Function));
|
||||
expect(console.error).toHaveBeenCalledWith('Upload error: 500 - Internal Server Error');
|
||||
expect(console.error).toHaveBeenCalledWith('OTHER MESSAGE');
|
||||
});
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user