From 55efe5469ad77271f96155a3910ef866001e7c58 Mon Sep 17 00:00:00 2001 From: agracio Date: Mon, 18 Nov 2024 14:28:58 +0000 Subject: [PATCH] updating tests --- .github/workflows/main.yml | 3 ++- tests/common.js | 32 ++++++++++++++++++++++++++++++-- tests/teardown.js | 2 ++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 63f94e9..0847e96 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,8 +21,9 @@ jobs: runs-on: ${{ matrix.os }} name: test-${{ matrix.os }} strategy: + fail-fast: false matrix: - os: [macos-latest, ubuntu-latest] + os: [macos-latest, ubuntu-latest, windows-2022] steps: - name: Checkout code uses: actions/checkout@v4 diff --git a/tests/common.js b/tests/common.js index c284b08..b2e9417 100644 --- a/tests/common.js +++ b/tests/common.js @@ -4,11 +4,15 @@ const fs = require("fs"); const reportDir= './tests/data/result'; const outDir= './tests/data/tmp'; +const compareDir = './tests/data/compare'; function removeTempDir(){ if(fs.existsSync(outDir)){ fs.rmSync(outDir, { recursive: true, force: true }); } + if(fs.existsSync(compareDir)){ + fs.rmSync(compareDir, { recursive: true, force: true }); + } } function getFilename(file){ @@ -29,6 +33,26 @@ function createOptions(file, type){ } } +/** + * @param {TestReportConverterOptions} options + * @param {string?} reportFilename + * @param {Boolean?} compareJunit + */ +function createCompareFiles(options, reportFilename, compareJunit){ + + if(!fs.existsSync(compareDir)){ + fs.mkdirSync(compareDir); + } + + let report = fs.readFileSync(path.join(reportDir, reportFilename ?? options.reportFilename), 'utf8'); + fs.writeFileSync(path.join(compareDir, reportFilename ?? options.reportFilename), report, 'utf8') + + if(compareJunit){ + let junitReport = fs.readFileSync(path.join(reportDir, options.junitReportFilename), 'utf8'); + fs.writeFileSync(path.join(compareDir, options.junitReportFilename), junitReport, 'utf8') + } +} + /** * @param {TestReportConverterOptions} options * @param {string?} reportFilename @@ -36,13 +60,16 @@ function createOptions(file, type){ */ function compare(options, reportFilename, compareJunit){ - let createdReport = fs.readFileSync(path.join(outDir, options.reportFilename), 'utf8'); + // rewrite compare files for test system compatibility + createCompareFiles(options, reportFilename, compareJunit); + + let createdReport = fs.readFileSync(path.join(compareDir, reportFilename ?? options.reportFilename), 'utf8'); let report = fs.readFileSync(path.join(reportDir, reportFilename ?? options.reportFilename), 'utf8'); expect(createdReport.replaceAll(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/g,'')).toBe(report.replaceAll(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/g,'')); if(compareJunit){ - let junitCreatedReport = fs.readFileSync(path.join(outDir, options.junitReportFilename), 'utf8'); + let junitCreatedReport = fs.readFileSync(path.join(compareDir, options.junitReportFilename), 'utf8'); let junitReport = fs.readFileSync(path.join(reportDir, options.junitReportFilename), 'utf8'); expect(junitCreatedReport).toBe(junitReport); @@ -50,6 +77,7 @@ function compare(options, reportFilename, compareJunit){ } exports.outDir = outDir; +exports.compareDir = compareDir; exports.createOptions = createOptions; exports.compare = compare; exports.removeTempDir = removeTempDir; diff --git a/tests/teardown.js b/tests/teardown.js index 3278a2c..6a237c9 100644 --- a/tests/teardown.js +++ b/tests/teardown.js @@ -1,4 +1,6 @@ const common = require("./common"); +const fs = require("fs"); + const teardown = async () => { common.removeTempDir(); }