Skip to content

Commit 052f6ab

Browse files
CrisDan1905Cristian Danilo Gutiérrez
andauthored
fix: duplicated files when "skipFilesWithNoCoverage=false" on windows
Co-authored-by: Cristian Danilo Gutiérrez <cristian.gutierrez@globant.com>
1 parent 5f3f030 commit 052f6ab

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function fixPathSeparators(filePath) {
1717
const isWin = process.platform.startsWith('win');
1818
// Workaround for https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues/9
1919
if (isWin && filePath) {
20-
return filePath.replace(/\//g, '\\');
20+
return filePath.replace(/\//g, '\\').replace(/\\\\/g, '\\');
2121
}
2222

2323
return filePath;

test/util.spec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const { expect } = require('chai');
22
const { fixWebpackSourcePaths } = require('../src/util');
3+
const { fixPathSeparators } = require('../src/util');
34

45
const originalPlatform = process.platform;
56

@@ -244,4 +245,34 @@ describe('util', () => {
244245
).to.deep.equal(output);
245246
});
246247
});
248+
249+
describe('fixPathSeparators', () => {
250+
let input;
251+
252+
beforeEach(() => {
253+
input =
254+
'\\Users\\mattlewis\\Code\\/open-source/karma-coverage-istanbul-reporter\\test\\fixtures\\typescript';
255+
});
256+
257+
it('Should transform any forwardslash into backslash and remove any leftover backslash if OS is Windows', () => {
258+
Object.defineProperty(process, 'platform', {
259+
value: 'win32',
260+
});
261+
262+
const output =
263+
'\\Users\\mattlewis\\Code\\open-source\\karma-coverage-istanbul-reporter\\test\\fixtures\\typescript';
264+
265+
expect(fixPathSeparators(input)).to.deep.equal(output);
266+
});
267+
268+
it('Should not transform any forwardslash into backslash if OS is different from Windows', () => {
269+
Object.defineProperty(process, 'platform', {
270+
value: 'linux',
271+
});
272+
273+
const output = input;
274+
275+
expect(fixPathSeparators(input)).to.deep.equal(output);
276+
});
277+
});
247278
});

0 commit comments

Comments
 (0)