Migrate to node:test

This commit is contained in:
Andras Schmelczer 2025-08-30 09:58:55 +01:00
parent 7aab7b05d6
commit bbbfc1a059
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
24 changed files with 759 additions and 6421 deletions

View file

@ -1,3 +0,0 @@
module.exports = {
preset: "ts-jest"
};

View file

@ -6,35 +6,33 @@
"scripts": {
"dev": "webpack watch --mode development",
"build": "webpack --mode production",
"test": "jest",
"test": "tsx --test src/**/*.test.ts",
"version": "node version-bump.mjs"
},
"keywords": [],
"author": "",
"license": "MIT",
"devDependencies": {
"@types/jest": "^30.0.0",
"@types/node": "^22.15.30",
"css-loader": "^7.1.2",
"date-fns": "^4.1.0",
"file-loader": "^6.2.0",
"fs-extra": "^11.3.0",
"jest": "^30.1.1",
"mini-css-extract-plugin": "^2.9.2",
"obsidian": "1.8.7",
"reconcile-text": "^0.5.0",
"resolve-url-loader": "^5.0.0",
"sass": "^1.91.0",
"sass-loader": "^16.0.5",
"sync-client": "file:../sync-client",
"terser-webpack-plugin": "^5.3.14",
"ts-jest": "^29.4.1",
"ts-loader": "^9.5.2",
"tslib": "2.8.1",
"tsx": "^4.20.5",
"typescript": "5.8.3",
"url": "^0.11.4",
"virtual-scroller": "^1.13.1",
"webpack": "^5.99.9",
"webpack-cli": "^6.0.1",
"reconcile-text": "^0.5.0"
"webpack-cli": "^6.0.1"
}
}

View file

@ -1,42 +1,44 @@
import { describe, it } from "node:test";
import assert from "node:assert";
import { lineAndColumnToPosition } from "./line-and-column-to-position";
describe("lineAndColumnToPosition", () => {
it("should return the correct position for the first line", () => {
const text = "Hello\nWorld";
const position = lineAndColumnToPosition(text, 0, 3);
expect(position).toBe(3);
assert.strictEqual(position, 3);
});
it("should return the correct position for the second line", () => {
const text = "Hello\nWorld";
const position = lineAndColumnToPosition(text, 1, 2);
expect(position).toBe(8);
assert.strictEqual(position, 8);
});
it("should return the correct position for an empty string", () => {
const text = "";
const position = lineAndColumnToPosition(text, 0, 0);
expect(position).toBe(0);
assert.strictEqual(position, 0);
});
it("with carrige return", () => {
expect(lineAndColumnToPosition("a\nb", 1, 1)).toBe(3);
expect(lineAndColumnToPosition("a\r\nb", 1, 1)).toBe(3);
assert.strictEqual(lineAndColumnToPosition("a\nb", 1, 1), 3);
assert.strictEqual(lineAndColumnToPosition("a\r\nb", 1, 1), 3);
});
it("should handle multi-line strings with varying lengths", () => {
const text = "Line1\nLongerLine2\nShort3";
const position = lineAndColumnToPosition(text, 2, 4);
expect(position).toBe(22);
assert.strictEqual(position, 22);
});
it("should throw an error if the line number is out of range", () => {
const text = "Line1\nLine2";
expect(() => lineAndColumnToPosition(text, 3, 0)).toThrow();
assert.throws(() => lineAndColumnToPosition(text, 3, 0));
});
it("should throw an error if the column number is out of range", () => {
const text = "Line1\nLine2";
expect(() => lineAndColumnToPosition(text, 1, 10)).toThrow();
assert.throws(() => lineAndColumnToPosition(text, 1, 10));
});
});

View file

@ -1,53 +1,58 @@
import { describe, test } from "node:test";
import assert from "node:assert";
import { positionToLineAndColumn } from "./position-to-line-and-column";
describe("positionToLineAndColumn", () => {
test("converts position to line and column in multi-line text", () => {
const text = "ab\ncd\n";
expect(positionToLineAndColumn(text, 0)).toEqual({
assert.deepStrictEqual(positionToLineAndColumn(text, 0), {
line: 0,
column: 0
});
expect(positionToLineAndColumn(text, 1)).toEqual({
assert.deepStrictEqual(positionToLineAndColumn(text, 1), {
line: 0,
column: 1
});
expect(positionToLineAndColumn(text, 2)).toEqual({
assert.deepStrictEqual(positionToLineAndColumn(text, 2), {
line: 0,
column: 2
});
expect(positionToLineAndColumn(text, 3)).toEqual({
assert.deepStrictEqual(positionToLineAndColumn(text, 3), {
line: 1,
column: 0
});
expect(positionToLineAndColumn(text, 4)).toEqual({
assert.deepStrictEqual(positionToLineAndColumn(text, 4), {
line: 1,
column: 1
});
expect(positionToLineAndColumn(text, 6)).toEqual({
assert.deepStrictEqual(positionToLineAndColumn(text, 6), {
line: 2,
column: 0
});
});
test("with carrige returns", () => {
expect(positionToLineAndColumn("a\nb", 3)).toEqual({
assert.deepStrictEqual(positionToLineAndColumn("a\nb", 3), {
line: 1,
column: 1
});
expect(positionToLineAndColumn("a\r\nb", 3)).toEqual({
assert.deepStrictEqual(positionToLineAndColumn("a\r\nb", 3), {
line: 1,
column: 1
});
});
test("handles empty input", () => {
expect(positionToLineAndColumn("", 0)).toEqual({ line: 0, column: 0 });
assert.deepStrictEqual(positionToLineAndColumn("", 0), {
line: 0,
column: 0
});
});
test("handles positions at the end of text", () => {
const text = "End";
expect(positionToLineAndColumn(text, 3)).toEqual({
assert.deepStrictEqual(positionToLineAndColumn(text, 3), {
line: 0,
column: 3
});
@ -55,7 +60,7 @@ describe("positionToLineAndColumn", () => {
test("throws error for position out of range", () => {
const text = "Short text";
expect(() => positionToLineAndColumn(text, 15)).toThrow();
expect(() => positionToLineAndColumn(text, -1)).toThrow();
assert.throws(() => positionToLineAndColumn(text, 15));
assert.throws(() => positionToLineAndColumn(text, -1));
});
});

View file

@ -8,7 +8,7 @@
"allowSyntheticDefaultImports": true,
"lib": [
"DOM",
"ESNext"
"ES2024"
]
},
"exclude": [