Skip to content

Commit 89f05a8

Browse files
committed
chore: swap to vite and vitest
vite and vitest allow a singular configuration & leads to faster compile times!
1 parent 787095d commit 89f05a8

File tree

9 files changed

+70
-79
lines changed

9 files changed

+70
-79
lines changed

.github/workflows/premerge.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ jobs:
1515
uses: DeterminateSystems/magic-nix-cache-action@main
1616

1717
- name: Install dependencies
18-
run: nix develop --impure --command npm install
18+
run: nix develop --impure --command npm install
19+
20+
- name: Check
21+
run: nix develop --impure --command npm run check
1922

2023
- name: Build
2124
run: nix develop --impure --command npm run build
2225

2326
- name: Test
24-
run: nix develop --impure --command npm run test
27+
run: nix develop --impure --command npm run test

package.json

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"name": "obsidian-todoist-plugin",
33
"version": "1.12.0",
44
"description": "A Todoist plugin for Obsidian",
5-
"main": "src/index.js",
65
"scripts": {
7-
"dev": "npm run build && cp -R dist/* ../../test-vault/.obsidian/plugins/todoist-sync-plugin/",
8-
"build": "svelte-check && rollup -c",
9-
"test": "npx mocha -r ts-node/register 'src/**/*.test.ts'",
6+
"check": "svelte-check",
7+
"dev": "npm run check && vite build",
8+
"build": "vite build",
9+
"test": "vitest",
1010
"format": "prettier --write src/**/*",
1111
"lint": "prettier --check src/**/*"
1212
},
@@ -23,24 +23,15 @@
2323
"yaml": "^2.1.3"
2424
},
2525
"devDependencies": {
26-
"@rollup/plugin-commonjs": "^24.0.0",
27-
"@rollup/plugin-node-resolve": "^15.0.1",
28-
"@rollup/plugin-typescript": "^10.0.1",
26+
"@sveltejs/vite-plugin-svelte": "^3.0.2",
2927
"@tsconfig/svelte": "^5.0.0",
30-
"@types/chai": "^4.3.4",
31-
"@types/mocha": "^10.0.1",
3228
"@types/node": "^18.11.17",
33-
"chai": "^4.3.7",
34-
"mocha": "^10.2.0",
3529
"prettier": "^2.8.1",
3630
"prettier-plugin-svelte": "^2.9.0",
37-
"rollup": "^3.8.1",
38-
"rollup-plugin-copy": "^3.4.0",
39-
"rollup-plugin-postcss": "^4.0.2",
40-
"rollup-plugin-svelte": "^7.1.5",
4131
"svelte-check": "^3.0.1",
42-
"svelte-preprocess": "^5.0.0",
43-
"ts-node": "^10.9.1",
44-
"typescript": "^5.3.3"
32+
"typescript": "^5.3.3",
33+
"vite": "^5.1.0",
34+
"vitest": "^1.2.2",
35+
"vite-plugin-static-copy": "^1.0.1"
4536
}
4637
}

rollup.config.mjs

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/api/domain/dueDate.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { assert } from "chai";
2-
import "mocha";
1+
import { describe, it, expect } from "vitest";
32
import { getDueDateInfo, type DueDate, type DueDateInfo } from "./dueDate";
43
import moment from "moment";
54

@@ -71,7 +70,7 @@ describe("getDueDateInfo", () => {
7170
for (const tc of testcases) {
7271
it(tc.description, () => {
7372
const actual = getDueDateInfo(tc.input);
74-
assert.deepEqual(actual, tc.expected);
73+
expect(actual).toStrictEqual(tc.expected);
7574
});
7675
}
7776
});

src/data/transformations.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import "mocha";
21
import type { Task } from "./task";
32
import type { Project } from "../api/domain/project";
43
import { UnknownProject, groupByProject, type GroupedTasks, sortTasks, type TaskTree, buildTaskTree } from "./transformations";
5-
import { assert } from "chai";
64
import { SortingVariant } from "../query/query";
5+
import { expect, describe, it } from "vitest";
76

87
function makeTask(id: string, opts?: Partial<Task>): Task {
98
return {
@@ -99,7 +98,7 @@ describe("groupByProject", () => {
9998
// Sort to make comparisons easier to reason about
10099
grouped.sort((a, b) => a.project.order - b.project.order);
101100

102-
assert.deepEqual(grouped, tc.expected);
101+
expect(grouped).toStrictEqual(tc.expected);
103102
});
104103
}
105104
});
@@ -334,7 +333,7 @@ describe("sortTasks", () => {
334333
const cloned = [...tc.input];
335334
sortTasks(cloned, tc.sortingOpts);
336335

337-
assert.deepEqual(cloned, tc.expectedOutput);
336+
expect(cloned).toStrictEqual(tc.expectedOutput);
338337
});
339338
}
340339
});
@@ -430,7 +429,7 @@ describe("buildTaskTree", () => {
430429
for (const tc of testcases) {
431430
it(tc.description, () => {
432431
const trees = buildTaskTree(tc.input);
433-
assert.deepEqual(trees, tc.output);
432+
expect(trees).toStrictEqual(tc.output);
434433
});
435434
}
436435
});

src/query/parser.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import "mocha";
2-
import { assert } from "chai";
1+
import { describe, it, expect } from "vitest";
32
import { parseQuery, ParsingError } from "./parser";
43
import { type Query, SortingVariant, ShowMetadataVariant } from "./query";
54

@@ -98,7 +97,7 @@ describe("parseQuery - rejections", () => {
9897

9998
for (const tc of testcases) {
10099
it(tc.description, () => {
101-
assert.throws(() => { parseQuery(JSON.stringify(tc.input)); }, ParsingError);
100+
expect(() => { parseQuery(JSON.stringify(tc.input)); }).toThrowError(ParsingError);
102101
});
103102
}
104103
});
@@ -191,7 +190,7 @@ describe("parseQuery", () => {
191190
for (const tc of testcases) {
192191
it(tc.description, () => {
193192
const output = parseQuery(JSON.stringify(tc.input));
194-
assert.deepEqual(output, tc.expectedOutput);
193+
expect(output).toStrictEqual(tc.expectedOutput);
195194
});
196195
}
197196
});

src/query/replacements.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import "mocha";
2-
import { assert } from "chai";
1+
import { describe, it, expect } from "vitest";
32
import { applyReplacements } from "./replacements";
43
import type { Query } from "./query";
54
import type { MarkdownPostProcessorContext, MarkdownRenderChild, MarkdownSectionInformation } from "obsidian";
@@ -58,7 +57,7 @@ describe("applyReplacements", () => {
5857

5958
applyReplacements(query, new FakeContext(tc.filePath ?? ""));
6059

61-
assert.equal(query.filter, tc.expectedFilter);
60+
expect(query.filter).toBe(tc.expectedFilter);
6261
});
6362
}
6463
});

svelte.config.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
2+
3+
export default {
4+
preprocess: vitePreprocess(),
5+
}

vite.config.mts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { configDefaults, defineConfig } from 'vitest/config'
2+
import { svelte } from '@sveltejs/vite-plugin-svelte'
3+
import { viteStaticCopy } from 'vite-plugin-static-copy'
4+
import { resolve } from 'path'
5+
6+
export default defineConfig({
7+
plugins: [
8+
svelte({
9+
emitCss: false,
10+
}),
11+
viteStaticCopy({
12+
targets: [
13+
{
14+
src: "styles.css",
15+
dest: "",
16+
},
17+
{
18+
src: "manifest.json",
19+
dest: "",
20+
}
21+
]
22+
}),
23+
],
24+
build: {
25+
// We aren't building a website, so we build in library mode
26+
// and bundle the output using our index.ts as the entrypoint.
27+
lib: {
28+
entry: resolve(__dirname, "src/index.ts"),
29+
fileName: "main",
30+
formats: ["cjs"]
31+
},
32+
rollupOptions: {
33+
external: ["obsidian"]
34+
}
35+
},
36+
test: {
37+
watch: false,
38+
exclude: [...configDefaults.exclude, ".direnv/**/*"],
39+
}
40+
})

0 commit comments

Comments
 (0)