Skip to content

Commit

Permalink
Switching most expect calls to node assert (#1057)
Browse files Browse the repository at this point in the history
* Switching most expect calls to node assert

* Manual adjustments
  • Loading branch information
araujoarthur0 authored Jan 28, 2024
1 parent 1227117 commit a0653a5
Show file tree
Hide file tree
Showing 22 changed files with 583 additions and 559 deletions.
33 changes: 17 additions & 16 deletions __tests__/__main__/date-aux.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-undef */
'use strict';

const assert = require('assert');
import { getDateStr, getCurrentDateTimeStr, getMonthLength } from '../../js/date-aux.js';

describe('Date Functions', () =>
Expand All @@ -13,12 +14,12 @@ describe('Date Functions', () =>
{
test('Given a JS Date() object, should return YYYY-MM-DD', () =>
{
expect(getDateStr(testDate)).toBe(expectedDate);
assert.strictEqual(getDateStr(testDate), expectedDate);
});

test('Given an insane object, should return an error', () =>
{
expect(getDateStr(badDate)).not.toBe(expectedDate);
assert.notStrictEqual(getDateStr(badDate), expectedDate);
});
});

Expand All @@ -27,18 +28,18 @@ describe('Date Functions', () =>
const testYear = 2024;
test('Given for the Year(2024) and Months, should return number of days in month', () =>
{
expect(getMonthLength(testYear, 0)).toBe(31);
expect(getMonthLength(testYear, 1)).toBe(29);
expect(getMonthLength(testYear, 2)).toBe(31);
expect(getMonthLength(testYear, 3)).toBe(30);
expect(getMonthLength(testYear, 4)).toBe(31);
expect(getMonthLength(testYear, 5)).toBe(30);
expect(getMonthLength(testYear, 6)).toBe(31);
expect(getMonthLength(testYear, 7)).toBe(31);
expect(getMonthLength(testYear, 8)).toBe(30);
expect(getMonthLength(testYear, 9)).toBe(31);
expect(getMonthLength(testYear, 10)).toBe(30);
expect(getMonthLength(testYear, 11)).toBe(31);
assert.strictEqual(getMonthLength(testYear, 0), 31);
assert.strictEqual(getMonthLength(testYear, 1), 29);
assert.strictEqual(getMonthLength(testYear, 2), 31);
assert.strictEqual(getMonthLength(testYear, 3), 30);
assert.strictEqual(getMonthLength(testYear, 4), 31);
assert.strictEqual(getMonthLength(testYear, 5), 30);
assert.strictEqual(getMonthLength(testYear, 6), 31);
assert.strictEqual(getMonthLength(testYear, 7), 31);
assert.strictEqual(getMonthLength(testYear, 8), 30);
assert.strictEqual(getMonthLength(testYear, 9), 31);
assert.strictEqual(getMonthLength(testYear, 10), 30);
assert.strictEqual(getMonthLength(testYear, 11), 31);
});
});

Expand All @@ -49,12 +50,12 @@ describe('Date Functions', () =>

test('Should return Current Date Time string in YYYY_MM_DD_HH_MM_SS format with no spaces or unexpected characters making sure it accepts digits', () =>
{
expect(looseRegexCurrentDateTime.test(getCurrentDateTimeStr())).toBe(true);
assert.strictEqual(looseRegexCurrentDateTime.test(getCurrentDateTimeStr()), true);
});

test('Should return Current Date Time string in YYYY_MM_DD_HH_MM_SS format with no spaces or unexpected characters', () =>
{
expect(regexCurrentDateTime.test(getCurrentDateTimeStr())).toBe(true);
assert.strictEqual(regexCurrentDateTime.test(getCurrentDateTimeStr()), true);
});
});
});
41 changes: 21 additions & 20 deletions __tests__/__main__/import-export.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-undef */
'use strict';

const assert = require('assert');
const {
exportDatabaseToFile,
importDatabaseFromFile,
Expand Down Expand Up @@ -28,17 +29,17 @@ describe('Import export', function()
const badWaivedEntry = {'type': 'regular', 'date': '2020-06-03', 'data': 'day-begin', 'hours': 'not-an-hour'};
test('should be valid', () =>
{
expect(validEntry(goodRegularEntry)).toBeTruthy();
expect(validEntry(goodWaivedEntry)).toBeTruthy();
expect(validEntry(goodFlexibleEntry)).toBeTruthy();
assert.strictEqual(validEntry(goodRegularEntry), true);
assert.strictEqual(validEntry(goodWaivedEntry), true);
assert.strictEqual(validEntry(goodFlexibleEntry), true);
});

test('should not be valid', () =>
{
expect(validEntry(badRegularEntry)).not.toBeTruthy();
expect(validEntry(badWaivedEntry)).not.toBeTruthy();
expect(validEntry(badFlexibleEntry)).not.toBeTruthy();
expect(validEntry(badFlexibleEntry2)).not.toBeTruthy();
assert.strictEqual(validEntry(badRegularEntry), false);
assert.strictEqual(validEntry(badWaivedEntry), false);
assert.strictEqual(validEntry(badFlexibleEntry), false);
assert.strictEqual(validEntry(badFlexibleEntry2), false);
});
});

Expand Down Expand Up @@ -82,8 +83,8 @@ describe('Import export', function()
{
test('Check that export works', () =>
{
expect(exportDatabaseToFile(path.join(folder, 'exported_file.ttldb'))).toBeTruthy();
expect(exportDatabaseToFile('/not/a/valid/path')).not.toBeTruthy();
assert.strictEqual(exportDatabaseToFile(path.join(folder, 'exported_file.ttldb')), true);
assert.strictEqual(exportDatabaseToFile('/not/a/valid/path'), false);
});
});

Expand All @@ -101,11 +102,11 @@ describe('Import export', function()
{
test('Check that import works', () =>
{
expect(importDatabaseFromFile([path.join(folder, 'exported_file.ttldb')])['result']).toBeTruthy();
expect(importDatabaseFromFile(['/not/a/valid/path'])['result']).not.toBeTruthy();
expect(importDatabaseFromFile(['/not/a/valid/path'])['failed']).toBe(0);
expect(importDatabaseFromFile([invalidEntriesFile])['result']).not.toBeTruthy();
expect(importDatabaseFromFile([invalidEntriesFile])['failed']).toBe(5);
assert.strictEqual(importDatabaseFromFile([path.join(folder, 'exported_file.ttldb')])['result'], true);
assert.strictEqual(importDatabaseFromFile(['/not/a/valid/path'])['result'], false);
assert.strictEqual(importDatabaseFromFile(['/not/a/valid/path'])['failed'], 0);
assert.strictEqual(importDatabaseFromFile([invalidEntriesFile])['result'], false);
assert.strictEqual(importDatabaseFromFile([invalidEntriesFile])['failed'], 5);
});
});

Expand All @@ -118,11 +119,11 @@ describe('Import export', function()
{
test('Check that migration works', () =>
{
expect(flexibleStore.size).toBe(2);
assert.strictEqual(flexibleStore.size, 2);
flexibleStore.clear();
expect(flexibleStore.size).toBe(0);
assert.strictEqual(flexibleStore.size, 0);
migrateFixedDbToFlexible();
expect(flexibleStore.size).toBe(2);
assert.strictEqual(flexibleStore.size, 2);
expect(flexibleStore.get('2020-3-1')).toStrictEqual(migratedFlexibleEntries['2020-3-1']);
expect(flexibleStore.get('2020-3-2')).toStrictEqual(migratedFlexibleEntries['2020-3-2']);
});
Expand All @@ -148,9 +149,9 @@ describe('Import export', function()
test('Check that import works', () =>
{
flexibleStore.clear();
expect(flexibleStore.size).toBe(0);
expect(importDatabaseFromFile([mixedEntriesFile])['result']).toBeTruthy();
expect(flexibleStore.size).toBe(2);
assert.strictEqual(flexibleStore.size, 0);
assert.strictEqual(importDatabaseFromFile([mixedEntriesFile])['result'], true);
assert.strictEqual(flexibleStore.size, 2);
expect(flexibleStore.get('2020-2-1')).toStrictEqual(expectedMixedEntries['2020-2-1']);
expect(flexibleStore.get('2020-5-3')).toStrictEqual(expectedMixedEntries['2020-5-3']);
});
Expand Down
35 changes: 18 additions & 17 deletions __tests__/__main__/main-window.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const assert = require('assert');
const notification = require('../../js/notification.js');
const userPreferences = require('../../js/user-preferences.js');
const { savePreferences, defaultPreferences, resetPreferences } = userPreferences;
Expand Down Expand Up @@ -42,16 +43,16 @@ describe('main-window.js', () =>
{
test('Should be null if it has not been started', () =>
{
expect(getWindowTray()).toBe(null);
expect(getMainWindow()).toBe(null);
expect(getLeaveByInterval()).toBe(null);
assert.strictEqual(getWindowTray(), null);
assert.strictEqual(getMainWindow(), null);
assert.strictEqual(getLeaveByInterval(), null);
});

test('Should get window', () =>
{
createWindow();
expect(showSpy).toHaveBeenCalledTimes(1);
expect(getMainWindow()).toBeInstanceOf(BrowserWindow);
assert.strictEqual(getMainWindow() instanceof BrowserWindow, true);
});
});

Expand All @@ -65,17 +66,17 @@ describe('main-window.js', () =>
* @type {BrowserWindow}
*/
const mainWindow = getMainWindow();
expect(mainWindow).toBeInstanceOf(BrowserWindow);
expect(ipcMain.listenerCount('TOGGLE_TRAY_PUNCH_TIME')).toBe(1);
expect(ipcMain.listenerCount('RESIZE_MAIN_WINDOW')).toBe(1);
expect(ipcMain.listenerCount('SWITCH_VIEW')).toBe(1);
expect(ipcMain.listenerCount('RECEIVE_LEAVE_BY')).toBe(1);
expect(mainWindow.listenerCount('minimize')).toBe(2);
expect(mainWindow.listenerCount('close')).toBe(1);
assert.strictEqual(mainWindow instanceof BrowserWindow, true);
assert.strictEqual(ipcMain.listenerCount('TOGGLE_TRAY_PUNCH_TIME'), 1);
assert.strictEqual(ipcMain.listenerCount('RESIZE_MAIN_WINDOW'), 1);
assert.strictEqual(ipcMain.listenerCount('SWITCH_VIEW'), 1);
assert.strictEqual(ipcMain.listenerCount('RECEIVE_LEAVE_BY'), 1);
assert.strictEqual(mainWindow.listenerCount('minimize'), 2);
assert.strictEqual(mainWindow.listenerCount('close'), 1);
expect(loadFileSpy).toHaveBeenCalledTimes(1);
expect(showSpy).toHaveBeenCalledTimes(1);
expect(getLeaveByInterval()).not.toBe(null);
expect(getLeaveByInterval()._idleNext.expiry).toBeGreaterThan(0);
assert.notStrictEqual(getLeaveByInterval(), null);
assert.strictEqual(getLeaveByInterval()._idleNext.expiry > 0, true);
});
});

Expand Down Expand Up @@ -264,7 +265,7 @@ describe('main-window.js', () =>
mainWindow.emit('minimize', {
preventDefault: () => {}
});
expect(mainWindow.isVisible()).toBe(false);
assert.strictEqual(mainWindow.isVisible(), false);
done();
});
});
Expand Down Expand Up @@ -309,8 +310,8 @@ describe('main-window.js', () =>
mainWindow.emit('close', {
preventDefault: () => {}
});
expect(mainWindow.isDestroyed()).toBe(false);
expect(mainWindow.isVisible()).toBe(false);
assert.strictEqual(mainWindow.isDestroyed(), false);
assert.strictEqual(mainWindow.isVisible(), false);
done();
});
});
Expand All @@ -337,7 +338,7 @@ describe('main-window.js', () =>
mainWindow.emit('close', {
preventDefault: () => {}
});
expect(mainWindow.isDestroyed()).toBe(true);
assert.strictEqual(mainWindow.isDestroyed(), true);
done();
});
});
Expand Down
Loading

0 comments on commit a0653a5

Please sign in to comment.