-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvitest.setup.js
31 lines (27 loc) · 925 Bytes
/
vitest.setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import fs from "node:fs";
import { beforeAll } from "vitest";
const testDataDir = "test-data";
beforeAll(async () => {
if (!fs.existsSync(testDataDir)) {
fs.mkdirSync(testDataDir);
//~ Tan et al. 2018
const url =
"https://dl.dropboxusercontent.com/scl/fi/lzv3ba5paum6srhte4z2t/GSM3271406_pbmc_18.impute.3dg.txt?rlkey=dc7k1gg5ghv2v7dsl0gg1uoo9&dl=0";
const filename = "tan2018.tsv";
await downloadFile(url, filename);
} else {
console.log("no need to fetch test data");
}
});
async function downloadFile(url, filename) {
console.log(`downloading: ${url}`);
const file = await fetchFile(url);
const path = `${testDataDir}/${filename}`;
fs.writeFileSync(path, file);
}
async function fetchFile(url) {
const response = await fetch(url);
if (!response.ok) throw new Error(`fetch failed: ${response.status}`);
const fileContent = await response.text();
return fileContent;
}