[code-coverage] fix so tests work in windows
Use path.resolve, and trim end of scmFiles Signed-off-by: alde <r.dybeck@gmail.com>
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
import { parseString } from 'xml2js';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { Cobertura } from './cobertura';
|
||||
import { CoberturaXML } from './types';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
@@ -27,7 +28,12 @@ describe('convert cobertura', () => {
|
||||
let fixture: CoberturaXML;
|
||||
parseString(
|
||||
fs.readFileSync(
|
||||
`${__dirname}/../__fixtures__/cobertura-testdata-${idx}.xml`,
|
||||
path.resolve(
|
||||
__dirname,
|
||||
'..',
|
||||
'__fixtures__',
|
||||
`cobertura-testdata-${idx}.xml`,
|
||||
),
|
||||
),
|
||||
(_e, r) => {
|
||||
fixture = r;
|
||||
@@ -36,13 +42,23 @@ describe('convert cobertura', () => {
|
||||
const expected = JSON.parse(
|
||||
fs
|
||||
.readFileSync(
|
||||
`${__dirname}/../__fixtures__/cobertura-jsoncoverage-files-${idx}.json`,
|
||||
path.resolve(
|
||||
__dirname,
|
||||
'..',
|
||||
'__fixtures__',
|
||||
`cobertura-jsoncoverage-files-${idx}.json`,
|
||||
),
|
||||
)
|
||||
.toString(),
|
||||
);
|
||||
const scmFiles = fs
|
||||
.readFileSync(
|
||||
`${__dirname}/../__fixtures__/cobertura-sourcefiles-${idx}.txt`,
|
||||
path.resolve(
|
||||
__dirname,
|
||||
'..',
|
||||
'__fixtures__',
|
||||
`cobertura-sourcefiles-${idx}.txt`,
|
||||
),
|
||||
)
|
||||
.toString()
|
||||
.split('\n');
|
||||
|
||||
@@ -62,7 +62,9 @@ export class Cobertura implements Converter {
|
||||
}
|
||||
});
|
||||
|
||||
const currentFile = scmFiles.find(f => f.endsWith(packageAndFilename));
|
||||
const currentFile = scmFiles
|
||||
.map(f => f.trimEnd())
|
||||
.find(f => f.endsWith(packageAndFilename));
|
||||
this.logger.debug(`matched ${packageAndFilename} to ${currentFile}`);
|
||||
if (
|
||||
scmFiles.length === 0 ||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
import { parseString } from 'xml2js';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { Jacoco } from './jacoco';
|
||||
import { JacocoXML } from './types';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
@@ -25,7 +26,9 @@ describe('convert jacoco', () => {
|
||||
const converter = new Jacoco(getVoidLogger());
|
||||
let fixture: JacocoXML;
|
||||
parseString(
|
||||
fs.readFileSync(`${__dirname}/../__fixtures__/jacoco-testdata-1.xml`),
|
||||
fs.readFileSync(
|
||||
path.resolve(`${__dirname}/../__fixtures__/jacoco-testdata-1.xml`),
|
||||
),
|
||||
(_e, r) => {
|
||||
fixture = r;
|
||||
},
|
||||
@@ -33,12 +36,16 @@ describe('convert jacoco', () => {
|
||||
const expected = JSON.parse(
|
||||
fs
|
||||
.readFileSync(
|
||||
`${__dirname}/../__fixtures__/jacoco-jsoncoverage-files-1.json`,
|
||||
path.resolve(
|
||||
`${__dirname}/../__fixtures__/jacoco-jsoncoverage-files-1.json`,
|
||||
),
|
||||
)
|
||||
.toString(),
|
||||
);
|
||||
const scmFiles = fs
|
||||
.readFileSync(`${__dirname}/../__fixtures__/jacoco-sourcefiles-1.txt`)
|
||||
.readFileSync(
|
||||
path.resolve(`${__dirname}/../__fixtures__/jacoco-sourcefiles-1.txt`),
|
||||
)
|
||||
.toString()
|
||||
.split('\n');
|
||||
|
||||
|
||||
@@ -63,7 +63,9 @@ export class Jacoco implements Converter {
|
||||
});
|
||||
|
||||
const packageAndFilename = `${packageName}/${fileName}`;
|
||||
const currentFile = scmFiles.find(f => f.endsWith(packageAndFilename));
|
||||
const currentFile = scmFiles
|
||||
.map(f => f.trimEnd())
|
||||
.find(f => f.endsWith(packageAndFilename));
|
||||
this.logger.debug(`matched ${packageAndFilename} to ${currentFile}`);
|
||||
if (Object.keys(lineHits).length > 0 && currentFile) {
|
||||
jscov.push({
|
||||
|
||||
Reference in New Issue
Block a user