Skip to content

Commit

Permalink
chore: swap to vite and vitest
Browse files Browse the repository at this point in the history
vite and vitest allow a singular configuration & leads to faster compile times!
  • Loading branch information
jamiebrynes7 committed Feb 11, 2024
1 parent 787095d commit 89f05a8
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 79 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/premerge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ jobs:
uses: DeterminateSystems/magic-nix-cache-action@main

- name: Install dependencies
run: nix develop --impure --command npm install
run: nix develop --impure --command npm install

- name: Check
run: nix develop --impure --command npm run check

- name: Build
run: nix develop --impure --command npm run build

- name: Test
run: nix develop --impure --command npm run test
run: nix develop --impure --command npm run test
27 changes: 9 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"name": "obsidian-todoist-plugin",
"version": "1.12.0",
"description": "A Todoist plugin for Obsidian",
"main": "src/index.js",
"scripts": {
"dev": "npm run build && cp -R dist/* ../../test-vault/.obsidian/plugins/todoist-sync-plugin/",
"build": "svelte-check && rollup -c",
"test": "npx mocha -r ts-node/register 'src/**/*.test.ts'",
"check": "svelte-check",
"dev": "npm run check && vite build",
"build": "vite build",
"test": "vitest",
"format": "prettier --write src/**/*",
"lint": "prettier --check src/**/*"
},
Expand All @@ -23,24 +23,15 @@
"yaml": "^2.1.3"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^24.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-typescript": "^10.0.1",
"@sveltejs/vite-plugin-svelte": "^3.0.2",
"@tsconfig/svelte": "^5.0.0",
"@types/chai": "^4.3.4",
"@types/mocha": "^10.0.1",
"@types/node": "^18.11.17",
"chai": "^4.3.7",
"mocha": "^10.2.0",
"prettier": "^2.8.1",
"prettier-plugin-svelte": "^2.9.0",
"rollup": "^3.8.1",
"rollup-plugin-copy": "^3.4.0",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-svelte": "^7.1.5",
"svelte-check": "^3.0.1",
"svelte-preprocess": "^5.0.0",
"ts-node": "^10.9.1",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"vite": "^5.1.0",
"vitest": "^1.2.2",
"vite-plugin-static-copy": "^1.0.1"
}
}
44 changes: 0 additions & 44 deletions rollup.config.mjs

This file was deleted.

5 changes: 2 additions & 3 deletions src/api/domain/dueDate.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { assert } from "chai";
import "mocha";
import { describe, it, expect } from "vitest";
import { getDueDateInfo, type DueDate, type DueDateInfo } from "./dueDate";
import moment from "moment";

Expand Down Expand Up @@ -71,7 +70,7 @@ describe("getDueDateInfo", () => {
for (const tc of testcases) {
it(tc.description, () => {
const actual = getDueDateInfo(tc.input);
assert.deepEqual(actual, tc.expected);
expect(actual).toStrictEqual(tc.expected);
});
}
});
9 changes: 4 additions & 5 deletions src/data/transformations.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import "mocha";
import type { Task } from "./task";
import type { Project } from "../api/domain/project";
import { UnknownProject, groupByProject, type GroupedTasks, sortTasks, type TaskTree, buildTaskTree } from "./transformations";
import { assert } from "chai";
import { SortingVariant } from "../query/query";
import { expect, describe, it } from "vitest";

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

assert.deepEqual(grouped, tc.expected);
expect(grouped).toStrictEqual(tc.expected);
});
}
});
Expand Down Expand Up @@ -334,7 +333,7 @@ describe("sortTasks", () => {
const cloned = [...tc.input];
sortTasks(cloned, tc.sortingOpts);

assert.deepEqual(cloned, tc.expectedOutput);
expect(cloned).toStrictEqual(tc.expectedOutput);
});
}
});
Expand Down Expand Up @@ -430,7 +429,7 @@ describe("buildTaskTree", () => {
for (const tc of testcases) {
it(tc.description, () => {
const trees = buildTaskTree(tc.input);
assert.deepEqual(trees, tc.output);
expect(trees).toStrictEqual(tc.output);
});
}
});
7 changes: 3 additions & 4 deletions src/query/parser.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import "mocha";
import { assert } from "chai";
import { describe, it, expect } from "vitest";
import { parseQuery, ParsingError } from "./parser";
import { type Query, SortingVariant, ShowMetadataVariant } from "./query";

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

for (const tc of testcases) {
it(tc.description, () => {
assert.throws(() => { parseQuery(JSON.stringify(tc.input)); }, ParsingError);
expect(() => { parseQuery(JSON.stringify(tc.input)); }).toThrowError(ParsingError);
});
}
});
Expand Down Expand Up @@ -191,7 +190,7 @@ describe("parseQuery", () => {
for (const tc of testcases) {
it(tc.description, () => {
const output = parseQuery(JSON.stringify(tc.input));
assert.deepEqual(output, tc.expectedOutput);
expect(output).toStrictEqual(tc.expectedOutput);
});
}
});
5 changes: 2 additions & 3 deletions src/query/replacements.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import "mocha";
import { assert } from "chai";
import { describe, it, expect } from "vitest";
import { applyReplacements } from "./replacements";
import type { Query } from "./query";
import type { MarkdownPostProcessorContext, MarkdownRenderChild, MarkdownSectionInformation } from "obsidian";
Expand Down Expand Up @@ -58,7 +57,7 @@ describe("applyReplacements", () => {

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

assert.equal(query.filter, tc.expectedFilter);
expect(query.filter).toBe(tc.expectedFilter);
});
}
});
Expand Down
5 changes: 5 additions & 0 deletions svelte.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'

export default {
preprocess: vitePreprocess(),
}
40 changes: 40 additions & 0 deletions vite.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { configDefaults, defineConfig } from 'vitest/config'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import { viteStaticCopy } from 'vite-plugin-static-copy'
import { resolve } from 'path'

export default defineConfig({
plugins: [
svelte({
emitCss: false,
}),
viteStaticCopy({
targets: [
{
src: "styles.css",
dest: "",
},
{
src: "manifest.json",
dest: "",
}
]
}),
],
build: {
// We aren't building a website, so we build in library mode
// and bundle the output using our index.ts as the entrypoint.
lib: {
entry: resolve(__dirname, "src/index.ts"),
fileName: "main",
formats: ["cjs"]
},
rollupOptions: {
external: ["obsidian"]
}
},
test: {
watch: false,
exclude: [...configDefaults.exclude, ".direnv/**/*"],
}
})

0 comments on commit 89f05a8

Please sign in to comment.