Skip to content

Commit

Permalink
Start migration of tests to electron-mocha (#1061)
Browse files Browse the repository at this point in the history
* Updating mocha, electron mocha and babel commonjs

* Migrating time-math to electron-mocha

* Properly generating coverage report from c8

* Using istanbul-merge to merge coverage reports

* Including other extensions in jest coverage

* Removing trailing comma
  • Loading branch information
araujoarthur0 authored Feb 3, 2024
1 parent 8f2ae80 commit b3fd77f
Show file tree
Hide file tree
Showing 9 changed files with 639 additions and 1,005 deletions.
6 changes: 6 additions & 0 deletions .c8rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"all": true,
"include": ["js/**.{cjs,js,mjs}", "js/classes/**.{cjs,js,mjs}", "src/**.{cjs,js,mjs}", "./main.{cjs,js,mjs}"],
"reporter": ["clover", "json", "lcov", "text"],
"reportsDir": "coverage_c8"
}
7 changes: 4 additions & 3 deletions .github/workflows/Checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,18 @@ jobs:
export DISPLAY=':99'
fi
npm run test:electron-mocha-main
npm run test:jest
- name: ' Create COV_REPORT'
run: |
mkdir COV_REPORT
- name: ' Copy jest results'
- name: ' Merge coverage results'
run: |
cp coverage_jest/coverage-final.json COV_REPORT/coverage-final-jest.json
npx istanbul-merge --out COV_REPORT/coverage-final.json coverage_c8/coverage-final.json coverage_jest/coverage-final.json
- name: ' CodeCov'
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: COV_REPORT/coverage-final-jest.json
files: COV_REPORT/coverage-final.json
name: codecov-${{ matrix.os }}
verbose: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ lib-cov

# Coverage directory used by tools like istanbul
coverage
coverage_c8
coverage_jest
*.lcov

Expand Down
52 changes: 25 additions & 27 deletions __tests__/__main__/time-math.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/* eslint-disable no-undef */
'use strict';

const assert = require('assert');
import assert from 'assert';

import {
diffDays,
hourToMinutes,
isNegative,
multiplyTime,
minutesToHourFormatted,
multiplyTime,
subtractTime,
sumTime,
validateDate,
validateTime,
hourToMinutes,
diffDays,
validateDate
} from '../../js/time-math.js';

const date1 = new Date(-349891200000);
Expand All @@ -21,29 +21,27 @@ const date3 = new Date();

describe('Time Math Functions', () =>
{

describe('Difference between two days', () =>
{
test('expect diffDays 22350', () =>
it('expect diffDays 22350', () =>
{
assert.strictEqual(diffDays(date1, date2), 22350);
});

test('expect diffDays greater than 0', () =>
it('expect diffDays greater than 0', () =>
{
assert.strictEqual(diffDays(date1, date3) > 0, true);
});

});

describe('Determine negative dates', () =>
{
test('date1 Should not be negative', () =>
it('date1 Should not be negative', () =>
{
assert.strictEqual(isNegative(date2), false);
});

test('-date2 Should be negative', () =>
it('-date2 Should be negative', () =>
{
assert.strictEqual(isNegative('-' + date2), true);
});
Expand All @@ -52,31 +50,31 @@ describe('Time Math Functions', () =>

describe('Minutes formatted to HH:MM', () =>
{
test('0 should return 00:00', () =>
it('0 should return 00:00', () =>
{
assert.strictEqual(minutesToHourFormatted(0), '00:00');
assert.strictEqual(minutesToHourFormatted(-0), '00:00');
});

test('1 should return 00:01', () =>
it('1 should return 00:01', () =>
{
assert.strictEqual(minutesToHourFormatted(1), '00:01');
assert.strictEqual(minutesToHourFormatted(-1), '-00:01');
});

test('59 should return 00:59', () =>
it('59 should return 00:59', () =>
{
assert.strictEqual(minutesToHourFormatted(59), '00:59');
assert.strictEqual(minutesToHourFormatted(-59), '-00:59');
});

test('60 should return 01:00', () =>
it('60 should return 01:00', () =>
{
assert.strictEqual(minutesToHourFormatted(60), '01:00');
assert.strictEqual(minutesToHourFormatted(-60), '-01:00');
});

test('61 should return 01:01', () =>
it('61 should return 01:01', () =>
{
assert.strictEqual(minutesToHourFormatted(61), '01:01');
assert.strictEqual(minutesToHourFormatted(-61), '-01:01');
Expand All @@ -87,28 +85,28 @@ describe('Time Math Functions', () =>
describe('HH:MM formatted to minutes', () =>
{

test('00:00 should return 0', () =>
it('00:00 should return 0', () =>
{
assert.strictEqual(hourToMinutes('00:00'), 0);
assert.strictEqual(hourToMinutes('-00:00') < 1, true);
});

test('01:01 should return 61', () =>
it('01:01 should return 61', () =>
{
assert.strictEqual(hourToMinutes('01:01'), 61);
assert.strictEqual(hourToMinutes('-01:01'), -61);
});
test('00:01 should return 1', () =>
it('00:01 should return 1', () =>
{
assert.strictEqual(hourToMinutes('00:01'), 1);
assert.strictEqual(hourToMinutes('-00:01'), -1);
});
test('00:59 should return 59', () =>
it('00:59 should return 59', () =>
{
assert.strictEqual(hourToMinutes('00:59'), 59);
assert.strictEqual(hourToMinutes('-00:59'), -59);
});
test('01:00 should return 60', () =>
it('01:00 should return 60', () =>
{
assert.strictEqual(hourToMinutes('01:00'), 60);
assert.strictEqual(hourToMinutes('-01:00'), -60);
Expand All @@ -118,14 +116,14 @@ describe('Time Math Functions', () =>
// Multiply time
describe('Multiply Time', () =>
{
test('01:00 * 10 should be 10:00', () =>
it('01:00 * 10 should be 10:00', () =>
{
assert.strictEqual(multiplyTime('01:00', 10), '10:00');
assert.strictEqual(multiplyTime('-01:00', 10), '-10:00');
assert.strictEqual(multiplyTime('01:00', -10), '-10:00');
});

test('00:60 * 1 should be 01:00', () =>
it('00:60 * 1 should be 01:00', () =>
{
assert.strictEqual(multiplyTime('00:60', 1), '01:00');
assert.strictEqual(multiplyTime('-00:60', 1), '-01:00');
Expand All @@ -134,7 +132,7 @@ describe('Time Math Functions', () =>
});

// Subtract time
test('subtractTime(HH:MM, HH:MM)', () =>
it('subtractTime(HH:MM, HH:MM)', () =>
{
assert.strictEqual(subtractTime('1:00', '1:00'), '00:00');
assert.strictEqual(subtractTime('00:00', '00:00'), '00:00');
Expand All @@ -147,7 +145,7 @@ describe('Time Math Functions', () =>
});

// Sum time
test('sumTime(HH:MM, HH:MM)', () =>
it('sumTime(HH:MM, HH:MM)', () =>
{
assert.strictEqual(sumTime('01:00', '01:00'), '02:00');
assert.strictEqual(sumTime('00:00', '00:00'), '00:00');
Expand All @@ -158,7 +156,7 @@ describe('Time Math Functions', () =>
});

// Time Validation
test('validateTime(HH:MM)', () =>
it('validateTime(HH:MM)', () =>
{
assert.strictEqual(validateTime('00:00'), true);
assert.strictEqual(validateTime('00:01'), true);
Expand All @@ -175,7 +173,7 @@ describe('Time Math Functions', () =>
assert.strictEqual(validateTime(''), false);
});

test('validateDate(date)', () =>
it('validateDate(date)', () =>
{
const tests = [
{date: '0001-00-00', valid: false},
Expand Down
5 changes: 5 additions & 0 deletions __tests__/electron-mocha-main.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const data = require('./mocha-base.config.cjs');

data.spec = ['__tests__/__main__/time-math.js'];

module.exports = data;
9 changes: 9 additions & 0 deletions __tests__/mocha-base.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
checkLeaks: true,
color: true,
parallel: true,
require: [
'@babel/register',
'@babel/plugin-transform-modules-commonjs'
]
};
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module.exports = {
collectCoverage: true,
coverageDirectory: 'coverage_jest',
collectCoverageFrom: ['js/**.js','js/classes/**.js','src/**.js','./main.js'],
collectCoverageFrom: ['js/**.{cjs,js,mjs}','js/classes/**.{cjs,js,mjs}','src/**.{cjs,js,mjs}','./main.{cjs,js,mjs}'],
projects: [
{
displayName: ' MAIN',
runner: '@jest-runner/electron/main',
testEnvironment: 'node',
testMatch: ['**/__tests__/**main**/*.js']
testMatch: ['**/__tests__/**main**/*.js', '!**/time-math.js']
},
{
displayName: 'RENDERER',
Expand Down
Loading

0 comments on commit b3fd77f

Please sign in to comment.