it('triggers `response(statusCode, headers)` when received headers', done => { nock('https://fragment') .get('/') .reply(200, 'OK', RESPONSE_HEADERS); const fragment = new Fragment(getOptions(TAG)); fragment.on('response', (statusCode, headers) => { assert.equal(statusCode, 200); assert.deepEqual(headers, RESPONSE_HEADERS); done(); }); fragment.fetch(REQUEST); });
describe('filter-headers', () => { const headers = { 'please-kill-me': '0', 'accept-language': '1', referer: '2', 'user-agent': '3', 'x-request-uri': '/example', 'x-request-host': 'localhost' }; it('keeps only certain headers', () => { const after = { 'accept-language': '1', referer: '2', 'user-agent': '3', 'x-request-uri': '/example', 'x-request-host': 'localhost' }; assert.deepEqual(filterHeaders({}, { headers }), after); }); it('removes headers if fragment is public', () => { assert.deepEqual(filterHeaders({ public: true }, { headers }), {}); }); });
it('emits `response(request, statusCode, headers)` event', done => { const onResponse = sinon.spy(); mockTemplate.returns('<html>'); tailor.on('response', onResponse); http.get('http://localhost:8080/template', response => { response.resume(); response.on('end', () => { const request = onResponse.args[0][0]; const statusCode = onResponse.args[0][1]; const headers = onResponse.args[0][2]; assert.equal(request.url, '/template'); assert.equal(statusCode, 200); assert.deepEqual(headers, { 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Content-Type': 'text/html', Pragma: 'no-cache' }); assert.equal(onResponse.callCount, 1); done(); }); }); });
it('should return headers from primary fragment', done => { const cookie = 'zalando.guid=6cc4da81; path=/; httponly'; nock('https://fragment') .get('/1') .reply(200, 'hello', { 'Set-Cookie': 'wrong' }) .get('/2') .reply(200, 'world', { 'Set-Cookie': cookie }) .get('/3') .reply(201); mockTemplate.returns( '<fragment src="https://fragment/1"></fragment>' + '<fragment src="https://fragment/2" primary></fragment>' + '<fragment src="https://fragment/3"></fragment>' ); getResponse('http://localhost:8080/test') .then(response => { assert.equal(response.statusCode, 200); assert.deepEqual(response.headers['set-cookie'], [cookie]); }) .then(done, done); });
describe('Fragment', () => { it('computed attributes are correctly initiliazed', () => { const attributes = { id: 'foo', src: 'https://fragment', 'fallback-src': 'https://fragment-fallback', async: true, timeout: '4000', custom: 'bar' }; const expected = { id: attributes.id, url: attributes.src, ['fallback-src']: attributes['fallback-src'], fallbackUrl: attributes['fallback-src'], async: attributes.async, timeout: 4000, primary: false, public: false, custom: 'bar' }; const tag = { attributes }; const fragment = new Fragment(getOptions(tag)); const fattributes = fragment.attributes; assert.deepEqual(fattributes, expected); }); });
const { tags } = traceResults(); assert.equal(tags.length, 1); assert.deepEqual(tags[0], { 'http.url': '/test', 'span.kind': 'server' .then(() => { const { tags, logs } = traceResults(); assert.deepEqual(tags[0], { 'http.url': '/error', 'span.kind': 'server', assert.deepEqual(tags[1], { error: true, primary: true, .then(() => { const { tags } = traceResults(); assert.deepEqual(tags[1], { 'span.kind': 'client', [Tags.HTTP_URL]: 'https://fragment/1',
const tag = mockHandleTag.args[0][1]; assert.equal(request.url, '/template'); assert.deepEqual(tag, { name: 'x-tag', attributes: {
'<!DOCTYPE html><!--comment--><html><head>' ); assert.deepEqual(serializedList[1], { placeholder: 'pipe' }); }); const template = '<x-tag></x-tag>'; const serializedList = getSerializer(template).serialize(); assert.deepEqual(serializedList[1], { attributes: {}, name: 'x-tag' }); assert.deepEqual(serializedList[2], { closingTag: 'x-tag' }); }); const template = '<x-tag foo="bar"><div>hello</div></x-tag>'; const serializedList = getSerializer(template).serialize(); assert.deepEqual(serializedList[1], { attributes: { foo: 'bar' }, name: 'x-tag' }); assert.equal(serializedList[2], '<div>hello</div>'); assert.deepEqual(serializedList[3], { closingTag: 'x-tag' }); }); '<html><head></head><body>' ); assert.deepEqual(serializedList[3], { placeholder: 'async' }); assert.equal(serializedList[4].toString().trim(), '</body></html>'); }); '<html><head><script></script></head><body>' );
const stream = new StringifierStream(tag => { if (tag && tag.name) { assert.deepEqual(tag.attributes, { title: 'mock' }); return st;
const test = () => { const histogram = build(); const series = Array.from({length: 99}).map(() => 100); series.push(1012); series.forEach(s => histogram.recordValue(s)); assert.deepEqual(histogramMockData, { median: histogram.getValueAtPercentile(0.5), p90: histogram.getValueAtPercentile(0.90), p99: histogram.getValueAtPercentile(0.99), p999: histogram.getValueAtPercentile(0.999), }, "Histogram percentile calculation is incorrect") }
const test = () => { // test data setup const series = Array.from({length: 99}).map(() => 100); series.push(1012); // test createFrequency const resultFrequency = series.reduce(calculateFrequency, []); assert.deepEqual(resultFrequency, frequencyDistribution, "Frequency distribution is wrong") // test calculatePercentile const resultPercentileDistribution = resultFrequency.reduce( calculatePercentile(series), {cumulativeFrequency: 0, percentiles: []} ) assert.deepEqual(resultPercentileDistribution, percentileDistribution, "Percentile Distribution is wrong") // test getValueAtPercentile const resultPercentile = getValueAtPercentile(0.92, resultPercentileDistribution.percentiles); assert.deepEqual(resultPercentile, percentileResult, "Percentile value is wrong") }