Skip to content

Commit

Permalink
Use "replaceAll()"
Browse files Browse the repository at this point in the history
  • Loading branch information
munderseth committed Jul 15, 2024
1 parent 543fd95 commit 447adc8
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 78 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cypress-xml-reporter",
"version": "1.0.1",
"version": "1.0.2",
"description": "A JUnit XML reporter for Cypress that includes screenshots, videos, and logs.",
"main": "src/reporter.js",
"scripts": {
Expand Down
4 changes: 3 additions & 1 deletion src/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ function createTestRecord(test, specRelativePath) {
}

function normalizePath(pathString) {
return pathString.split(path.sep).join('/');
if (path.sep !== '/') {
return pathString.replaceAll(path.sep, '/');
}
}

function CypressXML(runner, options) {
Expand Down
15 changes: 7 additions & 8 deletions tests/test.desc-desc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const expect = require("chai").expect;
const parseString = require('xml2js').parseString;
const path = require('path');
const fs = require('fs');
const helpers = require('./test_helper');

/**
* Setting
Expand Down Expand Up @@ -41,7 +40,7 @@ describe(testName, () => {
expect(suites[0].$.tests).to.equal('0');
});
it('File Name', () => {
expect(suites[1].$.file).to.equal(helpers.normalizePath(testFile));
expect(suites[1].$.file).to.equal(testFile.replaceAll(path.sep, '/'));
});
});
describe('TEST1', () => {
Expand All @@ -52,11 +51,11 @@ describe(testName, () => {
expect(suites[1].$.tests).to.equal('3');
});
it('File Name', () => {
expect(suites[1].$.file).to.equal(helpers.normalizePath(testFile));
expect(suites[1].$.file).to.equal(testFile.replaceAll(path.sep, '/'));
});
it('System-out', () => {
var systemout = suites[1]['system-out'][0];
expect(systemout).to.equal('[[ATTACHMENT|'+helpers.normalizePath(videoFile)+']]');
expect(systemout).to.equal('[[ATTACHMENT|'+videoFile.replaceAll(path.sep, '/')+']]');
});
describe('Testcases', ()=> {
var testcases;
Expand All @@ -74,7 +73,7 @@ describe(testName, () => {
});
it('"case3" Failure', () => {
var systemout = testcases[2]['system-out'][0];
expect(systemout).to.equal('[[ATTACHMENT|'+helpers.normalizePath(screenshotFile1)+']]');
expect(systemout).to.equal('[[ATTACHMENT|'+screenshotFile1.replaceAll(path.sep, '/')+']]');
})
});
});
Expand All @@ -86,11 +85,11 @@ describe(testName, () => {
expect(suites[2].$.tests).to.equal('3');
});
it('File Name', () => {
expect(suites[2].$.file).to.equal(helpers.normalizePath(testFile));
expect(suites[2].$.file).to.equal(testFile.replaceAll(path.sep, '/'));
});
it('System-out', () => {
var systemout = suites[2]['system-out'][0];
expect(systemout).to.equal('[[ATTACHMENT|'+helpers.normalizePath(videoFile)+']]');
expect(systemout).to.equal('[[ATTACHMENT|'+videoFile.replaceAll(path.sep, '/')+']]');
});
describe('Testcases', ()=> {
var testcases;
Expand All @@ -108,7 +107,7 @@ describe(testName, () => {
});
it('"case3" Failure', () => {
var systemout = testcases[2]['system-out'][0];
expect(systemout).to.equal('[[ATTACHMENT|'+helpers.normalizePath(screenshotFile2)+']]');
expect(systemout).to.equal('[[ATTACHMENT|'+screenshotFile2.replaceAll(path.sep, '/')+']]');
})
});
});
Expand Down
3 changes: 1 addition & 2 deletions tests/test.desc-fixture-hook-failure.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const expect = require("chai").expect;
const parseString = require('xml2js').parseString;
const path = require('path');
const fs = require('fs');
const helpers = require('./test_helper');

/**
* Setting
Expand Down Expand Up @@ -55,7 +54,7 @@ describe(testName, () => {
expect(suites[0].$.tests).to.equal('0');
});
it('File Name', () => {
expect(suites[1].$.file).to.equal(helpers.normalizePath(testFile));
expect(suites[1].$.file).to.equal(testFile.replaceAll(path.sep, '/'));
});
});
});
10 changes: 4 additions & 6 deletions tests/test.desc-nest-desc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ const expect = require("chai").expect;
const parseString = require('xml2js').parseString;
const path = require('path');
const fs = require('fs');
const helpers = require('./test_helper');


/**
* Setting
Expand Down Expand Up @@ -57,7 +55,7 @@ describe(testName, () => {
expect(suites[0].$.tests).to.equal('0');
});
it('File Name', () => {
expect(suites[1].$.file).to.equal(helpers.normalizePath(testFile));
expect(suites[1].$.file).to.equal(testFile.replaceAll(path.sep, '/'));
});
});
describe('TEST1', () => {
Expand All @@ -68,11 +66,11 @@ describe(testName, () => {
expect(suites[1].$.tests).to.equal('6');
});
it('File Name', () => {
expect(suites[1].$.file).to.equal(helpers.normalizePath(testFile));
expect(suites[1].$.file).to.equal(testFile.replaceAll(path.sep, '/'));
});
it('System-out', () => {
var systemout = suites[1]['system-out'][0];
expect(systemout).to.equal('[[ATTACHMENT|'+helpers.normalizePath(videoFile)+']]');
expect(systemout).to.equal('[[ATTACHMENT|'+videoFile.replaceAll(path.sep, '/')+']]');
});
describe('Testcases', ()=> {
var testcases;
Expand All @@ -99,7 +97,7 @@ describe(testName, () => {
});
it('"NEST -- case3" Failure', () => {
var systemout = testcases[5]['system-out'][0];
expect(systemout).to.equal('[[ATTACHMENT|'+helpers.normalizePath(screenshotFile)+']]');
expect(systemout).to.equal('[[ATTACHMENT|'+screenshotFile.replaceAll(path.sep, '/')+']]');
})
});
});
Expand Down
13 changes: 6 additions & 7 deletions tests/test.desc-nest-nest-desc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const expect = require("chai").expect;
const parseString = require('xml2js').parseString;
const path = require('path');
const fs = require('fs');
const helpers = require('./test_helper');

/**
* Setting
Expand Down Expand Up @@ -58,7 +57,7 @@ describe(testName, () => {
expect(suites[0].$.tests).to.equal('0');
});
it('File Name', () => {
expect(suites[1].$.file).to.equal(helpers.normalizePath(testFile));
expect(suites[1].$.file).to.equal(testFile.replaceAll(path.sep, '/'));
});
});
describe('TEST1', () => {
Expand All @@ -69,11 +68,11 @@ describe(testName, () => {
expect(suites[1].$.tests).to.equal('9');
});
it('File Name', () => {
expect(suites[1].$.file).to.equal(helpers.normalizePath(testFile));
expect(suites[1].$.file).to.equal(testFile.replaceAll(path.sep, '/'));
});
it('System-out', () => {
var systemout = suites[1]['system-out'][0];
expect(systemout).to.equal('[[ATTACHMENT|'+helpers.normalizePath(videoFile)+']]');
expect(systemout).to.equal('[[ATTACHMENT|'+videoFile.replaceAll(path.sep, '/')+']]');
});
describe('Testcases', ()=> {
var testcases;
Expand All @@ -91,7 +90,7 @@ describe(testName, () => {
});
it('"case3" Failure', () => {
var systemout = testcases[2]['system-out'][0];
expect(systemout).to.equal('[[ATTACHMENT|'+helpers.normalizePath(screenshotFile1)+']]');
expect(systemout).to.equal('[[ATTACHMENT|'+screenshotFile1.replaceAll(path.sep, '/')+']]');
});
it('"NEST1 -- case1" name', () => {
expect(testcases[3].$.name).to.equal('NEST1 -- case1');
Expand All @@ -104,7 +103,7 @@ describe(testName, () => {
});
it('"NEST1 -- case3" Failure', () => {
var systemout = testcases[5]['system-out'][0];
expect(systemout).to.equal('[[ATTACHMENT|'+helpers.normalizePath(screenshotFile2)+']]');
expect(systemout).to.equal('[[ATTACHMENT|'+screenshotFile2.replaceAll(path.sep, '/')+']]');
});
it('"NEST1 -- NEST2 -- case1" name', () => {
expect(testcases[6].$.name).to.equal('NEST1 -- NEST2 -- case1');
Expand All @@ -117,7 +116,7 @@ describe(testName, () => {
});
it('"NEST1 -- NEST2 -- case3" Failure', () => {
var systemout = testcases[8]['system-out'][0];
expect(systemout).to.equal('[[ATTACHMENT|'+helpers.normalizePath(screenshotFile3)+']]');
expect(systemout).to.equal('[[ATTACHMENT|'+screenshotFile3.replaceAll(path.sep, '/')+']]');
});

});
Expand Down
6 changes: 2 additions & 4 deletions tests/test.desc-nofailures.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ const expect = require("chai").expect;
const parseString = require('xml2js').parseString;
const path = require('path');
const fs = require('fs');
const helpers = require('./test_helper');


/**
* Setting
Expand Down Expand Up @@ -55,7 +53,7 @@ describe(testName, () => {
expect(suites[0].$.tests).to.equal('0');
});
it('File Name', () => {
expect(suites[1].$.file).to.equal(helpers.normalizePath(testFile));
expect(suites[1].$.file).to.equal(testFile.replaceAll(path.sep, '/'));
});
});
describe('TEST1', () => {
Expand All @@ -66,7 +64,7 @@ describe(testName, () => {
expect(suites[1].$.tests).to.equal('3');
});
it('File Name', () => {
expect(suites[1].$.file).to.equal(helpers.normalizePath(testFile));
expect(suites[1].$.file).to.equal(testFile.replaceAll(path.sep, '/'));
});
it('System-out', () => {
var systemout = suites[1]['system-out'][0];
Expand Down
6 changes: 2 additions & 4 deletions tests/test.desc-nofailures.log.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ const expect = require("chai").expect;
const parseString = require('xml2js').parseString;
const path = require('path');
const fs = require('fs');
const helpers = require('./test_helper');


/**
* Setting
Expand Down Expand Up @@ -57,7 +55,7 @@ describe(testName, () => {
expect(suites[0].$.tests).to.equal('0');
});
it('File Name', () => {
expect(suites[1].$.file).to.equal(helpers.normalizePath(testFile));
expect(suites[1].$.file).to.equal(testFile.replaceAll(path.sep, '/'));
});
});
describe('TEST1', () => {
Expand All @@ -68,7 +66,7 @@ describe(testName, () => {
expect(suites[1].$.tests).to.equal('3');
});
it('File Name', () => {
expect(suites[1].$.file).to.equal(helpers.normalizePath(testFile));
expect(suites[1].$.file).to.equal(testFile.replaceAll(path.sep, '/'));
});
it('System-out', () => {
var systemout = suites[1]['system-out'][0];
Expand Down
7 changes: 3 additions & 4 deletions tests/test.desc-pending.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const expect = require("chai").expect;
const parseString = require('xml2js').parseString;
const path = require('path');
const fs = require('fs');
const helpers = require('./test_helper');

/**
* Setting
Expand Down Expand Up @@ -56,7 +55,7 @@ describe(testName, () => {
expect(suites[0].$.tests).to.equal('0');
});
it('File Name', () => {
expect(suites[1].$.file).to.equal(helpers.normalizePath(testFile));
expect(suites[1].$.file).to.equal(testFile.replaceAll(path.sep, '/'));
});
});
describe('TEST1', () => {
Expand All @@ -73,11 +72,11 @@ describe(testName, () => {
expect(suites[1].$.skipped).to.equal('3');
});
it('File Name', () => {
expect(suites[1].$.file).to.equal(helpers.normalizePath(testFile));
expect(suites[1].$.file).to.equal(testFile.replaceAll(path.sep, '/'));
});
it('System-out', () => {
var systemout = suites[1]['system-out'][0];
expect(systemout).to.equal('[[ATTACHMENT|'+helpers.normalizePath(videoFile)+']]');
expect(systemout).to.equal('[[ATTACHMENT|'+videoFile.replaceAll(path.sep, '/')+']]');
});
describe('Testcases', ()=> {
var testcases;
Expand Down
9 changes: 4 additions & 5 deletions tests/test.desc-testname-chars.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const expect = require("chai").expect;
const parseString = require('xml2js').parseString;
const path = require('path');
const fs = require('fs');
const helpers = require('./test_helper');

/**
* Setting
Expand Down Expand Up @@ -56,7 +55,7 @@ describe(testName, () => {
expect(suites[0].$.tests).to.equal('0');
});
it('File Name', () => {
expect(suites[1].$.file).to.equal(helpers.normalizePath(testFile));
expect(suites[1].$.file).to.equal(testFile.replaceAll(path.sep, '/'));
});
});
describe('"TEST SUITE" with Quotes and Slash', () => {
Expand All @@ -67,11 +66,11 @@ describe(testName, () => {
expect(suites[1].$.tests).to.equal('3');
});
it('File Name', () => {
expect(suites[1].$.file).to.equal(helpers.normalizePath(testFile));
expect(suites[1].$.file).to.equal(testFile.replaceAll(path.sep, '/'));
});
it('System-out', () => {
var systemout = suites[1]['system-out'][0];
expect(systemout).to.equal('[[ATTACHMENT|'+helpers.normalizePath(videoFile)+']]');
expect(systemout).to.equal('[[ATTACHMENT|'+videoFile.replaceAll(path.sep, '/')+']]');
});
describe('Testcases', ()=> {
var testcases;
Expand All @@ -89,7 +88,7 @@ describe(testName, () => {
});
it('"case3" name with quotes and slash with failure', () => {
var systemout = testcases[2]['system-out'][0];
expect(systemout).to.equal('[[ATTACHMENT|'+helpers.normalizePath(screenshotFile)+']]');
expect(systemout).to.equal('[[ATTACHMENT|'+screenshotFile.replaceAll(path.sep, '/')+']]');
})
});
});
Expand Down
9 changes: 4 additions & 5 deletions tests/test.desc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const expect = require("chai").expect;
const parseString = require('xml2js').parseString;
const path = require('path');
const fs = require('fs');
const helpers = require('./test_helper');

/**
* Setting
Expand Down Expand Up @@ -56,7 +55,7 @@ describe(testName, () => {
expect(suites[0].$.tests).to.equal('0');
});
it('File Name', () => {
expect(suites[1].$.file).to.equal(helpers.normalizePath(testFile));
expect(suites[1].$.file).to.equal(testFile.replaceAll(path.sep, '/'));
});
});
describe('TEST1', () => {
Expand All @@ -67,11 +66,11 @@ describe(testName, () => {
expect(suites[1].$.tests).to.equal('3');
});
it('File Name', () => {
expect(suites[1].$.file).to.equal(helpers.normalizePath(testFile));
expect(suites[1].$.file).to.equal(testFile.replaceAll(path.sep, '/'));
});
it('System-out', () => {
var systemout = suites[1]['system-out'][0];
expect(systemout).to.equal('[[ATTACHMENT|'+helpers.normalizePath(videoFile)+']]');
expect(systemout).to.equal('[[ATTACHMENT|'+videoFile.replaceAll(path.sep, '/')+']]');
});
describe('Testcases', ()=> {
var testcases;
Expand All @@ -89,7 +88,7 @@ describe(testName, () => {
});
it('"case3" Failure', () => {
var systemout = testcases[2]['system-out'][0];
expect(systemout).to.equal('[[ATTACHMENT|'+helpers.normalizePath(screenshotFile)+']]');
expect(systemout).to.equal('[[ATTACHMENT|'+screenshotFile.replaceAll(path.sep, '/')+']]');
})
});
});
Expand Down
Loading

0 comments on commit 447adc8

Please sign in to comment.