Skip to content

Commit

Permalink
Use vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Dec 12, 2024
1 parent 487e416 commit 824eb7f
Show file tree
Hide file tree
Showing 10 changed files with 575 additions and 1,954 deletions.
13 changes: 12 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import tseslint from "typescript-eslint";

export default tseslint.config(
{
ignores: ["**/build/**/*", "**/dist/**/*", "**/esm/**/*", "**/public/**/*"],
ignores: [
"**/build/**/*",
"**/dist/**/*",
"**/esm/**/*",
"**/public/**/*",
"eslint.config.mjs",
],
},
{
languageOptions: {
Expand Down Expand Up @@ -42,6 +48,11 @@ export default tseslint.config(
},
{
rules: {
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-base-to-string": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"react/react-in-jsx-scope": "off",
"no-console": [
"warn",
{
Expand Down
6 changes: 0 additions & 6 deletions jest.config.js

This file was deleted.

6 changes: 3 additions & 3 deletions lib/src/accessFasta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export async function accessFasta(
const downstream = await t.getSequence(refseq, end, downstreamend);

return {
seq: seq || "",
upstream: upstream || "",
downstream: downstream || "",
seq: seq ?? "",
upstream: upstream ?? "",
downstream: downstream ?? "",
};
}
15 changes: 9 additions & 6 deletions lib/src/components/GenericGeneSeqPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { useState, useEffect } from "react";
import GenericSeqPanel from "./GenericSeqPanel";
import transcriptList from "../fetchTranscripts";
Expand All @@ -19,7 +18,7 @@ export default function GenericGeneSeqPanel(props: {
const [result, setResult] = useState<Feature[]>();
const [error, setError] = useState<unknown>();
const [transcript, setTranscript] = useState<Feature>();
const feature = transcript || result?.[0];
const feature = transcript ?? result?.[0];
const [model] = useState(SequenceFeatureDetailsF().create({}));

useEffect(() => {
Expand Down Expand Up @@ -51,9 +50,9 @@ export default function GenericGeneSeqPanel(props: {
<p>
Transcript:
<select
onChange={e =>
{ setTranscript(result.find(r => r.id() === e.target.value)); }
}
onChange={e => {
setTranscript(result.find(r => r.id() === e.target.value));
}}
>
{result.map(r => (
<option key={r.id()} value={r.id()}>
Expand All @@ -62,7 +61,11 @@ export default function GenericGeneSeqPanel(props: {
))}
</select>
&nbsp; Mode:
<select onChange={e => { model.setMode(e.target.value); }}>
<select
onChange={e => {
model.setMode(e.target.value);
}}
>
<option value="gene">gene</option>
<option value="cds">CDS</option>
<option value="cdna">cDNA</option>
Expand Down
12 changes: 8 additions & 4 deletions lib/src/components/GenericSeqPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { useState, useEffect, useRef } from "react";
import SequencePanel from "@jbrowse/core/BaseFeatureWidget/SequenceFeatureDetails/SequencePanel";
import { assembleBundle } from "../assembleBundle";
Expand Down Expand Up @@ -38,6 +37,7 @@ export default function GenericSeqPanel({
const [tooltipOpen, setTooltipOpen] = useState(false);

useEffect(() => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
(async () => {
try {
const res = await assembleBundle({
Expand Down Expand Up @@ -80,9 +80,11 @@ export default function GenericSeqPanel({
onClick={() => {
const ref = seqPanelRef.current;
if (ref) {
copy(ref.textContent || "", { format: "text/plain" });
copy(ref.textContent ?? "", { format: "text/plain" });
setCopied(true);
setTimeout(() => { setCopied(false); }, 1000);
setTimeout(() => {
setCopied(false);
}, 1000);
}
}}
>
Expand All @@ -101,7 +103,9 @@ export default function GenericSeqPanel({
}
copy(ref.innerHTML, { format: "text/html" });
setCopiedHtml(true);
setTimeout(() => { setCopiedHtml(false); }, 1000);
setTimeout(() => {
setCopiedHtml(false);
}, 1000);
}}
>
{copiedHtml ? "Copied to clipboard!" : "Copy highlighted fasta"}
Expand Down
5 changes: 3 additions & 2 deletions lib/src/fetchTranscripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ export default async function fetchTranscripts({
start: start,
end: end,
})) {
if (feature.get("name") === gene) {
return feature.get("subfeatures");
const f = feature as Feature;
if (f.get("name") === gene) {
return f.get("subfeatures") ?? [];
}
}
return [];
Expand Down
11 changes: 5 additions & 6 deletions lib/src/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

import React from "react";
/**
* @vitest-environment jsdom
*/

import { test } from "vitest";
import { render } from "@testing-library/react";
import GenericGeneSeqPanel from "./components/GenericGeneSeqPanel";
import fetch from "node-fetch";

// @ts-expect-error
globalThis.fetch = fetch;

test("expect protein rendering", async () => {
const { findByText } = render(
Expand Down
5 changes: 0 additions & 5 deletions lib/src/setupTests.js

This file was deleted.

13 changes: 5 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
"app"
],
"scripts": {
"test": "jest",
"lint": "eslint lib app"
"test": "vitest",
"lint": "eslint"
},
"devDependencies": {
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.1.0",
"@testing-library/user-event": "^14.4.3",
"@types/jest": "^29.5.14",
"@types/node": "^20.14.2",
"@types/node-fetch": "^2.6.12",
"@typescript-eslint/eslint-plugin": "^7.13.0",
Expand All @@ -24,13 +22,12 @@
"eslint-plugin-react-hooks": "^5.1.0",
"eslint-plugin-react-refresh": "^0.4.16",
"eslint-plugin-unicorn": "^56.0.1",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"jsdom": "^25.0.1",
"node-fetch": "^2.0.0",
"prettier": "^3.4.2",
"rimraf": "^6.0.1",
"ts-jest": "^29.2.5",
"typescript": "^5.7.2",
"typescript-eslint": "^8.18.0"
"typescript-eslint": "^8.18.0",
"vitest": "^2.1.8"
}
}
Loading

0 comments on commit 824eb7f

Please sign in to comment.