@reportportal/newman-reporter-agent-js-postman
Advanced tools
Comparing version 5.0.0 to 5.0.1
@@ -214,2 +214,14 @@ /* | ||
test('should not call client.startTestItem if test name is null', () => { | ||
reporter.onBeforeRequest(null, { | ||
item: { id: 'id' }, | ||
cursor: { ref: 'ref', iteration: 0 }, | ||
request: { | ||
description: { content: 'description' } | ||
} | ||
}); | ||
expect(reporter.client.startTestItem).not.toHaveBeenCalled(); | ||
}); | ||
test('should not call client.startTestItem if there is an error', () => { | ||
@@ -271,10 +283,237 @@ expect(() => reporter.onBeforeRequest('error')).toThrowError('error'); | ||
describe('finishStep', () => { | ||
test('should not call client.finishTestItem if testObj is empty', () => { | ||
reporter.collectionMap = new Map([['ref', { | ||
testId: 'startTestItem', | ||
steps: [] | ||
}]]); | ||
reporter.finishStep(null, { cursor: { ref: 'stepRef' } }); | ||
expect(reporter.client.finishTestItem).not.toHaveBeenCalled(); | ||
}); | ||
test('should not call client.finishTestItem if there is no appropriate step', () => { | ||
reporter.collectionMap = new Map([['ref', { | ||
testId: 'startTestItem', | ||
steps: [{ name: 'Step' }] | ||
}]]); | ||
reporter.finishStep(null, { cursor: { ref: 'ref' }, assertion: 'Step name' }); | ||
expect(reporter.client.finishTestItem).not.toHaveBeenCalled(); | ||
}); | ||
test('should call logMessage and client.finishTestItem if there is an error, status is failed', () => { | ||
reporter.collectionMap = new Map([['ref', { | ||
testId: 'testId', | ||
steps: [{ | ||
stepId: 'stepId', | ||
requestId: 'id', | ||
name: 'Step name' | ||
}] | ||
}]]); | ||
jest.spyOn(reporter, 'logMessage'); | ||
reporter.finishStep({ message: 'error' }, { cursor: { ref: 'ref' }, assertion: 'Step name' }); | ||
expect(reporter.logMessage).toHaveBeenCalledWith('stepId', 'error', 'ERROR'); | ||
expect(reporter.client.finishTestItem).toHaveBeenCalledWith('stepId', { status: 'FAILED' }); | ||
expect(reporter.collectionMap.get('ref')).toEqual({ testId: 'testId', steps: [] }); | ||
}); | ||
test('should call client.finishTestItem with status passed if there is no error', () => { | ||
reporter.collectionMap = new Map([['ref', { | ||
testId: 'testId', | ||
steps: [{ | ||
stepId: 'stepId', | ||
requestId: 'id', | ||
name: 'Step name' | ||
}] | ||
}]]); | ||
jest.spyOn(reporter, 'logMessage'); | ||
reporter.finishStep(null, { cursor: { ref: 'ref' }, assertion: 'Step name' }); | ||
expect(reporter.logMessage).not.toHaveBeenCalled(); | ||
expect(reporter.client.finishTestItem).toHaveBeenCalledWith('stepId', { status: 'PASSED' }); | ||
expect(reporter.collectionMap.get('ref')).toEqual({ testId: 'testId', steps: [] }); | ||
}); | ||
}); | ||
describe('finishAllSteps', () => { | ||
test('should not call failAllSteps if there is an error', () => { | ||
jest.spyOn(reporter, 'failAllSteps'); | ||
expect(() => reporter.finishAllSteps('error')).toThrowError('error'); | ||
expect(reporter.failAllSteps).not.toHaveBeenCalled(); | ||
}); | ||
test('should not call failAllSteps if testResult doesn\'t contain execution with error', () => { | ||
const testObj = { | ||
testId: 'testId', | ||
steps: [ | ||
{ | ||
stepId: 'stepId', | ||
requestId: 'id', | ||
name: 'Step name' | ||
}, | ||
{ | ||
stepId: 'stepIdTwo', | ||
requestId: 'idTwo', | ||
name: 'Step name two' | ||
} | ||
] | ||
}; | ||
const testResultObj = { | ||
cursor: { ref: 'ref' }, | ||
executions: [] | ||
}; | ||
reporter.collectionMap = new Map([['ref', testObj]]); | ||
jest.spyOn(reporter, 'failAllSteps'); | ||
reporter.finishAllSteps(null, testResultObj); | ||
expect(reporter.failAllSteps).not.toHaveBeenCalled(); | ||
}); | ||
test('should call failAllSteps with parameters if testResult contains execution with error', () => { | ||
const testObj = { | ||
testId: 'testId', | ||
steps: [ | ||
{ | ||
stepId: 'stepId', | ||
requestId: 'id', | ||
name: 'Step name' | ||
}, | ||
{ | ||
stepId: 'stepIdTwo', | ||
requestId: 'idTwo', | ||
name: 'Step name two' | ||
} | ||
] | ||
}; | ||
const testResultObj = { | ||
cursor: { ref: 'ref' }, | ||
executions: [{ error: { message: 'error' } }] | ||
}; | ||
reporter.collectionMap = new Map([['ref', testObj]]); | ||
jest.spyOn(reporter, 'failAllSteps'); | ||
reporter.finishAllSteps(null, testResultObj); | ||
expect(reporter.failAllSteps).toHaveBeenCalledWith(testObj, 'error'); | ||
}); | ||
}); | ||
describe('onRequest', () => { | ||
test('should update collectionMap with error and response values if testObj exists', () => { | ||
const testObj = { | ||
testId: 'testId', | ||
steps: [] | ||
}; | ||
const expectedTestObj = { | ||
testId: 'testId', | ||
steps: [], | ||
response: 'response', | ||
error: 'error' | ||
}; | ||
reporter.collectionMap = new Map([['ref', testObj]]); | ||
reporter.onRequest('error', { cursor: { ref: 'ref' }, response: 'response' }); | ||
expect(reporter.collectionMap.get('ref')).toEqual(expectedTestObj); | ||
}); | ||
test('should not update collectionMap with error and response values if testObj doesn\'t exist', () => { | ||
const testObj = { | ||
testId: 'testId', | ||
steps: [] | ||
}; | ||
reporter.collectionMap = new Map([['ref', testObj]]); | ||
reporter.onRequest('error', { cursor: { ref: 'refRequest' }, response: 'response' }); | ||
expect(reporter.collectionMap.get('ref')).toEqual(testObj); | ||
}); | ||
}); | ||
describe('finishTest', () => { | ||
let sendResponseLogs; | ||
beforeEach(() => { | ||
sendResponseLogs = jest.spyOn(reporter, 'sendResponseLogs').mockImplementation(() => {}); | ||
}); | ||
afterEach(() => { | ||
sendResponseLogs.mockRestore(); | ||
}); | ||
test('should not call client.finishTestItem if there is an error', () => { | ||
expect(() => reporter.finishTest('error')).toThrowError('error'); | ||
expect(reporter.client.finishTestItem).not.toHaveBeenCalled(); | ||
}); | ||
test('should not call client.finishTestItem if testObj doesn\'t exist', () => { | ||
const testObj = { | ||
testId: 'testId', | ||
steps: [], | ||
error: undefined | ||
}; | ||
reporter.collectionMap = new Map([['ref', testObj]]); | ||
reporter.finishTest(null, { cursor: { ref: 'refRequest' } }); | ||
expect(reporter.client.finishTestItem).not.toHaveBeenCalled(); | ||
}); | ||
test('should call logMessage with ERROR and client.finishTestItem with status failed if testObj has error value', () => { | ||
const testObj = { | ||
testId: 'testId', | ||
steps: [], | ||
error: { message: 'error' } | ||
}; | ||
reporter.collectionMap = new Map([['ref', testObj]]); | ||
jest.spyOn(reporter, 'logMessage'); | ||
reporter.finishTest(null, { cursor: { ref: 'ref' } }); | ||
expect(reporter.logMessage).toHaveBeenCalledWith('testId', 'error', 'ERROR'); | ||
expect(reporter.client.finishTestItem).toHaveBeenCalledWith('testId', { status: 'FAILED' }); | ||
}); | ||
test('should call sendResponseLogs and client.finishTestItem with status passed if testObj has response', () => { | ||
const testObj = { | ||
testId: 'testId', | ||
steps: [], | ||
error: undefined, | ||
response: { headers: { members: ['members'] } } | ||
}; | ||
reporter.collectionMap = new Map([['ref', testObj]]); | ||
reporter.finishTest(null, { cursor: { ref: 'ref' } }); | ||
expect(reporter.sendResponseLogs).toHaveBeenCalledWith('testId', { headers: { members: ['members'] } }); | ||
expect(reporter.client.finishTestItem).toHaveBeenCalledWith('testId', { status: 'PASSED' }); | ||
}); | ||
test('should not call sendResponseLogs if testObj hasn\'t response', () => { | ||
const testObj = { | ||
testId: 'testId', | ||
steps: [], | ||
error: undefined | ||
}; | ||
reporter.collectionMap = new Map([['ref', testObj]]); | ||
reporter.finishTest(null, { cursor: { ref: 'ref' } }); | ||
expect(reporter.sendResponseLogs).not.toHaveBeenCalledWith(); | ||
expect(reporter.client.finishTestItem).toHaveBeenCalledWith('testId', { status: 'PASSED' }); | ||
}); | ||
}); | ||
describe('onBeforeDone', () => { | ||
let finishSteps; | ||
let finishTest; | ||
let finishSuite; | ||
beforeEach(() => { | ||
finishSteps = jest.spyOn(reporter, 'finishSteps').mockImplementation(() => {}); | ||
finishTest = jest.spyOn(reporter, 'finishTest').mockImplementation(() => {}); | ||
finishSuite = jest.spyOn(reporter, 'finishSuite').mockImplementation(() => {}); | ||
@@ -284,30 +523,14 @@ }); | ||
afterEach(() => { | ||
finishSteps.mockRestore(); | ||
finishTest.mockRestore(); | ||
finishSuite.mockRestore(); | ||
}); | ||
test('should call finishSteps, finishTest and finishSuite with parameters', () => { | ||
const expectedTestObj = { steps: [], testId: 'startTestItem' }; | ||
reporter.collectionMap = new Map([['ref', { | ||
testId: 'startTestItem', | ||
steps: [] | ||
}]]); | ||
test('should call finishSuite', () => { | ||
reporter.onBeforeDone(); | ||
reporter.onBeforeDone(null, { | ||
summary: { run: 'run' } | ||
}); | ||
expect(reporter.finishSteps).toHaveBeenCalledTimes(1); | ||
expect(reporter.finishTest).toHaveBeenCalledTimes(1); | ||
expect(reporter.finishSuite).toHaveBeenCalledTimes(1); | ||
expect(reporter.finishSteps).toHaveBeenCalledWith('ref', expectedTestObj, 'run'); | ||
expect(reporter.finishTest).toHaveBeenCalledWith('ref', expectedTestObj, 'run'); | ||
expect(reporter.finishSuite).toHaveBeenCalledWith(); | ||
}); | ||
test('should not call finishTest, finishSteps and finishSuite if there is an error', () => { | ||
test('should not call finishSuite if there is an error', () => { | ||
expect(() => reporter.onBeforeDone('error')).toThrowError('error'); | ||
expect(reporter.finishSteps).not.toHaveBeenCalled(); | ||
expect(reporter.finishTest).not.toHaveBeenCalled(); | ||
expect(reporter.finishSuite).not.toHaveBeenCalled(); | ||
@@ -379,2 +602,8 @@ }); | ||
describe('getTestName', () => { | ||
test('should return null if test name as parameter is not defined', () => { | ||
const testName = reporter.getTestName({ cursor: { iteration: 0 }, item: { } }); | ||
expect(testName).toEqual(null); | ||
}); | ||
test('should return test name with iteration number if iterationCount is not undefined', () => { | ||
@@ -386,3 +615,3 @@ const expectedTestName = 'name #1'; | ||
expect(expectedTestName).toEqual(testName); | ||
expect(testName).toEqual(expectedTestName); | ||
}); | ||
@@ -396,3 +625,3 @@ | ||
expect(expectedTestName).toEqual(testName); | ||
expect(testName).toEqual(expectedTestName); | ||
}); | ||
@@ -507,83 +736,2 @@ }); | ||
describe('finishSteps', () => { | ||
test('should call failAllSteps with parameters if if there is an error in a test-scripts', () => { | ||
const testObj = { | ||
testId: 'startTestItem', | ||
steps: [{ | ||
stepId: 'startTestItem', | ||
requestId: 'id', | ||
name: 'step name' | ||
}] | ||
}; | ||
const runObj = { | ||
executions: [{ id: 'id' }], | ||
failures: [{ | ||
at: 'test-script', | ||
cursor: { | ||
ref: 'ref' | ||
}, | ||
error: { | ||
message: 'scriptFailureError' | ||
} | ||
}] | ||
}; | ||
jest.spyOn(reporter, 'failAllSteps'); | ||
jest.spyOn(reporter, 'sendResponseLogs').mockImplementation(() => {}); | ||
reporter.finishSteps('ref', testObj, runObj); | ||
expect(reporter.failAllSteps).toHaveBeenCalledWith(testObj, 'scriptFailureError'); | ||
}); | ||
test('should call logMessage and client.finishTestItem if there are failures, status is failed', () => { | ||
const testObj = { | ||
testId: 'startTestItem', | ||
steps: [{ | ||
stepId: 'startTestItem', | ||
requestId: 'id', | ||
name: 'step name' | ||
}] | ||
}; | ||
const runObj = { | ||
executions: [{ id: 'id' }], | ||
failures: [{ | ||
cursor: { | ||
ref: 'ref' | ||
}, | ||
error: { | ||
test: 'step name', | ||
message: 'error' | ||
} | ||
}] | ||
}; | ||
jest.spyOn(reporter, 'logMessage'); | ||
jest.spyOn(reporter, 'sendResponseLogs').mockImplementation(() => {}); | ||
reporter.finishSteps('ref', testObj, runObj); | ||
expect(reporter.logMessage).toHaveBeenCalledWith('startTestItem', 'error', 'ERROR'); | ||
expect(reporter.client.finishTestItem).toHaveBeenCalledWith('startTestItem', { status: 'FAILED' }); | ||
}); | ||
test('should call client.finishTestItem with status passed', () => { | ||
const testObj = { | ||
testId: 'startTestItem', | ||
steps: [{ | ||
stepId: 'startTestItem', | ||
requestId: 'id', | ||
name: 'step name' | ||
}] | ||
}; | ||
const runObj = { | ||
executions: [{ id: 'id' }], | ||
failures: [] | ||
}; | ||
jest.spyOn(reporter, 'sendResponseLogs').mockImplementation(() => {}); | ||
reporter.finishSteps('ref', testObj, runObj); | ||
expect(reporter.client.finishTestItem).toHaveBeenCalledWith('startTestItem', { status: 'PASSED' }); | ||
}); | ||
}); | ||
describe('failAllSteps', () => { | ||
@@ -605,82 +753,2 @@ test('should call client.finishTestItem with status failed and logMessage with error', () => { | ||
describe('finishTest', () => { | ||
test('should call logMessage with ERROR and client.finishTestItem with status failed if there is requestError', () => { | ||
const testObj = { | ||
testId: 'startTestItem', | ||
requestId: 'id' | ||
}; | ||
const runObj = { | ||
executions: [{ | ||
id: 'id', | ||
cursor: { | ||
httpRequestId: 'id' | ||
}, | ||
requestError: { | ||
message: 'requestError' | ||
} | ||
}] | ||
}; | ||
jest.spyOn(reporter, 'logMessage'); | ||
reporter.finishTest('ref', testObj, runObj); | ||
expect(reporter.logMessage).toHaveBeenCalledWith('startTestItem', 'requestError', 'ERROR'); | ||
expect(reporter.client.finishTestItem).toHaveBeenCalledWith('startTestItem', { status: 'FAILED' }); | ||
}); | ||
test('should call sendResponseLogs and client.finishTestItem with status failed if cursor.ref is the same as reference', () => { | ||
const testObj = { | ||
testId: 'startTestItem', | ||
requestId: 'id' | ||
}; | ||
const runObj = { | ||
failures: [{ | ||
cursor: { | ||
ref: 'ref' | ||
} | ||
}], | ||
executions: [{ | ||
id: 'id', | ||
cursor: { | ||
httpRequestId: 'id' | ||
}, | ||
response: 'response' | ||
}] | ||
}; | ||
jest.spyOn(reporter, 'sendResponseLogs'); | ||
reporter.finishTest('ref', testObj, runObj); | ||
expect(reporter.sendResponseLogs).toHaveBeenCalledWith('startTestItem', 'response'); | ||
expect(reporter.client.finishTestItem).toHaveBeenCalledWith('startTestItem', { status: 'FAILED' }); | ||
}); | ||
test('should call sendResponseLogs and client.finishTestItem with status passed if cursor.ref is not the same as reference', () => { | ||
const testObj = { | ||
testId: 'startTestItem', | ||
requestId: 'id' | ||
}; | ||
const runObj = { | ||
failures: [{ | ||
cursor: { | ||
ref: 'refTwo' | ||
} | ||
}], | ||
executions: [{ | ||
id: 'id', | ||
cursor: { | ||
httpRequestId: 'id' | ||
}, | ||
response: 'response' | ||
}] | ||
}; | ||
jest.spyOn(reporter, 'sendResponseLogs'); | ||
reporter.finishTest('ref', testObj, runObj); | ||
expect(reporter.sendResponseLogs).toHaveBeenCalledWith('startTestItem', 'response'); | ||
expect(reporter.client.finishTestItem).toHaveBeenCalledWith('startTestItem', { status: 'PASSED' }); | ||
}); | ||
}); | ||
describe('finishSuite', () => { | ||
@@ -687,0 +755,0 @@ let getCurrentSuiteTempId; |
@@ -85,2 +85,41 @@ /* | ||
describe('getArrAttributesFromString', () => { | ||
test('should return correct array of attributes', () => { | ||
const parameter = 'keyOne:valueOne'; | ||
const expectedAttributes = [ | ||
{ | ||
key: 'keyOne', | ||
value: 'valueOne' | ||
} | ||
]; | ||
const attributes = utils.getArrAttributesFromString(parameter); | ||
expect(attributes).toEqual(expectedAttributes); | ||
}); | ||
test('should return correct array of attributes, key should be null', () => { | ||
const parameter = 'keyOne:valueOne;valueTwo'; | ||
const expectedAttributes = [ | ||
{ | ||
key: 'keyOne', | ||
value: 'valueOne' | ||
}, { | ||
key: null, | ||
value: 'valueTwo' | ||
} | ||
]; | ||
const attributes = utils.getArrAttributesFromString(parameter); | ||
expect(attributes).toEqual(expectedAttributes); | ||
}); | ||
test('should return empty array of attributes, if there is no parameter', () => { | ||
const attributes = utils.getArrAttributesFromString(); | ||
expect(attributes).toEqual([]); | ||
}); | ||
}); | ||
describe('getAttributes', () => { | ||
@@ -170,3 +209,3 @@ test('should return correct array of attributes', () => { | ||
const testCaseId = utils.getCollectionVariablesByKey( 'testCaseId', variables); | ||
const testCaseId = utils.getCollectionVariablesByKey('testCaseId', variables); | ||
@@ -230,2 +269,30 @@ expect(testCaseId).toEqual('testCaseId'); | ||
test('should return client with CLI options', () => { | ||
const options = { | ||
reportportalAgentJsPostmanToken: 'token', | ||
reportportalAgentJsPostmanEndpoint: 'endpoint', | ||
reportportalAgentJsPostmanLaunch: 'launch', | ||
reportportalAgentJsPostmanProject: 'project', | ||
reportportalAgentJsPostmanRerun: true, | ||
reportportalAgentJsPostmanRerunOf: 'rerunOf', | ||
reportportalAgentJsPostmanDescription: 'description', | ||
reportportalAgentJsPostmanAttributes: 'attribute', | ||
reportportalAgentJsPostmanDebug: true | ||
}; | ||
const clientInitObject = utils.getClientInitObject(options); | ||
expect(clientInitObject).toEqual({ | ||
token: 'token', | ||
endpoint: 'endpoint', | ||
launch: 'launch', | ||
project: 'project', | ||
rerun: true, | ||
rerunOf: 'rerunOf', | ||
description: 'description', | ||
attributes: [{ key: null, value: 'attribute' }], | ||
debug: true | ||
}); | ||
}); | ||
test('should return client init object with default launch name', () => { | ||
@@ -283,2 +350,26 @@ const options = { | ||
test('should return start launch object with CLI options', () => { | ||
const options = { | ||
reportportalAgentJsPostmanLaunch: 'launch name', | ||
reportportalAgentJsPostmanDescription: 'description', | ||
reportportalAgentJsPostmanRerun: true, | ||
reportportalAgentJsPostmanRerunOf: 'rerunOf' | ||
}; | ||
const startLaunchObject = utils.getStartLaunchObj(options); | ||
expect(startLaunchObject).toEqual({ | ||
launch: 'launch name', | ||
description: 'description', | ||
attributes: [{ | ||
key: 'agent', | ||
value: `${pjson.name}|${pjson.version}`, | ||
system: true | ||
}], | ||
rerun: true, | ||
rerunOf: 'rerunOf', | ||
mode: undefined | ||
}); | ||
}); | ||
test('should return start launch object with default launch name', () => { | ||
@@ -285,0 +376,0 @@ const options = { |
## [5.0.1] - 2021-05-18 | ||
### Fixed | ||
- [#53](https://github.com/reportportal/agent-js-postman/issues/43) Fix working with CLI. | ||
- [#31](https://github.com/reportportal/agent-js-postman/issues/31) Fix reporting attributes for launch with CLI. | ||
- [#8](https://github.com/reportportal/agent-js-postman/issues/8) Fix error "Cannot read property 'requestError' of undefined". | ||
## [5.0.0] - 2021-03-08 | ||
@@ -3,0 +9,0 @@ ### Changed |
@@ -62,2 +62,6 @@ /* | ||
emitter.on('beforeTest', this.onBeforeTest.bind(this)); | ||
emitter.on('item', this.finishTest.bind(this)); | ||
emitter.on('assertion', this.finishStep.bind(this)); | ||
emitter.on('test', this.finishAllSteps.bind(this)); | ||
emitter.on('request', this.onRequest.bind(this)); | ||
emitter.on('beforeDone', this.onBeforeDone.bind(this)); | ||
@@ -104,2 +108,5 @@ emitter.on('done', this.onDone.bind(this)); | ||
getTestName (result) { | ||
if (result.item.name === undefined) { | ||
return null; | ||
} | ||
const iteration = this.collectionRunOptions.iterationCount === undefined ? | ||
@@ -142,5 +149,8 @@ '' : | ||
} | ||
const name = this.getTestName(result); | ||
if (!name) { | ||
return; | ||
} | ||
const parentId = this.getCurrentSuiteTempId(); | ||
const description = result.request.description && result.request.description.content; | ||
const name = this.getTestName(result); | ||
const codeRefTitle = `${this.collectionRunOptions.collection.name}/${result.item.name}`; | ||
@@ -228,4 +238,29 @@ const codeRef = utils.getCodeRef(this.collectionPath, codeRefTitle); | ||
// Finishes all test steps and tests | ||
onBeforeDone (err, result) { | ||
finishStep (error, testAssertion) { | ||
const testObj = this.collectionMap.get(testAssertion.cursor.ref); | ||
if (!testObj) { | ||
return; | ||
} | ||
const currentStepIndex = testObj.steps.findIndex(step => step.name === testAssertion.assertion); | ||
const currentStep = testObj.steps[currentStepIndex]; | ||
testObj.steps.splice(currentStepIndex, 1); | ||
if (!currentStep) { | ||
return; | ||
} | ||
const actualError = error || testAssertion.error; | ||
if (actualError) { | ||
// Logs error message for the failed steps | ||
this.logMessage(currentStep.stepId, actualError.message, 'ERROR'); | ||
} | ||
this.client | ||
.finishTestItem(currentStep.stepId, { | ||
status: currentStep.status || (actualError ? TestStatus.FAILED : TestStatus.PASSED) | ||
}) | ||
.promise.catch(errorHandler); | ||
this.collectionMap.set(testAssertion.cursor.ref, testObj); | ||
} | ||
finishAllSteps (err, testResult) { | ||
if (err) { | ||
@@ -235,9 +270,59 @@ throw err; | ||
const run = result.summary.run; | ||
const testObj = this.collectionMap.get(testResult.cursor.ref); | ||
const testWithError = testResult.executions.find(item => item.error); | ||
for (let [ref, testObj] of this.collectionMap) { | ||
this.finishSteps(ref, testObj, run); | ||
this.finishTest(ref, testObj, run); | ||
if (testWithError) { | ||
// Fails all steps with the same error if there is an error in a test-script | ||
this.failAllSteps(testObj, testWithError.error.message); | ||
} | ||
} | ||
onRequest (error, result) { | ||
const testObj = this.collectionMap.get(result.cursor.ref); | ||
if (testObj) { | ||
this.collectionMap.set(result.cursor.ref, { ...testObj, response: result && result.response, error }); | ||
} | ||
} | ||
finishTest (err, result) { | ||
if (err) { | ||
throw err; | ||
} | ||
const testObj = this.collectionMap.get(result.cursor.ref); | ||
if (!testObj) { | ||
return; | ||
} | ||
const status = testObj.status; | ||
if (testObj.error) { | ||
this.logMessage(testObj.testId, testObj.error.message, 'ERROR'); | ||
this.client | ||
.finishTestItem(testObj.testId, { | ||
status: status || TestStatus.FAILED | ||
}) | ||
.promise.catch(errorHandler); | ||
return; | ||
} | ||
if (testObj.response) { | ||
this.sendResponseLogs(testObj.testId, testObj.response); | ||
} | ||
this.client | ||
.finishTestItem(testObj.testId, { | ||
status: status || TestStatus.PASSED | ||
}) | ||
.promise.catch(errorHandler); | ||
} | ||
// Finishes suite | ||
onBeforeDone (err) { | ||
if (err) { | ||
throw err; | ||
} | ||
this.finishSuite(); | ||
@@ -333,48 +418,2 @@ this.suitesInfoStack.pop(); | ||
/** | ||
* Finishes all test steps in a given test object. | ||
* | ||
* @param {string} reference Reference id to the current test run. | ||
* @param {Object} testObj Test item steps of which have to be finished. | ||
* @param {Object} run Object with information about current test run. | ||
*/ | ||
finishSteps (reference, testObj, run) { | ||
const scriptFailure = _.find(run.failures, { | ||
at: 'test-script', | ||
cursor: { | ||
ref: reference | ||
} | ||
}); | ||
if (scriptFailure) { | ||
// Fails all steps with the same error if there is an error in a test-script | ||
this.failAllSteps(testObj, scriptFailure.error.message); | ||
return; | ||
} | ||
// Otherwise finishes all steps according to their results | ||
_.forEach(testObj.steps, step => { | ||
const failure = _.find(run.failures, { | ||
cursor: { | ||
ref: reference | ||
}, | ||
error: { | ||
test: step.name | ||
} | ||
}); | ||
if (failure) { | ||
// Logs error message for the failed steps | ||
this.logMessage(step.stepId, failure.error.message, 'ERROR'); | ||
} | ||
this.client | ||
.finishTestItem(step.stepId, { | ||
status: step.status || (failure ? TestStatus.FAILED : TestStatus.PASSED) | ||
}) | ||
.promise.catch(errorHandler); | ||
}); | ||
} | ||
/** | ||
* Fails all steps of the given test object with sending the same error message for each of them. | ||
@@ -397,41 +436,2 @@ * | ||
/** | ||
* Finishes given test object. | ||
* | ||
* @param {string} reference Reference id to the current test run. | ||
* @param {Object} testObj Test item to finish. | ||
* @param {Object} run Object with information about current test run. | ||
*/ | ||
finishTest (reference, testObj, run) { | ||
const failed = _.some(run.failures, ['cursor.ref', reference]); | ||
const execution = _.find(run.executions, { | ||
cursor: { | ||
httpRequestId: testObj && testObj.requestId | ||
} | ||
}); | ||
const status = testObj && testObj.status; | ||
if (execution && execution.requestError) { | ||
this.logMessage(testObj.testId, execution.requestError.message, 'ERROR'); | ||
this.client | ||
.finishTestItem(testObj.testId, { | ||
status: status || TestStatus.FAILED | ||
}) | ||
.promise.catch(errorHandler); | ||
return; | ||
} | ||
if (execution && execution.response) { | ||
this.sendResponseLogs(testObj.testId, execution.response); | ||
} | ||
this.client | ||
.finishTestItem(testObj.testId, { | ||
status: status || failed ? TestStatus.FAILED : TestStatus.PASSED | ||
}) | ||
.promise.catch(errorHandler); | ||
} | ||
finishSuite () { | ||
@@ -438,0 +438,0 @@ const currentSuiteTempId = this.getCurrentSuiteTempId(); |
@@ -77,2 +77,13 @@ /* | ||
getArrAttributesFromString (stringAttr) { | ||
return stringAttr ? stringAttr.split(';').map(attribute => { | ||
const attributeArr = attribute.split(':'); | ||
return { | ||
key: attributeArr.length === 1 ? null : attributeArr[0], | ||
value: attributeArr.length === 1 ? attributeArr[0] : attributeArr[1] | ||
}; | ||
}) : []; | ||
}, | ||
/** | ||
@@ -89,10 +100,3 @@ * Extract all attributes from the given array and transform its | ||
return attributes && attributes.value ? attributes.value.split(';').map(attribute => { | ||
const attributeArr = attribute.split(':'); | ||
return { | ||
key: attributeArr.length === 1 ? null : attributeArr[0], | ||
value: attributeArr.length === 1 ? attributeArr[0] : attributeArr[1] | ||
}; | ||
}) : []; | ||
return attributes ? this.getArrAttributesFromString(attributes.value) : []; | ||
}, | ||
@@ -108,12 +112,13 @@ | ||
return { | ||
token: options.token, | ||
endpoint: options.endpoint, | ||
launch: options.launch || DEFAULT_LAUNCH_NAME, | ||
project: options.project, | ||
rerun: options.rerun, | ||
rerunOf: options.rerunOf, | ||
description: options.description, | ||
attributes: options.attributes, | ||
debug: options.debug, | ||
mode: options.mode | ||
token: options.token || options.reportportalAgentJsPostmanToken, | ||
endpoint: options.endpoint || options.reportportalAgentJsPostmanEndpoint, | ||
launch: options.launch || options.reportportalAgentJsPostmanLaunch || DEFAULT_LAUNCH_NAME, | ||
project: options.project || options.reportportalAgentJsPostmanProject, | ||
rerun: options.rerun || options.reportportalAgentJsPostmanRerun, | ||
rerunOf: options.rerunOf || options.reportportalAgentJsPostmanRerunOf, | ||
description: options.description || options.reportportalAgentJsPostmanDescription, | ||
attributes: options.attributes || | ||
this.getArrAttributesFromString(options.reportportalAgentJsPostmanAttributes), | ||
debug: options.debug || options.reportportalAgentJsPostmanDebug, | ||
mode: options.mode || options.reportportalAgentJsPostmanMode | ||
}; | ||
@@ -128,10 +133,12 @@ }, | ||
}; | ||
const attributes = options.attributes || | ||
this.getArrAttributesFromString(options.reportportalAgentJsPostmanAttributes); | ||
return { | ||
launch: options.launch || DEFAULT_LAUNCH_NAME, | ||
description: options.description, | ||
attributes: options.attributes ? options.attributes.concat(systemAttr) : [systemAttr], | ||
rerun: options.rerun, | ||
rerunOf: options.rerunOf, | ||
mode: options.mode | ||
launch: options.launch || options.reportportalAgentJsPostmanLaunch || DEFAULT_LAUNCH_NAME, | ||
description: options.description || options.reportportalAgentJsPostmanDescription, | ||
attributes: attributes ? attributes.concat(systemAttr) : [systemAttr], | ||
rerun: options.rerun || options.reportportalAgentJsPostmanRerun, | ||
rerunOf: options.rerunOf || options.reportportalAgentJsPostmanRerunOf, | ||
mode: options.mode || options.reportportalAgentJsPostmanMode | ||
}; | ||
@@ -138,0 +145,0 @@ }, |
{ | ||
"name": "@reportportal/newman-reporter-agent-js-postman", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"description": "ReportPortal reporter for newman", | ||
@@ -32,4 +32,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@reportportal/client-javascript": "^5.0.4", | ||
"lodash": "^4.17.15", | ||
"@reportportal/client-javascript": "^5.0.3", | ||
"string_decoder": "^1.2.0" | ||
@@ -36,0 +36,0 @@ }, |
@@ -31,2 +31,3 @@ # @reportportal/agent-js-postman | ||
--reporter-@reportportal/agent-js-postman-description=LAUNCH_DESCRIPTION \ | ||
--reporter-@reportportal/agent-js-postman-attributes=launchKey:launchValue;launchValueTwo \ | ||
-x | ||
@@ -87,2 +88,3 @@ ``` | ||
| description | Text description of launch. | | ||
| attributes | Attributes of launch.<br/> Programmatically - [{ "key": "YourKey", "value": "YourValue" }] <br/> with CLI - "YourKey:YourValue;YourValueTwo" | | ||
| rerun | Enable [rerun](https://github.com/reportportal/documentation/blob/master/src/md/src/DevGuides/rerun.md) | | ||
@@ -89,0 +91,0 @@ | rerunOf | UUID of launch you want to rerun. If not specified, report portal will update the latest launch with the same name. | |
Sorry, the diff of this file is not supported yet
114107
1817
189