worker.on('close', () => { console.log( 'Tailor Overhead Metrics', JSON.stringify(histogram.printObj(), null, 2) ); fragment.kill(); worker.kill(); process.exit(0); });
async function validateHooks() { const browser = await puppeteer.launch(); const page = await browser.newPage(); try { // Forcing to wait till there are no networking events await page.goto('http://localhost:8080/index', { waitUntil: 'networkidle0' }); // Capture all the fragment related metrics const metrics = await page.evaluate(() => { // Serializing the outputs otherwise it will be undefined return [ JSON.stringify(performance.getEntriesByType('mark')), JSON.stringify(performance.getEntriesByType('measure')), JSON.stringify(window.TailorPipe.getEntries()) ]; }); const [mark, measure, entries] = [ JSON.parse(metrics[0]), JSON.parse(metrics[1]), JSON.parse(metrics[2]) ]; await analyseHooks(mark, measure, entries); await browser.close(); } catch (e) { console.error(e); process.exit(1); } }
describe('showHelp', () => { it('shows the help message and exits', () => { args.showHelp() expect(console.log).to.be.calledOnce() expect(process.exit).to.be.calledWith(0) }) })
client.set('key', 'value', () => { console.log('\nKEY SET') process.exit(0) })
describe('tasks', () => { beforeEach(() => { sinon.stub(utils, 'tasks') }) afterEach(() => { utils.tasks.restore() }) it('calls utils tasks method to list available tasks', () => { args.tasks() expect(utils.tasks).to.be.calledOnce() expect(process.exit).to.be.calledWith(0) }) })
describe('init', () => { beforeEach(() => { sandbox.stub(output, 'success') sandbox.stub(output, 'error') }) it('calls init method, outputs success and exits with 0 on success', () => { initStub = sinon.spy(() => Promise.resolve('foo')) return args.init() .then(() => { expect(output.success).to.be.calledWith('foo') expect(process.exit).to.be.calledWith(0) }) }) it('calls init method, outputs error and exits with 1 on failure', () => { initStub = sinon.spy(() => Promise.reject(new Error('foo'))) return args.init() .catch(() => { expect(output.error).to.be.calledWith(/foo/) expect(process.exit).to.be.calledWith(1) }) }) })
describe('cleanupAll', () => { beforeEach(() => { sandbox.stub(utils, 'cleanup', () => Promise.resolve()) }) it('call utils.cleanup with no arguments', () => { args.cleanupAll() expect(utils.cleanup).to.be.calledWith(true) }) it('exits code 0 on success', () => { return args.cleanupAll() .then(() => { expect(process.exit).to.have.been.calledOnce() expect(process.exit).to.have.been.calledWithExactly(0) }) }) it('exits code 1 on fail', () => { utils.cleanup.restore() sandbox.stub(utils, 'cleanup', () => Promise.reject()) return args.cleanupAll() .then(() => { expect(process.exit).to.have.been.calledOnce() expect(process.exit).to.have.been.calledWithExactly(1) }) }) })
describe('showVersion', () => { it('shows the installed version and exits', () => { args.showVersion() expect(console.log).to.be.calledWith(pkg.version) expect(process.exit).to.be.calledWith(0) }) })
describe('cleanupBC', () => { beforeEach(() => { sandbox.stub(utils, 'cleanup', () => Promise.resolve()) }) it('call utils.cleanup with no arguments', () => { return args.cleanupBC().then(() => { expect(utils.cleanup).to.be.calledOnce() }) }) it('exits code 0 on success', () => { return args.cleanupBC() .then(() => { expect(process.exit).to.have.been.calledOnce() expect(process.exit).to.have.been.calledWithExactly(0) }) }) it('exits code 1 on fail', () => { utils.cleanup.restore() sandbox.stub(utils, 'cleanup', () => Promise.reject()) return args.cleanupBC() .then(() => { expect(process.exit).to.have.been.calledOnce() expect(process.exit).to.have.been.calledWithExactly(1) }) }) })
client.on('error', () => { console.log('ERROR') process.exit(1) })