Skip to content

Commit 44fd936

Browse files
committed
Port tests from JS to TS, replacing Ava with Jest
1 parent f476e43 commit 44fd936

24 files changed

+3412
-3499
lines changed

jest.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
export default {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
};

package-lock.json

+2,190-2,211
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+6-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"type": "git",
1313
"url": "git+https://github.com/hebcal/hdate-js.git"
1414
},
15+
"type": "module",
1516
"main": "dist/cjs/index.js",
1617
"module": "dist/esm/index.js",
1718
"typings": "dist/index.d.ts",
@@ -25,9 +26,9 @@
2526
"dist/*"
2627
],
2728
"scripts": {
28-
"test": "ava",
29+
"test": "jest",
2930
"build": "npm run po2json && npm run build:es6 && npm run build:cjs && npm run build:types",
30-
"build:cjs": "tsc",
31+
"build:cjs": "tsc -p ./tsconfig-cjs.json",
3132
"build:es6": "tsc -p ./tsconfig-es6.json",
3233
"build:types": "tsc -p ./tsconfig-types.json",
3334
"po2json": "node ./po2json.cjs po/*.po",
@@ -39,10 +40,11 @@
3940
"lint": "gts lint"
4041
},
4142
"devDependencies": {
42-
"@ava/typescript": "^5.0.0",
43+
"@types/jest": "^29.5.12",
4344
"@types/node": "20.12.12",
44-
"ava": "^6.1.3",
4545
"gts": "^5.3.0",
46+
"jest": "^29.7.0",
47+
"ts-jest": "^29.1.4",
4648
"ttag-cli": "^1.10.12",
4749
"typescript": "^5.4.5"
4850
}

src/hdate.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class HDate {
8686
* @param {number|string} [month] - Hebrew month of year (1=NISAN, 7=TISHREI)
8787
* @param {number} [year] - Hebrew year
8888
*/
89-
constructor(day: number|Date|HDate|SimpleHebrewDate|undefined, month?: number|string, year?: number) {
89+
constructor(day?: number|Date|HDate|SimpleHebrewDate|undefined, month?: number|string, year?: number) {
9090
if (arguments.length === 2 || arguments.length > 3) {
9191
throw new TypeError('HDate constructor requires 0, 1 or 3 arguments');
9292
}

src/locale.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ export class Locale {
9696
* Adds a translation to `locale`, replacing any previous translation.
9797
* @param {string} locale Locale name (i.e: `'he'`, `'fr'`).
9898
* @param {string} id Message ID to translate
99-
* @param {string} translation Translation text
99+
* @param {string | string[]} translation Translation text
100100
*/
101-
static addTranslation(locale: string, id: string, translation: string): void {
101+
static addTranslation(locale: string, id: string, translation: string | string[]): void {
102102
if (typeof locale !== 'string') {
103103
throw new TypeError(`Invalid locale name: ${locale}`);
104104
}

src/sedra.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export class Sedra {
119119
* @param {string} [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to active locale
120120
* @return {string}
121121
*/
122-
getString(hd: HDate | number, locale: string): string {
122+
getString(hd: HDate | number, locale?: string): string {
123123
const parsha = this.get(hd);
124124
const locale0 = locale || Locale.getLocaleName();
125125
let name = Locale.gettext(parsha[0], locale0);

test/anniversary.spec.js test/anniversary.spec.ts

+27-20
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/* eslint-disable max-len */
2-
const test = require('ava');
3-
const {months} = require('../dist/cjs/hdate-base');
4-
const {getYahrzeit, getBirthdayOrAnniversary,
5-
getYahrzeitHD, getBirthdayHD} = require('../dist/cjs/anniversary');
2+
import {months} from '../src/hdate-base';
3+
import {
4+
getYahrzeit, getBirthdayOrAnniversary,
5+
getYahrzeitHD, getBirthdayHD
6+
} from '../src/anniversary';
67

7-
test('yahrzeit', (t) => {
8+
test('yahrzeit', () => {
89
// Gregorian YYYY, MM, DD
9-
const items = [
10+
const items: [number, number, number, string, string][] = [
1011
[2017, 1, 13, 'General',
1112
'1/2/2018 12/23/2018 1/12/2020 12/30/2020 12/19/2021 1/8/2023 12/27/2023 1/15/2025 1/4/2026 12/25/2026 1/14/2028 1/2/2029 12/21/2029 1/10/2031 12/30/2031 12/17/2032 1/6/2034 12/27/2034 1/15/2036 1/2/2037 12/23/2037 1/11/2039 1/1/2040 12/19/2040 1/7/2042 12/28/2042',
1213
],
@@ -36,14 +37,15 @@ test('yahrzeit', (t) => {
3637
for (let i = 0; i < 25; i++) {
3738
const hyear = i + 5778;
3839
const yahrzeit = getYahrzeit(hyear, gd);
39-
const dateStr = yahrzeit.toLocaleDateString('en-US');
40-
t.is(dateStr, expected[i], `${name} ${i} ${hyear}`);
40+
expect(yahrzeit).toBeDefined();
41+
const dateStr = (yahrzeit as Date).toLocaleDateString('en-US');
42+
expect(dateStr).toBe(expected[i]);
4143
}
4244
}
4345
});
4446

45-
test('birthday', (t) => {
46-
const items = [
47+
test('birthday', () => {
48+
const items: [number, number, number, string, string][] = [
4749
[1948, 3, 11, 'Adar1-30',
4850
'3/23/1993 3/13/1994 3/2/1995 3/21/1996 3/9/1997 3/28/1998 3/18/1999 3/7/2000 3/25/2001 3/14/2002 3/4/2003 3/23/2004 3/11/2005 3/30/2006 3/20/2007 3/7/2008 3/26/2009 3/16/2010 3/6/2011 3/24/2012 3/12/2013',
4951
],
@@ -70,32 +72,37 @@ test('birthday', (t) => {
7072
for (let i = 0; i < 21; i++) {
7173
const hyear = i + 5753;
7274
const birthday = getBirthdayOrAnniversary(hyear, gd);
73-
const dateStr = birthday.toLocaleDateString('en-US');
74-
t.is(dateStr, expected[i], `${name} ${i} ${hyear}`);
75+
expect(birthday).toBeDefined();
76+
const dateStr = (birthday as Date).toLocaleDateString('en-US');
77+
expect(dateStr).toBe(expected[i]);
7578
}
7679
}
7780
});
7881

79-
test('before-original', (t) => {
82+
test('before-original', () => {
8083
let dt = getYahrzeit(5769, new Date(2008, 10, 13));
81-
t.is(dt, undefined, 'Hebrew year 5769 occurs on or before original date in 5769');
84+
expect(dt).toBe(undefined); // 'Hebrew year 5769 occurs on or before original date in 5769');
8285

8386
dt = getYahrzeit(5770, new Date(2008, 10, 13));
84-
t.is(dt.getFullYear(), 2009);
87+
expect(dt).toBeDefined();
88+
expect((dt as Date).getFullYear()).toBe(2009);
8589

8690
dt = getBirthdayOrAnniversary(5778, new Date(2018, 11, 13));
87-
t.is(dt, undefined, 'Hebrew year 5778 occurs before original date in 5779');
91+
expect(dt).toBe(undefined); // 'Hebrew year 5778 occurs before original date in 5779');
8892

8993
dt = getBirthdayOrAnniversary(5780, new Date(2018, 11, 13));
90-
t.is(dt.getFullYear(), 2020);
94+
expect(dt).toBeDefined();
95+
expect((dt as Date).getFullYear()).toBe(2020);
9196
});
9297

93-
test('ctor-hdate', (t) => {
98+
test('ctor-hdate', () => {
9499
const niftar = {dd: 15, mm: months.CHESHVAN, yy: 5769};
95100
const yahrzeit = getYahrzeitHD(5782, niftar);
96-
t.deepEqual(yahrzeit, {dd: 15, mm: 8, yy: 5782}, '15 Cheshvan 5782');
101+
expect(yahrzeit).toBeDefined();
102+
expect(yahrzeit).toEqual({dd: 15, mm: 8, yy: 5782});
97103

98104
const birth = {dd: 23, mm: months.SIVAN, yy: 5735};
99105
const anniversary = getBirthdayHD(5782, birth);
100-
t.deepEqual(anniversary, {dd: 23, mm: 3, yy: 5782}, '23 Sivan 5782');
106+
expect(anniversary).toBeDefined();
107+
expect(anniversary).toEqual({dd: 23, mm: 3, yy: 5782});
101108
});

test/gematriya.spec.js

-52
This file was deleted.

test/gematriya.spec.ts

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import {gematriya, gematriyaStrToNum} from '../src/gematriya';
2+
3+
test('gematriya', () => {
4+
expect(gematriya(5749)).toBe('תשמ״ט');
5+
expect(gematriya(5774)).toBe('תשע״ד');
6+
expect(gematriya(5780)).toBe('תש״פ');
7+
expect(gematriya(3)).toBe('ג׳');
8+
expect(gematriya(14)).toBe('י״ד');
9+
expect(gematriya(15)).toBe('ט״ו');
10+
expect(gematriya(16)).toBe('ט״ז');
11+
expect(gematriya(17)).toBe('י״ז');
12+
expect(gematriya(20)).toBe('כ׳');
13+
expect(gematriya(25)).toBe('כ״ה');
14+
expect(gematriya(60)).toBe('ס׳');
15+
expect(gematriya(123)).toBe('קכ״ג');
16+
expect(gematriya(613)).toBe('תרי״ג');
17+
expect(gematriya(3761)).toBe('ג׳תשס״א');
18+
expect(gematriya(6749)).toBe('ו׳תשמ״ט');
19+
expect(gematriya(8765)).toBe('ח׳תשס״ה');
20+
expect(gematriya(22700)).toBe('כב׳ת״ש');
21+
expect(gematriya(16123)).toBe('טז׳קכ״ג');
22+
expect(gematriya(1123)).toBe('א׳קכ״ג');
23+
expect(gematriya(6000)).toBe('ו׳');
24+
expect(gematriya(7007)).toBe('ז׳ז׳');
25+
});
26+
27+
test('gematriyaStrToNum', () => {
28+
expect(gematriyaStrToNum('תשמ״ט')).toBe(749);
29+
expect(gematriyaStrToNum('תשע״ד')).toBe(774);
30+
expect(gematriyaStrToNum('תש״פ')).toBe(780);
31+
expect(gematriyaStrToNum('ג׳')).toBe(3);
32+
expect(gematriyaStrToNum('י״ד')).toBe(14);
33+
expect(gematriyaStrToNum('ט״ו')).toBe(15);
34+
expect(gematriyaStrToNum('ט״ז')).toBe(16);
35+
expect(gematriyaStrToNum('י״ז')).toBe(17);
36+
expect(gematriyaStrToNum('כ׳')).toBe(20);
37+
expect(gematriyaStrToNum('כ״ה')).toBe(25);
38+
expect(gematriyaStrToNum('ס׳')).toBe(60);
39+
expect(gematriyaStrToNum('קכ״ג')).toBe(123);
40+
expect(gematriyaStrToNum('תרי״ג')).toBe(613);
41+
});
42+
43+
test('gematriyaStrToNum-thousands', () => {
44+
expect(gematriyaStrToNum('ג׳תשס״א')).toBe(3761);
45+
expect(gematriyaStrToNum('ו׳תשמ״ט')).toBe(6749);
46+
expect(gematriyaStrToNum('ח׳תשס״ה')).toBe(8765);
47+
expect(gematriyaStrToNum('כב׳ת״ש')).toBe(22700);
48+
expect(gematriyaStrToNum('טז׳קכ״ג')).toBe(16123);
49+
expect(gematriyaStrToNum('א׳קכ״ג')).toBe(1123);
50+
expect(gematriyaStrToNum('ז׳ז׳')).toBe(7007);
51+
});

test/greg.spec.js

-126
This file was deleted.

0 commit comments

Comments
 (0)