Skip to content

Commit

Permalink
Switch test runner from Jest to Vitest (#1609)
Browse files Browse the repository at this point in the history
* Initial work to switch from Jest to Vitest

* Fix for tsconfig.test.json to satisfy picocolors import

* Enable Vitest globals and remove imports for Vitest

* Undo formatting changes to files that didn't need touched

* Fix issue with test-types task by including Vitest global types

* Fix coverage tests by adding @vitest/coverage-istanbul

* Add lcov recorder for test coverage

* Remove Jest config

* Add text reporter so CLI still reports coverage amounts

* Move Vite config to Solid package

* Split include into include/exclude paths

* Switch to c8 instead of istanbul for coverage

* Create twenty-jobs-study.md

---------

Co-authored-by: Ryan Carniato <ryansolid@gmail.com>
  • Loading branch information
niccholaspage and ryansolid committed Mar 26, 2023
1 parent 220a289 commit 620c763
Show file tree
Hide file tree
Showing 27 changed files with 1,359 additions and 1,930 deletions.
6 changes: 6 additions & 0 deletions .changeset/twenty-jobs-study.md
@@ -0,0 +1,6 @@
---
"solid-js": patch
"test-integration": patch
---

Switch test runner from Jest to Vitest
12 changes: 5 additions & 7 deletions package.json
Expand Up @@ -30,29 +30,27 @@
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-replace": "^5.0.2",
"@types/jest": "^28.1.6",
"@types/node": "^18.11.19",
"babel-jest": "^28.1.3",
"@vitest/coverage-c8": "^0.29.7",
"babel-plugin-jsx-dom-expressions": "^0.35.19",
"coveralls": "^3.1.1",
"csstype": "^3.1.0",
"dom-expressions": "0.35.22",
"fast-glob": "^3.2.11",
"hyper-dom-expressions": "0.35.22",
"jest": "^28.1.3",
"jest-environment-jsdom": "^28.1.3",
"jest-ts-webcompat-resolver": "^1.0.0",
"jsdom": "^21.1.1",
"lit-dom-expressions": "0.35.22",
"ncp": "^2.0.0",
"npm-run-all": "^4.1.5",
"rimraf": "^3.0.2",
"rollup": "^3.7.5",
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-copy": "^3.4.0",
"solid-jest": "^0.2.0",
"symlink-dir": "^5.0.1",
"tsconfig-replace-paths": "^0.0.11",
"turbo": "^1.3.1",
"typescript": "^4.9.5"
"typescript": "^4.9.5",
"vite-plugin-solid": "^2.6.1",
"vitest": "^0.29.3"
}
}
8 changes: 0 additions & 8 deletions packages/solid/jest.config.cjs

This file was deleted.

4 changes: 2 additions & 2 deletions packages/solid/package.json
Expand Up @@ -266,8 +266,8 @@
"types:universal": "tsc --project ./universal/tsconfig.json && ncp ../../node_modules/dom-expressions/src/universal.d.ts ./universal/types/universal.d.ts",
"bench": "node --allow-natives-syntax bench/bench.cjs",
"link": "symlink-dir . node_modules/solid-js",
"test": "jest",
"coverage": "jest --coverage",
"test": "vitest run",
"coverage": "vitest run --coverage",
"test-types": "tsc --project tsconfig.test.json"
},
"keywords": [
Expand Down
25 changes: 13 additions & 12 deletions packages/solid/store/test/mutable.spec.ts
Expand Up @@ -219,18 +219,19 @@ describe("Setting state from Effects", () => {
expect(state!.data).toBe("signal");
});

test("Select Promise", done => {
createRoot(async () => {
const p = new Promise<string>(resolve => {
setTimeout(resolve, 20, "promised");
}),
state = createMutable({ data: "" });
p.then(v => (state.data = v));
await p;
expect(state.data).toBe("promised");
done();
});
});
test("Select Promise", () =>
new Promise(done => {
createRoot(async () => {
const p = new Promise<string>(resolve => {
setTimeout(resolve, 20, "promised");
}),
state = createMutable({ data: "" });
p.then(v => (state.data = v));
await p;
expect(state.data).toBe("promised");
done(undefined);
});
}));
});

describe("State wrapping", () => {
Expand Down
23 changes: 12 additions & 11 deletions packages/solid/store/test/store.spec.ts
Expand Up @@ -548,18 +548,19 @@ describe("Setting state from Effects", () => {
expect(state.data).toBe("signal");
});

test("Select Promise", done => {
createRoot(async () => {
const p = new Promise<string>(resolve => {
setTimeout(resolve, 20, "promised");
test("Select Promise", () =>
new Promise(done => {
createRoot(async () => {
const p = new Promise<string>(resolve => {
setTimeout(resolve, 20, "promised");
});
const [state, setState] = createStore({ data: "" });
p.then(v => setState("data", v));
await p;
expect(state.data).toBe("promised");
done(undefined);
});
const [state, setState] = createStore({ data: "" });
p.then(v => setState("data", v));
await p;
expect(state.data).toBe("promised");
done();
});
});
}));
});

describe("Batching", () => {
Expand Down
23 changes: 14 additions & 9 deletions packages/solid/test/component.spec.ts
Expand Up @@ -104,14 +104,19 @@ describe("Clone Props", () => {
});

describe("Clone Store", () => {
const [state, setState] = createStore<{ a: string; b: string; c?: string }>({ a: "Hi", b: "Jo" });
const clone = mergeProps(state);
expect(clone.a).toBe("Hi");
expect(clone.b).toBe("Jo");
setState({ a: "Greetings", c: "John" });
expect(clone.a).toBe("Greetings");
expect(clone.b).toBe("Jo");
expect(clone.c).toBe("John");
test("simple set", () => {
const [state, setState] = createStore<{ a: string; b: string; c?: string }>({
a: "Hi",
b: "Jo"
});
const clone = mergeProps(state);
expect(clone.a).toBe("Hi");
expect(clone.b).toBe("Jo");
setState({ a: "Greetings", c: "John" });
expect(clone.a).toBe("Greetings");
expect(clone.b).toBe("Jo");
expect(clone.c).toBe("John");
});
});

describe("Merge Signal", () => {
Expand All @@ -124,7 +129,7 @@ describe("Merge Signal", () => {
c: "j"
}),
defaults: SimplePropTypes = { a: "yy", b: "ggg", d: "DD" };
let props!: SimplePropTypes;;
let props!: SimplePropTypes;
const res: string[] = [];
createRoot(() => {
props = mergeProps(defaults, s);
Expand Down
2 changes: 1 addition & 1 deletion packages/solid/test/dev.spec.ts
Expand Up @@ -124,7 +124,7 @@ describe("Dev features", () => {
});

test("OnStoreNodeUpdate Hook", () => {
const cb = jest.fn();
const cb = vi.fn();
global._$onStoreNodeUpdate = cb;
const [s, set] = createStore({ firstName: "John", lastName: "Smith", inner: { foo: 1 } });
expect(cb).toHaveBeenCalledTimes(0);
Expand Down
2 changes: 1 addition & 1 deletion packages/solid/test/observable.spec.ts
Expand Up @@ -18,7 +18,7 @@ describe("Observable operator", () => {

test("preserve the observer's next binding", () => {
const observer = {
next: jest.fn().mockReturnThis()
next: vi.fn().mockReturnThis()
};

createRoot(() => {
Expand Down
68 changes: 36 additions & 32 deletions packages/solid/test/scheduler.spec.ts
@@ -1,40 +1,44 @@
/** @jest-environment jsdom */
/** @vitest-environment jsdom */
import { cancelCallback, requestCallback } from "../src";
import "./MessageChannel";

describe("requestCallback basics", () => {
test("queue a task", done => {
requestCallback(() => {
done();
});
});
test("queue a task", () =>
new Promise(done => {
requestCallback(() => {
done(undefined);
});
}));

test("queue a task in correct order", done => {
let count = 0;
requestCallback(() => {
expect(count).toBe(2);
done();
});
requestCallback(
() => {
count++;
expect(count).toBe(1);
},
{ timeout: 10 }
);
requestCallback(
() => {
count++;
test("queue a task in correct order", () =>
new Promise(done => {
let count = 0;
requestCallback(() => {
expect(count).toBe(2);
},
{ timeout: 40 }
);
});

test("supports cancelling a callback", done => {
const task = requestCallback(() => { done(new Error('should not be called')) });
cancelCallback(task);
requestCallback(done);
});
done(undefined);
});
requestCallback(
() => {
count++;
expect(count).toBe(1);
},
{ timeout: 10 }
);
requestCallback(
() => {
count++;
expect(count).toBe(2);
},
{ timeout: 40 }
);
}));

test("supports cancelling a callback", () =>
new Promise((done, reject) => {
const task = requestCallback(() => {
reject(new Error("should not be called"));
});
cancelCallback(task);
requestCallback(() => done(undefined));
}));
});

0 comments on commit 620c763

Please sign in to comment.