diff --git a/packages/core/src/api.js b/packages/core/src/api.js index f55d272c8..8fda5a1ef 100644 --- a/packages/core/src/api.js +++ b/packages/core/src/api.js @@ -102,8 +102,9 @@ export function createPercyServer(percy, port) { body = Buffer.isBuffer(body) ? body.toString() : body; if (cmd === 'reset') { - // the reset command will reset testing mode to its default options + // the reset command will reset testing mode and clear any logs percy.testing = {}; + logger.instance.messages.clear(); } else if (cmd === 'version') { // the version command will update the api version header for testing percy.testing.version = body; diff --git a/packages/core/test/api.test.js b/packages/core/test/api.test.js index 3e72e887a..2073ac5ee 100644 --- a/packages/core/test/api.test.js +++ b/packages/core/test/api.test.js @@ -257,6 +257,19 @@ describe('API Server', () => { expect(percy.dryRun).toBeTrue(); }); + it('enables a /test/snapshot endpoint that serves a simple html document', async () => { + await expectAsync(get('/test/snapshot')).toBeResolvedTo('
Snapshot Me!
'); + }); + + it('enables a /test/logs endpoint to return raw logs', async () => { + percy.log.info('foo bar from test'); + let { logs } = await get('/test/logs'); + + expect(logs).toEqual(jasmine.arrayContaining([ + jasmine.objectContaining({ message: 'foo bar from test' }) + ])); + }); + it('enables several /test/api endpoint commands', async () => { expect(percy.testing).toEqual({}); await post('/test/api/version', false); @@ -300,17 +313,22 @@ describe('API Server', () => { await expectAsync(req('/percy/healthcheck')).toBeRejected(); }); - it('enables a /test/logs endpoint to return raw logs', async () => { + it('can reset testing mode and clear logs via /test/reset', async () => { + // already tested up above + await post('/test/api/version', false); + await post('/test/api/disconnect', '/percy/healthcheck'); percy.log.info('foo bar from test'); - let { logs } = await get('/test/logs'); - expect(logs).toEqual(jasmine.arrayContaining([ - jasmine.objectContaining({ message: 'foo bar from test' }) - ])); - }); + // the actual endpoint to test + await post('/test/api/reset'); - it('enables a /test/snapshot endpoint that serves a simple html document', async () => { - await expectAsync(get('/test/snapshot')).toBeResolvedTo('Snapshot Me!
'); + // everything should work as usual + let { headers } = await req('/percy/healthcheck'); + expect(headers['x-percy-core-version']).toBeDefined(); + + // logs should be empty after reset + let { logs } = await get('/test/logs'); + expect(logs).toEqual([]); }); }); });