diff --git a/test/instrumentation/module/express.test.js b/test/instrumentation/module/express.test.js index 6d71cbcc..9fa96764 100644 --- a/test/instrumentation/module/express.test.js +++ b/test/instrumentation/module/express.test.js @@ -173,45 +173,11 @@ test(`${testName1} Should record request in basic route`, function (t) { } process.nextTick(() => { const trace = agent.traceContext.currentTraceObject() - let actualBuilder = new MethodDescriptorBuilder('express', 'app.get') - .setParameterDescriptor('(path, callback)') - .setLineNumber(481) - .setFileName('application.js') - const actualMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder) - let spanEvent = trace.storage.storage[2] - t.equal(actualMethodDescriptor.apiId, spanEvent.apiId, 'apiId') - t.equal(spanEvent.annotations[0].key, -1, 'parameter') - t.equal(spanEvent.annotations[0].value.stringValue, '/express3', 'parameter value matching') - t.true(actualMethodDescriptor.apiDescriptor.startsWith('express.Function.app.get(path, callback)'), 'apiDescriptor') - t.equal(actualMethodDescriptor.className, 'Function', 'className') - t.equal(actualMethodDescriptor.fullName, 'express.app.get(path, callback)', 'fullName') - t.equal(actualMethodDescriptor.lineNumber, 481, 'lineNumber') - t.equal(actualMethodDescriptor.methodName, 'get', 'methodName') - t.equal(actualMethodDescriptor.moduleName, 'express', 'moduleName') - t.equal(actualMethodDescriptor.objectPath, 'app.get', 'objectPath') - t.true(actualMethodDescriptor.location.endsWith('application.js'), 'location') - t.equal(spanEvent.sequence, 0, 'sequence') - t.equal(spanEvent.depth, 1, 'spanEvent.depth') - - actualBuilder = new MethodDescriptorBuilder(undefined, '') - .setLineNumber(150) - .setFileName('express.test.js') - const actualHandlerMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder) - spanEvent = trace.storage.storage[1] - t.equal(spanEvent.sequence, 1, 'sequence') - t.equal(spanEvent.depth, 2, 'spanEvent.depth') - t.equal(actualHandlerMethodDescriptor.apiId, spanEvent.apiId, 'apiId') - t.equal(actualHandlerMethodDescriptor.apiDescriptor, 'Test.()', 'apiInfo') - t.equal(actualHandlerMethodDescriptor.type, 0, 'type') - t.equal(actualHandlerMethodDescriptor.lineNumber, 150, 'line number') - t.true(actualHandlerMethodDescriptor.location.endsWith('express.test.js'), 'location') - - spanEvent = trace.storage.storage[0] - t.equal(spanEvent.sequence, 2, 'sequence') - t.equal(spanEvent.depth, 3, 'spanEvent.depth') - t.equal(spanEvent.exceptionInfo.intValue, 1, 'error value') - t.true(spanEvent.exceptionInfo.stringValue.endsWith('express/lib/middleware/init.js:40:5)'), 'error case') + if (errorOrder == 1) { + noHandleTest(trace, t) + } else if (errorOrder == 2) { + } res.status(500).send('Something broke!') }) }) @@ -473,4 +439,45 @@ test('express version check', (t) => { actual = hook(null, '5.0.0', expected) t.equal(actual.name, 'module', 'express version 5.0.0 test') t.end() -}) \ No newline at end of file +}) + +function noHandleTest(trace, t) { + let actualBuilder = new MethodDescriptorBuilder('express', 'app.get') + .setParameterDescriptor('(path, callback)') + .setLineNumber(481) + .setFileName('application.js') + const actualMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder) + let spanEvent = trace.storage.storage[2] + t.equal(actualMethodDescriptor.apiId, spanEvent.apiId, 'apiId') + t.equal(spanEvent.annotations[0].key, -1, 'parameter') + t.equal(spanEvent.annotations[0].value.stringValue, '/express3', 'parameter value matching') + t.true(actualMethodDescriptor.apiDescriptor.startsWith('express.Function.app.get(path, callback)'), 'apiDescriptor') + t.equal(actualMethodDescriptor.className, 'Function', 'className') + t.equal(actualMethodDescriptor.fullName, 'express.app.get(path, callback)', 'fullName') + t.equal(actualMethodDescriptor.lineNumber, 481, 'lineNumber') + t.equal(actualMethodDescriptor.methodName, 'get', 'methodName') + t.equal(actualMethodDescriptor.moduleName, 'express', 'moduleName') + t.equal(actualMethodDescriptor.objectPath, 'app.get', 'objectPath') + t.true(actualMethodDescriptor.location.endsWith('application.js'), 'location') + t.equal(spanEvent.sequence, 0, 'sequence') + t.equal(spanEvent.depth, 1, 'spanEvent.depth') + + actualBuilder = new MethodDescriptorBuilder(undefined, '') + .setLineNumber(150) + .setFileName('express.test.js') + const actualHandlerMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder) + spanEvent = trace.storage.storage[1] + t.equal(spanEvent.sequence, 1, 'sequence') + t.equal(spanEvent.depth, 2, 'spanEvent.depth') + t.equal(actualHandlerMethodDescriptor.apiId, spanEvent.apiId, 'apiId') + t.equal(actualHandlerMethodDescriptor.apiDescriptor, 'Test.()', 'apiInfo') + t.equal(actualHandlerMethodDescriptor.type, 0, 'type') + t.equal(actualHandlerMethodDescriptor.lineNumber, 150, 'line number') + t.true(actualHandlerMethodDescriptor.location.endsWith('express.test.js'), 'location') + + spanEvent = trace.storage.storage[0] + t.equal(spanEvent.sequence, 2, 'sequence') + t.equal(spanEvent.depth, 3, 'spanEvent.depth') + t.equal(spanEvent.exceptionInfo.intValue, 1, 'error value') + t.true(spanEvent.exceptionInfo.stringValue.endsWith('express/lib/middleware/init.js:40:5)'), 'error case') +}