Skip to content

Commit 8e3205f

Browse files
authored
Merge pull request #70 from mtsmfm/fix-filepath
Fix to output relative path correctly
2 parents 00c4807 + bcdaa23 commit 8e3205f

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

__tests__/buildJsonResults.test.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,28 @@ const constants = require('../constants/index');
66
describe('buildJsonResults', () => {
77
it('should contain number of tests in testSuite', () => {
88
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
9-
const jsonResults = buildJsonResults(noFailingTestsReport, '', constants.DEFAULT_OPTIONS);
9+
const jsonResults = buildJsonResults(noFailingTestsReport, '/', constants.DEFAULT_OPTIONS);
1010

1111
expect(jsonResults.testsuites[1].testsuite[0]._attr.tests).toBe(1);
1212
});
1313

1414
it('should contain number of tests in testSuites', () => {
1515
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
16-
const jsonResults = buildJsonResults(noFailingTestsReport, '', constants.DEFAULT_OPTIONS);
16+
const jsonResults = buildJsonResults(noFailingTestsReport, '/', constants.DEFAULT_OPTIONS);
1717

1818
expect(jsonResults.testsuites[0]._attr.tests).toBe(1);
1919
});
2020

2121
it('should return the proper name from ancestorTitles when usePathForSuiteName is "false"', () => {
2222
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
23-
const jsonResults = buildJsonResults(noFailingTestsReport, '', constants.DEFAULT_OPTIONS);
23+
const jsonResults = buildJsonResults(noFailingTestsReport, '/', constants.DEFAULT_OPTIONS);
2424

2525
expect(jsonResults.testsuites[1].testsuite[0]._attr.name).toBe('foo');
2626
});
2727

2828
it('should return the proper filename when suiteNameTemplate is "{filename}"', () => {
2929
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
30-
const jsonResults = buildJsonResults(noFailingTestsReport, '',
30+
const jsonResults = buildJsonResults(noFailingTestsReport, '/',
3131
Object.assign({}, constants.DEFAULT_OPTIONS, {
3232
suiteNameTemplate: "{filename}"
3333
}));
@@ -36,7 +36,7 @@ describe('buildJsonResults', () => {
3636

3737
it('should support suiteNameTemplate as function', () => {
3838
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
39-
const jsonResults = buildJsonResults(noFailingTestsReport, '',
39+
const jsonResults = buildJsonResults(noFailingTestsReport, '/',
4040
Object.assign({}, constants.DEFAULT_OPTIONS, {
4141
suiteNameTemplate: (vars) => {
4242
return 'function called with vars: ' + Object.keys(vars).join(', ');
@@ -48,7 +48,7 @@ describe('buildJsonResults', () => {
4848

4949
it('should return the proper filename when classNameTemplate is "{filename}"', () => {
5050
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
51-
const jsonResults = buildJsonResults(noFailingTestsReport, '',
51+
const jsonResults = buildJsonResults(noFailingTestsReport, '/',
5252
Object.assign({}, constants.DEFAULT_OPTIONS, {
5353
classNameTemplate: "{filename}"
5454
}));
@@ -57,7 +57,7 @@ describe('buildJsonResults', () => {
5757

5858
it('should support return the function result when classNameTemplate is a function', () => {
5959
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
60-
const jsonResults = buildJsonResults(noFailingTestsReport, '',
60+
const jsonResults = buildJsonResults(noFailingTestsReport, '/',
6161
Object.assign({}, constants.DEFAULT_OPTIONS, {
6262
classNameTemplate: (vars) => {
6363
return 'function called with vars: ' + Object.keys(vars).join(', ');
@@ -69,38 +69,38 @@ describe('buildJsonResults', () => {
6969

7070
it('should return the proper filepath when titleTemplate is "{filepath}"', () => {
7171
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
72-
const jsonResults = buildJsonResults(noFailingTestsReport, '',
72+
const jsonResults = buildJsonResults(noFailingTestsReport, '/',
7373
Object.assign({}, constants.DEFAULT_OPTIONS, {
7474
titleTemplate: "{filepath}"
7575
}));
76-
expect(jsonResults.testsuites[1].testsuite[1].testcase[0]._attr.name).toBe('/path/to/test/__tests__/foo.test.js');
76+
expect(jsonResults.testsuites[1].testsuite[1].testcase[0]._attr.name).toBe('path/to/test/__tests__/foo.test.js');
7777
});
7878

7979
it('should return the proper filepath when suiteNameTemplate is "{filepath}" and usePathForSuiteName is "false"', () => {
8080
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
81-
const jsonResults = buildJsonResults(noFailingTestsReport, '',
81+
const jsonResults = buildJsonResults(noFailingTestsReport, '/',
8282
Object.assign({}, constants.DEFAULT_OPTIONS, {
8383
suiteNameTemplate: "{filepath}"
8484
}));
85-
expect(jsonResults.testsuites[1].testsuite[0]._attr.name).toBe('/path/to/test/__tests__/foo.test.js');
85+
expect(jsonResults.testsuites[1].testsuite[0]._attr.name).toBe('path/to/test/__tests__/foo.test.js');
8686
});
8787

8888
it('should return the proper name from ancestorTitles when suiteNameTemplate is set to "{title}" and usePathForSuiteName is "true"', () => {
8989
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
90-
const jsonResults = buildJsonResults(noFailingTestsReport, '',
90+
const jsonResults = buildJsonResults(noFailingTestsReport, '/',
9191
Object.assign({}, constants.DEFAULT_OPTIONS, {
9292
usePathForSuiteName: "true"
9393
}));
94-
expect(jsonResults.testsuites[1].testsuite[0]._attr.name).toBe('/path/to/test/__tests__/foo.test.js');
94+
expect(jsonResults.testsuites[1].testsuite[0]._attr.name).toBe('path/to/test/__tests__/foo.test.js');
9595
});
9696

9797
it('should return the proper name from testFilePath when usePathForSuiteName is "true"; no appDirectory set', () => {
9898
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
99-
const jsonResults = buildJsonResults(noFailingTestsReport, '',
99+
const jsonResults = buildJsonResults(noFailingTestsReport, '/',
100100
Object.assign({}, constants.DEFAULT_OPTIONS, {
101101
usePathForSuiteName: "true"
102102
}));
103-
expect(jsonResults.testsuites[1].testsuite[0]._attr.name).toBe('/path/to/test/__tests__/foo.test.js');
103+
expect(jsonResults.testsuites[1].testsuite[0]._attr.name).toBe('path/to/test/__tests__/foo.test.js');
104104
});
105105

106106
it('should return the proper name from testFilePath when usePathForSuiteName is "true"; with appDirectory set', () => {
@@ -109,19 +109,19 @@ describe('buildJsonResults', () => {
109109
Object.assign({}, constants.DEFAULT_OPTIONS, {
110110
usePathForSuiteName: "true"
111111
}));
112-
expect(jsonResults.testsuites[1].testsuite[0]._attr.name).toBe('/__tests__/foo.test.js');
112+
expect(jsonResults.testsuites[1].testsuite[0]._attr.name).toBe('__tests__/foo.test.js');
113113
});
114114

115115
it('should return the proper classname when ancestorSeparator is default', () => {
116116
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
117-
const jsonResults = buildJsonResults(noFailingTestsReport, '',
117+
const jsonResults = buildJsonResults(noFailingTestsReport, '/',
118118
Object.assign({}, constants.DEFAULT_OPTIONS));
119119
expect(jsonResults.testsuites[1].testsuite[1].testcase[0]._attr.classname).toBe('foo baz should bar');
120120
});
121121

122122
it('should return the proper classname when ancestorSeparator is customized', () => {
123123
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
124-
const jsonResults = buildJsonResults(noFailingTestsReport, '',
124+
const jsonResults = buildJsonResults(noFailingTestsReport, '/',
125125
Object.assign({}, constants.DEFAULT_OPTIONS, {
126126
ancestorSeparator: " › "
127127
}));
@@ -146,7 +146,7 @@ describe('buildJsonResults', () => {
146146
const startDate = new Date(multiProjectNoFailingTestsReport.startTime);
147147
spyOn(Date, 'now').and.returnValue(startDate.getTime() + 1234);
148148

149-
const jsonResults = buildJsonResults(multiProjectNoFailingTestsReport, '',
149+
const jsonResults = buildJsonResults(multiProjectNoFailingTestsReport, '/',
150150
Object.assign({}, constants.DEFAULT_OPTIONS, {
151151
suiteNameTemplate: "{displayName}-foo",
152152
titleTemplate: "{displayName}-foo"

utils/buildJsonResults.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ module.exports = function (report, appDirectory, options) {
6767
}
6868

6969
// Build variables for suite name
70-
const filepath = suite.testFilePath.replace(appDirectory, '');
70+
const filepath = path.relative(appDirectory, suite.testFilePath);
7171
const filename = path.basename(filepath);
7272
const suiteTitle = suite.testResults[0].ancestorTitles[0];
7373
const displayName = suite.displayName;

0 commit comments

Comments
 (0)