diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..c84a281 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,40 @@ + + + + +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node', + testMatch: [ + '**/tests/*.test.ts', + '**/*.test.ts', + ], + moduleFileExtensions: ['ts', 'js'], +}; + +// module.exports = { +// preset: 'ts-jest', // תומך ב-TS +// testEnvironment: 'node', // סביבה מבוססת Node.js (אופציונלי, תלוי בפרויקט) +// testMatch: [ +// '**/tests/*.test.ts', // חפש את הקבצים בתיקיית tests עם סיומת .test.ts +// '**/*.test.ts', // חפש כל קובץ עם סיומת .test.ts +// ], +// moduleFileExtensions: ['ts', 'js'], +// "compilerOptions": { +// "types": ["jest", "node"] +// } +// // קובצי מודול ש-Jest תומך בהם +// }; + + + +// module.exports = { +// preset: 'ts-jest', +// testEnvironment: 'node', +// testMatch: [; +// '**/tests/**/*.test.ts', // תוודא שזה כולל את המיקום של קבצי הבדיקות שלך +// '**/*.test.ts', +// '**/*.spec.ts' +// ], +// moduleFileExtensions: ['ts', 'js'], +// }; diff --git a/modules/ecs6-class/line.ts b/modules/ecs6-class/line.ts index e2d6086..3afd779 100644 --- a/modules/ecs6-class/line.ts +++ b/modules/ecs6-class/line.ts @@ -12,39 +12,58 @@ export default class Line { this.n = n; } - - calculateSlope() { - this.slope = (this.point1.y - this.point2.y) / (this.point1.x - this.point2.x) + + +calculateSlope() { + if (this.point1.x === this.point2.x) { + this.slope = undefined; // קו אנכי, שיפוע לא מוגדר + } else if (this.point1.y === this.point2.y) { + this.slope = 0; // קו אופקי + } else { + this.slope = (this.point1.y - this.point2.y) / (this.point1.x - this.point2.x); } +} + calculateNOfLineFunction() { - if (this.slope) - this.n = this.point1.y - this.slope * this.point1.x + if (this.slope === 0) { + this.n = this.point1.y; // עבור קו אופקי, n שווה ל-y של point1 + } else if (this.slope !== undefined) { + this.n = this.point1.y - this.slope * this.point1.x; } +} getPointOnXAsis() { return this.getPointByY(0) } + + // חישוב החיתוך עם ציר Y + getPointOnYAsis(): Point | undefined { + // אם מדובר בקו אופקי, אז ה-Y נשאר קבוע + if (this.point1.y === this.point2.y) { + return new Point({ x: 0, y: this.point1.y }); // קו אופקי חותך את ציר ה-Y באותו ה-Y + } - getPointOnYAsis() { - return this.getPointByX(0) - } - + // אם יש שיפוע מחושב, נחשב את החיתוך עם ציר ה-Y (כאשר x = 0) + if (this.slope !== undefined && this.n !== undefined) { + const y = this.slope * 0 + this.n; // חישוב y כאשר x = 0 + return new Point({ x: 0, y }); + } + return undefined; + } getPointByX(x: number) { if (this.slope && this.n) { let y = this.slope * x + this.n return new Point({ x, y }) } } - getPointByY(y: number) { if (this.slope && this.n) { let x = (y - this.n) / this.slope; return new Point({ x, y }) } } - - -} + +} \ No newline at end of file diff --git a/modules/geometry-calculation.ts b/modules/geometry-calculation.ts index 22ab78b..5e86d7d 100644 --- a/modules/geometry-calculation.ts +++ b/modules/geometry-calculation.ts @@ -36,6 +36,4 @@ export const isPointOnLine = (line: Line, point: Point): Boolean => { } } return false -} - - +} \ No newline at end of file diff --git a/modules/tests/line.test.ts b/modules/tests/line.test.ts new file mode 100644 index 0000000..b10ac4f --- /dev/null +++ b/modules/tests/line.test.ts @@ -0,0 +1,275 @@ +import Line from "../ecs6-class/line"; +import Point from "../ecs6-class/point"; +import { describe,beforeEach ,it, expect } from '@jest/globals'; + + +describe('Line Class', () => { + let point1: Point; + let point2: Point; + let line: Line; + + beforeEach(() => { + point1 = new Point({ x: 1, y: 2 }); + point2 = new Point({ x: 3, y: 4 }); + line = new Line({ point1, point2 }); + }); + + test('should initialize with default values', () => { + const defaultLine = new Line({}); + expect(defaultLine.point1.x).toBe(0); + expect(defaultLine.point1.y).toBe(0); + expect(defaultLine.point2.x).toBe(0); + expect(defaultLine.point2.y).toBe(0); + expect(defaultLine.slope).toBeUndefined(); + expect(defaultLine.n).toBeUndefined(); + }); + + test('should initialize with given values', () => { + expect(line.point1.x).toBe(1); + expect(line.point1.y).toBe(2); + expect(line.point2.x).toBe(3); + expect(line.point2.y).toBe(4); + expect(line.slope).toBeUndefined(); + expect(line.n).toBeUndefined(); + }); + + // + test('should calculate slope correctly', () => { + line.calculateSlope(); + expect(line.slope).toBe(1); // (4 - 2) / (3 - 1) = 1 + }); + + test('should calculate n correctly', () => { + line.calculateSlope(); + line.calculateNOfLineFunction(); + expect(line.n).toBe(1); // 2 - (1 * 1) = 1 + }); + + test('should calculate the point on X axis correctly', () => { + line.calculateSlope(); + line.calculateNOfLineFunction(); + const pointOnX = line.getPointOnXAsis(); + expect(pointOnX?.x).toBe(-1); // y = 0, solve for x + expect(pointOnX?.y).toBe(0); // y = 0 + }); +// ! + // test('should calculate the point on Y axis correctly', () => { + // line.calculateSlope(); + // line.calculateNOfLineFunction(); + // const pointOnY = line.getPointOnYAsis(); + // expect(pointOnY?.x).toBe(0); // x = 0 + // expect(pointOnY?.y).toBe(2); // y = 2 (from point1) + // }); +// ! + +test('should handle line with identical points and return undefined slope', () => { + const identicalLine = new Line({ point1: new Point({ x: 1, y: 2 }), point2: new Point({ x: 1, y: 2 }) }); + identicalLine.calculateSlope(); + expect(identicalLine.slope).toBeUndefined(); // כאשר הנקודות זהות, אין שיפוע +}); + +test('should calculate slope correctly for negative coordinates', () => { + const negativeLine = new Line({ point1: new Point({ x: -1, y: -2 }), point2: new Point({ x: -3, y: -4 }) }); + negativeLine.calculateSlope(); + expect(negativeLine.slope).toBe(1); // חישוב השיפוע אמור להיות 1 במקרה של נקודות שליליות +}); + +test('should handle vertical line on X axis', () => { + const verticalLine = new Line({ + point1: new Point({ x: 3, y: 0 }), + point2: new Point({ x: 3, y: 5 }), + }); + const pointOnY = verticalLine.getPointOnYAsis(); + expect(pointOnY).toBeUndefined(); // קו אנכי לא חותך את ציר ה-Y +}); + + test('should return correct point by X value', () => { + line.calculateSlope(); + line.calculateNOfLineFunction(); + const pointByX = line.getPointByX(5); + expect(pointByX?.x).toBe(5); + expect(pointByX?.y).toBe(6); // y = slope * x + n = 1 * 5 + 1 = 6 + }); + + test('should return correct point by Y value', () => { + line.calculateSlope(); + line.calculateNOfLineFunction(); + const pointByY = line.getPointByY(6); + expect(pointByY?.x).toBe(5); // x = (y - n) / slope = (6 - 1) / 1 = 5 + expect(pointByY?.y).toBe(6); + }); + // + test('should handle vertical line (undefined slope)', () => { + const verticalLine = new Line({ point1: new Point({ x: 1, y: 2 }), point2: new Point({ x: 1, y: 4 }) }); + verticalLine.calculateSlope(); + expect(verticalLine.slope).toBeUndefined(); // Vertical line should have no defined slope + }); + + test('should handle horizontal line (zero slope)', () => { + const horizontalLine = new Line({ point1: new Point({ x: 1, y: 2 }), point2: new Point({ x: 3, y: 2 }) }); + horizontalLine.calculateSlope(); + expect(horizontalLine.slope).toBe(0); // שיפוע 0 עבור קו אופקי + }); + + test('should calculate n correctly for horizontal line', () => { + const horizontalLine = new Line({ point1: new Point({ x: 1, y: 2 }), point2: new Point({ x: 3, y: 2 }) }); + horizontalLine.calculateSlope(); + horizontalLine.calculateNOfLineFunction(); + expect(horizontalLine.n).toBe(2); // מכיוון שהקו אופקי, n שווה ל-2 + }); + test('should return undefined for X axis intersection of horizontal line', () => { + const horizontalLine = new Line({ point1: new Point({ x: 1, y: 2 }), point2: new Point({ x: 3, y: 2 }) }); + horizontalLine.calculateSlope(); + horizontalLine.calculateNOfLineFunction(); + const pointOnX = horizontalLine.getPointOnXAsis(); + expect(pointOnX).toBeUndefined(); // קו אופקי לא חותך את ציר ה-X + }); + test('should return undefined for point by Y value on vertical line', () => { + const verticalLine = new Line({ point1: new Point({ x: 1, y: 2 }), point2: new Point({ x: 1, y: 4 }) }); + verticalLine.calculateSlope(); + const pointByY = verticalLine.getPointByY(6); + expect(pointByY).toBeUndefined(); // קו אנכי לא יכול לחשב את הנקודה על פי Y + }); + test('should retain undefined slope and n if not calculated', () => { + const line = new Line({ point1: new Point({ x: 1, y: 2 }), point2: new Point({ x: 3, y: 4 }) }); + expect(line.slope).toBeUndefined(); // לא חישבנו את השיפוע + expect(line.n).toBeUndefined(); // לא חישבנו את ה-n + }); + test('should handle coincident points', () => { + const coincidentLine = new Line({ point1: new Point({ x: 1, y: 2 }), point2: new Point({ x: 1, y: 2 }) }); + coincidentLine.calculateSlope(); + expect(coincidentLine.slope).toBeUndefined(); // אין שיפוע + }); + test('should handle line with points in different quadrants', () => { + const lineWithOppositePoints = new Line({ point1: new Point({ x: -1, y: -1 }), point2: new Point({ x: 2, y: 3 }) }); + lineWithOppositePoints.calculateSlope(); + lineWithOppositePoints.calculateNOfLineFunction(); + expect(lineWithOppositePoints.slope).toBeCloseTo(4 / 3); // חישוב שיפוע נכון + }); + // ! + test('should handle horizontal line on Y axis', () => { + const horizontalLine = new Line({ point1: new Point({ x: 0, y: 2 }), point2: new Point({ x: 5, y: 2 }) }); + const pointOnY = horizontalLine.getPointOnYAsis(); + expect(pointOnY?.x).toBe(0); // x = 0 + expect(pointOnY?.y).toBe(2); // y = 2 + }); + // ! + + test('should handle lines with negative coordinates', () => { + const negativeLine = new Line({ point1: new Point({ x: -1, y: -2 }), point2: new Point({ x: -3, y: -4 }) }); + negativeLine.calculateSlope(); + expect(negativeLine.slope).toBe(1); // (y2 - y1) / (x2 - x1) = (-4 - (-2)) / (-3 - (-1)) = 1 + }); + + test('should calculate the point on Y axis correctly for non-vertical lines', () => { + line.calculateSlope(); + line.calculateNOfLineFunction(); + const pointOnY = line.getPointOnYAsis(); + expect(pointOnY?.x).toBe(0); // החיתוך עם ציר ה-Y תמיד יהיה ב-x = 0 + expect(pointOnY?.y).toBe(1); // הנקודה על ציר ה-Y צריכה להיות (0, 1) עבור שיפוע 1 ו-n = 1 +}); + +test('should return undefined for vertical line on Y axis', () => { + const verticalLine = new Line({ + point1: new Point({ x: 3, y: 0 }), + point2: new Point({ x: 3, y: 5 }), + }); + const pointOnY = verticalLine.getPointOnYAsis(); + expect(pointOnY).toBeUndefined(); // קו אנכי לא חותך את ציר ה-Y +}); +describe('Line class - calculateSlope tests', () => { + it('should return undefined for vertical line', () => { + const point1 = new Point({ x: 0, y: 0 }); + const point2 = new Point({ x: 0, y: 5 }); + const line = new Line({ point1, point2 }); + line.calculateSlope(); + expect(line.slope).toBeUndefined(); // קו אנכי, שיפוע לא מוגדר + }); + + it('should return 0 for horizontal line', () => { + const point1 = new Point({ x: 0, y: 0 }); + const point2 = new Point({ x: 5, y: 0 }); + const line = new Line({ point1, point2 }); + line.calculateSlope(); + expect(line.slope).toBe(0); // קו אופקי, שיפוע 0 + }); + + it('should return correct slope for non-horizontal, non-vertical line', () => { + const point1 = new Point({ x: 0, y: 0 }); + const point2 = new Point({ x: 5, y: 5 }); + const line = new Line({ point1, point2 }); + line.calculateSlope(); + expect(line.slope).toBe(1); // שיפוע 1 (כי 5-0/5-0 = 1) + }); +}); +describe('Line class - calculateNOfLineFunction tests', () => { + it('should return correct n for horizontal line', () => { + const point1 = new Point({ x: 0, y: 3 }); + const point2 = new Point({ x: 5, y: 3 }); + const line = new Line({ point1, point2 }); + line.calculateSlope(); // קו אופקי + line.calculateNOfLineFunction(); + expect(line.n).toBe(3); // n שווה ל-y של point1 + }); + + it('should return correct n for non-horizontal line', () => { + const point1 = new Point({ x: 0, y: 0 }); + const point2 = new Point({ x: 5, y: 5 }); + const line = new Line({ point1, point2 }); + line.calculateSlope(); + line.calculateNOfLineFunction(); + expect(line.n).toBe(0); // n = y - slope * x => 0 - 1 * 0 = 0 + }); +}); +describe('Line class - getPointOnYAsis tests', () => { + it('should return point on Y-axis for horizontal line', () => { + const point1 = new Point({ x: 0, y: 5 }); + const point2 = new Point({ x: 5, y: 5 }); + const line = new Line({ point1, point2 }); + expect(line.getPointOnYAsis()).toEqual(new Point({ x: 0, y: 5 })); // קו אופקי חותך את ציר ה-Y בנקודה (0, 5) + }); + + it('should return point on Y-axis for non-horizontal line', () => { + const point1 = new Point({ x: 0, y: 3 }); + const point2 = new Point({ x: 5, y: 8 }); + const line = new Line({ point1, point2 }); + line.calculateSlope(); + line.calculateNOfLineFunction(); + expect(line.getPointOnYAsis()).toEqual(new Point({ x: 0, y: 3 })); // חישוב החיתוך עם ציר ה-Y + }); + + it('should return undefined if slope is undefined', () => { + const point1 = new Point({ x: 0, y: 3 }); + const point2 = new Point({ x: 0, y: 8 }); + const line = new Line({ point1, point2 }); + line.calculateSlope(); // קו אנכי, אין חיתוך עם ציר ה-Y + expect(line.getPointOnYAsis()).toBeUndefined(); + }); + test('should return undefined for vertical line on Y axis', () => { + const verticalLine = new Line({ + point1: new Point({ x: 3, y: 0 }), + point2: new Point({ x: 3, y: 5 }), + }); + const pointOnY = verticalLine.getPointOnYAsis(); + expect(pointOnY).toBeUndefined(); // קו אנכי לא חותך את ציר ה-Y +}); + +test('should handle line with identical points and return undefined slope', () => { + const identicalLine = new Line({ point1: new Point({ x: 1, y: 2 }), point2: new Point({ x: 1, y: 2 }) }); + identicalLine.calculateSlope(); + expect(identicalLine.slope).toBeUndefined(); // כאשר הנקודות זהות, אין שיפוע + expect(identicalLine.n).toBeUndefined(); // כאשר אין שיפוע, אין גם ערך של n +}); + +test('should return undefined for vertical line on X axis', () => { + const verticalLine = new Line({ + point1: new Point({ x: 0, y: 0 }), + point2: new Point({ x: 0, y: 5 }), + }); + verticalLine.calculateSlope(); + const pointOnX = verticalLine.getPointOnXAsis(); + expect(pointOnX).toBeUndefined(); // קו אנכי לא חותך את ציר ה-X +}); + +}); +}); diff --git a/modules/tests/point.test.ts b/modules/tests/point.test.ts new file mode 100644 index 0000000..aefb32a --- /dev/null +++ b/modules/tests/point.test.ts @@ -0,0 +1,170 @@ +import Point from "../ecs6-class/point"; +import { describe, it, beforeEach, expect } from '@jest/globals'; + +describe('Point Class', () => { + let point: Point; + + beforeEach(() => { + point = new Point({ x: 1, y: 2 }); + }); + + test('should initialize with default values', () => { + const defaultPoint = new Point(); + expect(defaultPoint.x).toBe(0); + expect(defaultPoint.y).toBe(0); + }); + + test('should initialize with given values', () => { + expect(point.x).toBe(1); + expect(point.y).toBe(2); + }); + + test('moveVertical should increase y coordinate', () => { + point.moveVertical(3); + expect(point.y).toBe(5); // 2 + 3 + }); + + test('moveVertical should decrease y coordinate', () => { + point.moveVertical(-1); + expect(point.y).toBe(1); // 2 - 1 + }); + + test('moveHorizontal should increase x coordinate', () => { + point.moveHorizontal(4); + expect(point.x).toBe(5); // 1 + 4 + }); + + test('moveHorizontal should decrease x coordinate', () => { + point.moveHorizontal(-2); + expect(point.x).toBe(-1); // 1 - 2 + }); + + test('moveVertical should handle zero movement', () => { + point.moveVertical(0); + expect(point.y).toBe(2); // no change + }); + + test('moveHorizontal should handle zero movement', () => { + point.moveHorizontal(0); + expect(point.x).toBe(1); // no change + }); + + test('should handle negative initial values', () => { + const negativePoint = new Point({ x: -3, y: -4 }); + expect(negativePoint.x).toBe(-3); + expect(negativePoint.y).toBe(-4); + }); + + test('should handle large number values', () => { + const largePoint = new Point({ x: 1000000, y: 2000000 }); + expect(largePoint.x).toBe(1000000); + expect(largePoint.y).toBe(2000000); + }); + + test('should initialize with only x or y', () => { + const pointWithOnlyX = new Point({ x: 5 }); + expect(pointWithOnlyX.x).toBe(5); + expect(pointWithOnlyX.y).toBe(0); + + const pointWithOnlyY = new Point({ y: 10 }); + expect(pointWithOnlyY.x).toBe(0); + expect(pointWithOnlyY.y).toBe(10); + }); +}); + +describe('Point Class - Additional Tests', () => { + let point: Point; + + beforeEach(() => { + point = new Point({ x: 2, y: 3 }); + }); + + test('should handle initialization with no parameters', () => { + const point = new Point(); + expect(point.x).toBe(0); + expect(point.y).toBe(0); + }); + + test('should correctly update x when moved horizontally by a positive value', () => { + point.moveHorizontal(5); + expect(point.x).toBe(7); // 2 + 5 + }); + + test('should correctly update x when moved horizontally by a negative value', () => { + point.moveHorizontal(-3); + expect(point.x).toBe(-1); // 2 - 3 + }); + + test('should correctly update y when moved vertically by a positive value', () => { + point.moveVertical(6); + expect(point.y).toBe(9); // 3 + 6 + }); + + test('should correctly update y when moved vertically by a negative value', () => { + point.moveVertical(-2); + expect(point.y).toBe(1); // 3 - 2 + }); + + test('should allow multiple vertical moves', () => { + point.moveVertical(5); + point.moveVertical(2); + expect(point.y).toBe(10); // 3 + 5 + 2 + }); + + test('should allow multiple horizontal moves', () => { + point.moveHorizontal(3); + point.moveHorizontal(-1); + expect(point.x).toBe(4); // 2 + 3 - 1 + }); + + test('should create multiple points with different initial values', () => { + const point1 = new Point({ x: 10, y: 20 }); + const point2 = new Point({ x: -5, y: 10 }); + expect(point1.x).toBe(10); + expect(point1.y).toBe(20); + expect(point2.x).toBe(-5); + expect(point2.y).toBe(10); + }); + + test('should allow movement of point from negative coordinates', () => { + const pointNegative = new Point({ x: -10, y: -15 }); + pointNegative.moveVertical(10); + pointNegative.moveHorizontal(5); + expect(pointNegative.x).toBe(-5); // -10 + 5 + expect(pointNegative.y).toBe(-5); // -15 + 10 + }); + + test('should return correct x and y after multiple movements', () => { + point.moveVertical(4); + point.moveHorizontal(-6); + point.moveVertical(-3); + point.moveHorizontal(8); + expect(point.x).toBe(4); // 2 - 6 + 8 + expect(point.y).toBe(4); // 3 + 4 - 3 + }); + + test('should allow both positive and negative movements in sequence', () => { + point.moveVertical(5); // 3 + 5 = 8 + point.moveHorizontal(-3); // 2 - 3 = -1 + point.moveVertical(-2); // 8 - 2 = 6 + point.moveHorizontal(7); // -1 + 7 = 6 + expect(point.x).toBe(6); + expect(point.y).toBe(6); + }); + + test('should reset point to new values correctly', () => { + point.moveHorizontal(3); + point.moveVertical(4); + expect(point.x).toBe(5); // 2 + 3 + expect(point.y).toBe(7); // 3 + 4 + + // reset to new coordinates + point = new Point({ x: 10, y: 10 }); + expect(point.x).toBe(10); + expect(point.y).toBe(10); + }); +}); +// function beforeEach(arg0: () => void) { +// throw new Error("Function not implemented."); +// } + diff --git a/package-lock.json b/package-lock.json index 5bc5ea8..b8dc6cd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,9 @@ "license": "ISC", "devDependencies": { "@types/jest": "^30.0.0", + "@types/mocha": "^10.0.10", "jest": "^30.0.4", + "ts-jest": "^29.4.0", "ts-node": "^10.9.2", "typescript": "^5.8.3" } @@ -1250,6 +1252,13 @@ "pretty-format": "^30.0.0" } }, + "node_modules/@types/mocha": { + "version": "10.0.10", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.10.tgz", + "integrity": "sha512-xPyYSz1cMPnJQhl0CLMH68j3gprKZaTjG3s5Vi+fDgx+uhG9NOXwbVt52eFS8ECyXhyKcjDLCBEqBExKuiZb7Q==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/node": { "version": "24.0.12", "resolved": "https://registry.npmjs.org/@types/node/-/node-24.0.12.tgz", @@ -1662,6 +1671,13 @@ "sprintf-js": "~1.0.2" } }, + "node_modules/async": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.6.tgz", + "integrity": "sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==", + "dev": true, + "license": "MIT" + }, "node_modules/babel-jest": { "version": "30.0.4", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-30.0.4.tgz", @@ -1823,6 +1839,19 @@ "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" } }, + "node_modules/bs-logger": { + "version": "0.2.6", + "resolved": "https://registry.npmjs.org/bs-logger/-/bs-logger-0.2.6.tgz", + "integrity": "sha512-pd8DCoxmbgc7hyPKOvxtqNcjYoOsABPQdcCUjGp3d42VR2CX1ORhk2A87oqqu5R1kk+76nsxZupkmyd+MVtCog==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-json-stable-stringify": "2.x" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/bser": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/bser/-/bser-2.1.1.tgz", @@ -2153,6 +2182,22 @@ "dev": true, "license": "MIT" }, + "node_modules/ejs": { + "version": "3.1.10", + "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.10.tgz", + "integrity": "sha512-UeJmFfOrAQS8OJWPZ4qtgHyWExa088/MtK5UEyoJGFH67cDEXkZSviOiKRCZ4Xij0zxI3JECgYs3oKx+AizQBA==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "jake": "^10.8.5" + }, + "bin": { + "ejs": "bin/cli.js" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/electron-to-chromium": { "version": "1.5.181", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.181.tgz", @@ -2300,6 +2345,29 @@ "bser": "2.1.1" } }, + "node_modules/filelist": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.4.tgz", + "integrity": "sha512-w1cEuf3S+DrLCQL7ET6kz+gmlJdbq9J7yXCSjK/OZCPA+qEN1WyF4ZAf0YYJa4/shHJra2t/d/r8SV4Ji+x+8Q==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "minimatch": "^5.0.1" + } + }, + "node_modules/filelist/node_modules/minimatch": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", + "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/fill-range": { "version": "7.1.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", @@ -2681,6 +2749,49 @@ "@pkgjs/parseargs": "^0.11.0" } }, + "node_modules/jake": { + "version": "10.9.2", + "resolved": "https://registry.npmjs.org/jake/-/jake-10.9.2.tgz", + "integrity": "sha512-2P4SQ0HrLQ+fw6llpLnOaGAvN2Zu6778SJMrCUwns4fOoG9ayrTiZk3VV8sCPkVZF8ab0zksVpS8FDY5pRCNBA==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "async": "^3.2.3", + "chalk": "^4.0.2", + "filelist": "^1.0.4", + "minimatch": "^3.1.2" + }, + "bin": { + "jake": "bin/cli.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/jake/node_modules/brace-expansion": { + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz", + "integrity": "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/jake/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, "node_modules/jest": { "version": "30.0.4", "resolved": "https://registry.npmjs.org/jest/-/jest-30.0.4.tgz", @@ -3371,6 +3482,13 @@ "node": ">=8" } }, + "node_modules/lodash.memoize": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", + "integrity": "sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==", + "dev": true, + "license": "MIT" + }, "node_modules/lru-cache": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", @@ -4221,6 +4339,85 @@ "node": ">=8.0" } }, + "node_modules/ts-jest": { + "version": "29.4.0", + "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.4.0.tgz", + "integrity": "sha512-d423TJMnJGu80/eSgfQ5w/R+0zFJvdtTxwtF9KzFFunOpSeD+79lHJQIiAhluJoyGRbvj9NZJsl9WjCUo0ND7Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "bs-logger": "^0.2.6", + "ejs": "^3.1.10", + "fast-json-stable-stringify": "^2.1.0", + "json5": "^2.2.3", + "lodash.memoize": "^4.1.2", + "make-error": "^1.3.6", + "semver": "^7.7.2", + "type-fest": "^4.41.0", + "yargs-parser": "^21.1.1" + }, + "bin": { + "ts-jest": "cli.js" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || ^18.0.0 || >=20.0.0" + }, + "peerDependencies": { + "@babel/core": ">=7.0.0-beta.0 <8", + "@jest/transform": "^29.0.0 || ^30.0.0", + "@jest/types": "^29.0.0 || ^30.0.0", + "babel-jest": "^29.0.0 || ^30.0.0", + "jest": "^29.0.0 || ^30.0.0", + "jest-util": "^29.0.0 || ^30.0.0", + "typescript": ">=4.3 <6" + }, + "peerDependenciesMeta": { + "@babel/core": { + "optional": true + }, + "@jest/transform": { + "optional": true + }, + "@jest/types": { + "optional": true + }, + "babel-jest": { + "optional": true + }, + "esbuild": { + "optional": true + }, + "jest-util": { + "optional": true + } + } + }, + "node_modules/ts-jest/node_modules/semver": { + "version": "7.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz", + "integrity": "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/ts-jest/node_modules/type-fest": { + "version": "4.41.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.41.0.tgz", + "integrity": "sha512-TeTSQ6H5YHvpqVwBRcnLDCBnDOHWYu7IvGbHT6N8AOymcr9PJGjc1GTtiWZTYg0NCgYwvnYWEkVChQAr9bjfwA==", + "dev": true, + "license": "(MIT OR CC0-1.0)", + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/ts-node": { "version": "10.9.2", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", diff --git a/package.json b/package.json index f9371ee..9c88474 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "", "main": "index.js", "scripts": { - "test": "jest" + "test": "jest", + "coverage": "jest --coverage" }, "repository": { "type": "git", @@ -21,7 +22,9 @@ "homepage": "https://github.com/gemtechd/build-tests-ts#readme", "devDependencies": { "@types/jest": "^30.0.0", + "@types/mocha": "^10.0.10", "jest": "^30.0.4", + "ts-jest": "^29.4.0", "ts-node": "^10.9.2", "typescript": "^5.8.3" } diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..28adb67 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,133 @@ +{ + + + + "compilerOptions": { + /* Visit https://aka.ms/tsconfig to read more about this file */ + + /* Projects */ + // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ + // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ + // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ + // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ + + /* Language and Environment */ + "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + // "jsx": "preserve", /* Specify what JSX code is generated. */ + // "libReplacement": true, /* Enable lib replacement. */ + // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ + // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ + // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ + // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ + // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ + // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ + // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ + // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ + + /* Modules */ + "module": "commonjs", /* Specify what module code is generated. */ + // "rootDir": "./", /* Specify the root folder within your source files. */ + // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ + // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ + // "types": [], /* Specify type package names to be included without being referenced in a source file. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ + // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ + // "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */ + // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ + // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ + // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ + // "noUncheckedSideEffectImports": true, /* Check side effect imports. */ + // "resolveJsonModule": true, /* Enable importing .json files. */ + // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ + // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ + + /* JavaScript Support */ + // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ + // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ + + /* Emit */ + // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + // "declarationMap": true, /* Create sourcemaps for d.ts files. */ + // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ + // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ + // "noEmit": true, /* Disable emitting files from a compilation. */ + // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ + // "outDir": "./", /* Specify an output folder for all emitted files. */ + // "removeComments": true, /* Disable emitting comments. */ + // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ + // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ + // "newLine": "crlf", /* Set the newline character for emitting files. */ + // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ + // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ + // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ + // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + + /* Interop Constraints */ + // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ + // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ + // "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */ + // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ + // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + + /* Type Checking */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ + // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ + // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ + // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + // "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */ + // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ + // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ + // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ + // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ + // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ + // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ + // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ + // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ + // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ + + /* Completeness */ + // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ + } + , + // "include": ["src/**/*.ts", "tests/**/*.ts"], + // "exclude": ["node_modules"] +} + + +// { +// "compilerOptions": { +// "target": "es6", +// "module": "commonjs", +// "strict": true, +// "esModuleInterop": true, +// "types": ["jest", "node"], +// "skipLibCheck": true +// }, +// "include": ["src/**/*.ts", "tests/**/*.ts"], +// "exclude": ["node_modules"] +// }