Skip to content

Commit

Permalink
updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
agracio committed Nov 18, 2024
1 parent 4d55e4d commit 55efe54
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 30 additions & 2 deletions tests/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -29,27 +33,51 @@ 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
* @param {Boolean?} compareJunit
*/
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);
}
}

exports.outDir = outDir;
exports.compareDir = compareDir;
exports.createOptions = createOptions;
exports.compare = compare;
exports.removeTempDir = removeTempDir;
2 changes: 2 additions & 0 deletions tests/teardown.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const common = require("./common");
const fs = require("fs");

const teardown = async () => {
common.removeTempDir();
}
Expand Down

0 comments on commit 55efe54

Please sign in to comment.