diff --git a/.changeset/rotten-cups-bow.md b/.changeset/rotten-cups-bow.md new file mode 100644 index 0000000000..967681171d --- /dev/null +++ b/.changeset/rotten-cups-bow.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-code-coverage': patch +'@backstage/plugin-code-coverage-backend': patch +--- + +Update tests to function in windows diff --git a/plugins/code-coverage-backend/src/service/converter/cobertura.test.ts b/plugins/code-coverage-backend/src/service/converter/cobertura.test.ts index 72d4018f94..0e67d35d7a 100644 --- a/plugins/code-coverage-backend/src/service/converter/cobertura.test.ts +++ b/plugins/code-coverage-backend/src/service/converter/cobertura.test.ts @@ -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'); diff --git a/plugins/code-coverage-backend/src/service/converter/cobertura.ts b/plugins/code-coverage-backend/src/service/converter/cobertura.ts index 02ac187387..fcaea839ee 100644 --- a/plugins/code-coverage-backend/src/service/converter/cobertura.ts +++ b/plugins/code-coverage-backend/src/service/converter/cobertura.ts @@ -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 || diff --git a/plugins/code-coverage-backend/src/service/converter/jacoco.test.ts b/plugins/code-coverage-backend/src/service/converter/jacoco.test.ts index 48202748da..0507cf3a98 100644 --- a/plugins/code-coverage-backend/src/service/converter/jacoco.test.ts +++ b/plugins/code-coverage-backend/src/service/converter/jacoco.test.ts @@ -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'); diff --git a/plugins/code-coverage-backend/src/service/converter/jacoco.ts b/plugins/code-coverage-backend/src/service/converter/jacoco.ts index 4c554fec91..e4a41f8bc4 100644 --- a/plugins/code-coverage-backend/src/service/converter/jacoco.ts +++ b/plugins/code-coverage-backend/src/service/converter/jacoco.ts @@ -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({