Browse Source

[reporter] xUnit reporter fix for skipped tests

master
Muthu Kumar 6 years ago
parent
commit
190dd1e223
  1. 3
      .vscode/launch.json
  2. 2
      package.json
  3. 21
      sample/sample7.test.js
  4. 11
      src/reporters/xunit.js

3
.vscode/launch.json

@ -8,7 +8,8 @@
"type": "node", "type": "node",
"request": "launch", "request": "launch",
"name": "Debug Gunner", "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": [ "args": [
"--log", "--log",
"--trace", "--trace",

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "@klenty/gunner", "name": "@klenty/gunner",
"version": "0.11.6", "version": "0.11.7",
"description": "Zero magic, fast test-runner and assertion framework. No magic globals.", "description": "Zero magic, fast test-runner and assertion framework. No magic globals.",
"main": "index.js", "main": "index.js",
"repository": { "repository": {

21
sample/sample7.test.js

@ -3,7 +3,7 @@
* used during development * used during development
*/ */
const Gunner = require('../es5/Gunner'); const Gunner = require('../src/Gunner');
const expect = Gunner.expect; const expect = Gunner.expect;
const expectMany = Gunner.expectMany; const expectMany = Gunner.expectMany;
const gunner = new Gunner('sample tests'); const gunner = new Gunner('sample tests');
@ -37,17 +37,10 @@ gunner.test('wait and resolve', () => {
gunner.test('should resolve to 5', () => gunner.test('should resolve to 5', () =>
expect(Promise.resolve(5)).resolvesTo(5)); expect(Promise.resolve(5)).resolvesTo(5));
// gunner.before( gunner.before(
// 'file must have hello as content', 'file must have hello as content',
// () => console.log('>> starting test! file must have hello as content'), () => { throw new Error('>> I caused a before hook to fail!') }
// 'helloContentBefore', );
// );
// gunner.after(
// 'file must have hello as content',
// () => console.log('>> finished test! file must have hello as content'),
// 'helloContentAfter',
// );
gunner.test('file must have hello as content', async () => { gunner.test('file must have hello as content', async () => {
const { readFile } = require('fs').promises; 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 trace = process.argv.slice(2).indexOf('--trace') !== -1;
const reporter = process.argv.slice(2).indexOf('--log') !== -1; const reporter = process.argv.slice(2).indexOf('--log') !== -1;
gunner.run({ trace, reporter }); // gunner.run({ trace, reporter });
// gunner.run({ reporter:'xunit' }); gunner.run({ reporter:'xunit' });

11
src/reporters/xunit.js

@ -20,14 +20,11 @@ const toJSON = resultsArray => {
time: (results.duration / 1000) || 0, time: (results.duration / 1000) || 0,
}, },
children: results.reduce((acc, r) => { children: results.reduce((acc, r) => {
const reason = r.reason ? (r.reason.stack || r.reason) : '';
const content = r.status !== 'ok' && const content = r.status !== 'ok' &&
(r.status === 'skip' r.status === 'skip'
? 'skipped' ? { name: 'skipped', text: reason }
: { : { name: 'failure', text: reason };
name: 'failure',
text: r.reason
? (r.reason && r.reason.stack) : ''
});
acc.push({ acc.push({
name: 'testcase', name: 'testcase',
attrs: { attrs: {

Loading…
Cancel
Save