From 190dd1e223c38debe9a22ff27abc3e3b48f3a43b Mon Sep 17 00:00:00 2001 From: Muthu Kumar Date: Tue, 25 Sep 2018 19:49:27 +0530 Subject: [PATCH] [reporter] xUnit reporter fix for skipped tests --- .vscode/launch.json | 3 ++- package.json | 2 +- sample/sample7.test.js | 21 +++++++-------------- src/reporters/xunit.js | 11 ++++------- 4 files changed, 14 insertions(+), 23 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 004e6d3..5fbe89c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,8 @@ "type": "node", "request": "launch", "name": "Debug Gunner", - "program": "${workspaceFolder}/sample/sample.test.js", + "runtimeExecutable": "/home/mkr/.nvs/node/10.8.0/x64/bin/node", + "program": "${workspaceFolder}/sample/sample7.test.js", "args": [ "--log", "--trace", diff --git a/package.json b/package.json index 6471057..ec756e0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@klenty/gunner", - "version": "0.11.6", + "version": "0.11.7", "description": "Zero magic, fast test-runner and assertion framework. No magic globals.", "main": "index.js", "repository": { diff --git a/sample/sample7.test.js b/sample/sample7.test.js index 23e1505..837e338 100644 --- a/sample/sample7.test.js +++ b/sample/sample7.test.js @@ -3,7 +3,7 @@ * used during development */ -const Gunner = require('../es5/Gunner'); +const Gunner = require('../src/Gunner'); const expect = Gunner.expect; const expectMany = Gunner.expectMany; const gunner = new Gunner('sample tests'); @@ -37,17 +37,10 @@ gunner.test('wait and resolve', () => { gunner.test('should resolve to 5', () => expect(Promise.resolve(5)).resolvesTo(5)); -// gunner.before( -// 'file must have hello as content', -// () => console.log('>> starting test! file must have hello as content'), -// 'helloContentBefore', -// ); - -// gunner.after( -// 'file must have hello as content', -// () => console.log('>> finished test! file must have hello as content'), -// 'helloContentAfter', -// ); +gunner.before( + 'file must have hello as content', + () => { throw new Error('>> I caused a before hook to fail!') } +); gunner.test('file must have hello as content', async () => { const { readFile } = require('fs').promises; @@ -99,5 +92,5 @@ gunner.test('(should fail) should not resolve to 5', () => const trace = process.argv.slice(2).indexOf('--trace') !== -1; const reporter = process.argv.slice(2).indexOf('--log') !== -1; -gunner.run({ trace, reporter }); -// gunner.run({ reporter:'xunit' }); +// gunner.run({ trace, reporter }); +gunner.run({ reporter:'xunit' }); diff --git a/src/reporters/xunit.js b/src/reporters/xunit.js index bfffc8e..c4d3b0e 100644 --- a/src/reporters/xunit.js +++ b/src/reporters/xunit.js @@ -20,14 +20,11 @@ const toJSON = resultsArray => { time: (results.duration / 1000) || 0, }, children: results.reduce((acc, r) => { + const reason = r.reason ? (r.reason.stack || r.reason) : ''; const content = r.status !== 'ok' && - (r.status === 'skip' - ? 'skipped' - : { - name: 'failure', - text: r.reason - ? (r.reason && r.reason.stack) : '' - }); + r.status === 'skip' + ? { name: 'skipped', text: reason } + : { name: 'failure', text: reason }; acc.push({ name: 'testcase', attrs: {