Skip to content

Commit

Permalink
test: rename test db to test data
Browse files Browse the repository at this point in the history
  • Loading branch information
velut committed Apr 23, 2024
1 parent 208a6bc commit 8be7ff9
Show file tree
Hide file tree
Showing 37 changed files with 66 additions and 63 deletions.
Binary file removed data/get-abbreviated-packument.db.gz
Binary file not shown.
Binary file removed data/get-package-versions-downloads.db.gz
Binary file not shown.
Binary file removed data/get-packument.db.gz
Binary file not shown.
Binary file removed data/get-registry-metadata.db.gz
Binary file not shown.
Binary file removed data/get-registry-signing-keys.db.gz
Binary file not shown.
Binary file removed data/search-packages.db.gz
Binary file not shown.
Binary file added data/test/get-abbreviated-packument.json.gz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added data/test/get-packument.json.gz
Binary file not shown.
Binary file not shown.
Binary file added data/test/get-registry-metadata.json.gz
Binary file not shown.
Binary file added data/test/get-registry-signing-keys.json.gz
Binary file not shown.
Binary file added data/test/search-packages.json.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"build": "tsc --noEmit && tsup",
"attw": "attw --pack . --ignore-rules cjs-resolves-to-esm",
"test": "vitest",
"test:update-db": "bun run scripts/update-test-db.ts",
"test:update-data": "bun run scripts/update-test-data.ts",
"test:ci": "vitest run --coverage --bail 1",
"lint": "prettier --check .",
"format": "prettier --write .",
Expand Down
3 changes: 3 additions & 0 deletions scripts/update-test-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { $ } from "bun";

await $`UPDATE_TEST_DATA=true vitest run --bail 1 --test-timeout=60000`;
3 changes: 0 additions & 3 deletions scripts/update-test-db.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/get-abbreviated-packument.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { afterAll, beforeAll, expect, test } from "vitest";
import { testDb } from "../utils/test-db";
import { testData } from "../utils/test-data";
import { getAbbreviatedPackument } from "./get-abbreviated-packument";

const { loadIntoCache, updateFromCache } = testDb("get-abbreviated-packument");
const { loadIntoCache, updateFromCache } = testData("get-abbreviated-packument");

beforeAll(async () => {
await loadIntoCache();
Expand Down
4 changes: 2 additions & 2 deletions src/get-bulk-daily-package-downloads.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { afterAll, beforeAll, expect, test } from "vitest";
import { testDb } from "../utils/test-db";
import { testData } from "../utils/test-data";
import { getBulkDailyPackageDownloads } from "./get-bulk-daily-package-downloads";

const { loadIntoCache, updateFromCache } = testDb("get-bulk-daily-package-downloads");
const { loadIntoCache, updateFromCache } = testData("get-bulk-daily-package-downloads");

beforeAll(async () => {
await loadIntoCache();
Expand Down
4 changes: 2 additions & 2 deletions src/get-bulk-package-downloads.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { afterAll, beforeAll, expect, test } from "vitest";
import { testDb } from "../utils/test-db";
import { testData } from "../utils/test-data";
import { getBulkPackageDownloads } from "./get-bulk-package-downloads";

const { loadIntoCache, updateFromCache } = testDb("get-bulk-package-downloads");
const { loadIntoCache, updateFromCache } = testData("get-bulk-package-downloads");

beforeAll(async () => {
await loadIntoCache();
Expand Down
4 changes: 2 additions & 2 deletions src/get-daily-package-downloads.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { afterAll, beforeAll, expect, test } from "vitest";
import { testDb } from "../utils/test-db";
import { testData } from "../utils/test-data";
import { getDailyPackageDownloads } from "./get-daily-package-downloads";

const { loadIntoCache, updateFromCache } = testDb("get-daily-package-downloads");
const { loadIntoCache, updateFromCache } = testData("get-daily-package-downloads");

beforeAll(async () => {
await loadIntoCache();
Expand Down
4 changes: 2 additions & 2 deletions src/get-daily-registry-downloads.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { afterAll, beforeAll, expect, test } from "vitest";
import { testDb } from "../utils/test-db";
import { testData } from "../utils/test-data";
import { getDailyRegistryDownloads } from "./get-daily-registry-downloads";

const { loadIntoCache, updateFromCache } = testDb("get-daily-registry-downloads");
const { loadIntoCache, updateFromCache } = testData("get-daily-registry-downloads");

beforeAll(async () => {
await loadIntoCache();
Expand Down
4 changes: 2 additions & 2 deletions src/get-package-downloads.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { afterAll, beforeAll, expect, test } from "vitest";
import { testDb } from "../utils/test-db";
import { testData } from "../utils/test-data";
import { getPackageDownloads } from "./get-package-downloads";

const { loadIntoCache, updateFromCache } = testDb("get-package-downloads");
const { loadIntoCache, updateFromCache } = testData("get-package-downloads");

beforeAll(async () => {
await loadIntoCache();
Expand Down
4 changes: 2 additions & 2 deletions src/get-package-manifest.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { afterAll, beforeAll, expect, test } from "vitest";
import { testDb } from "../utils/test-db";
import { testData } from "../utils/test-data";
import { getPackageManifest } from "./get-package-manifest";

const { loadIntoCache, updateFromCache } = testDb("get-package-manifest");
const { loadIntoCache, updateFromCache } = testData("get-package-manifest");

beforeAll(async () => {
await loadIntoCache();
Expand Down
4 changes: 2 additions & 2 deletions src/get-package-versions-downloads.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { afterAll, beforeAll, expect, test } from "vitest";
import { testDb } from "../utils/test-db";
import { testData } from "../utils/test-data";
import { getPackageVersionsDownloads } from "./get-package-versions-downloads";

const { loadIntoCache, updateFromCache } = testDb("get-package-versions-downloads");
const { loadIntoCache, updateFromCache } = testData("get-package-versions-downloads");

beforeAll(async () => {
await loadIntoCache();
Expand Down
4 changes: 2 additions & 2 deletions src/get-packument.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { afterAll, beforeAll, expect, test } from "vitest";
import { testDb } from "../utils/test-db";
import { testData } from "../utils/test-data";
import { getPackument } from "./get-packument";

const { loadIntoCache, updateFromCache } = testDb("get-packument");
const { loadIntoCache, updateFromCache } = testData("get-packument");

beforeAll(async () => {
await loadIntoCache();
Expand Down
4 changes: 2 additions & 2 deletions src/get-registry-downloads.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { afterAll, beforeAll, expect, test } from "vitest";
import { testDb } from "../utils/test-db";
import { testData } from "../utils/test-data";
import { getRegistryDownloads } from "./get-registry-downloads";

const { loadIntoCache, updateFromCache } = testDb("get-registry-downloads");
const { loadIntoCache, updateFromCache } = testData("get-registry-downloads");

beforeAll(async () => {
await loadIntoCache();
Expand Down
4 changes: 2 additions & 2 deletions src/get-registry-metadata.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { afterAll, beforeAll, expect, test } from "vitest";
import { testDb } from "../utils/test-db";
import { testData } from "../utils/test-data";
import { getRegistryMetadata } from "./get-registry-metadata";

const { loadIntoCache, updateFromCache } = testDb("get-registry-metadata");
const { loadIntoCache, updateFromCache } = testData("get-registry-metadata");

beforeAll(async () => {
await loadIntoCache();
Expand Down
4 changes: 2 additions & 2 deletions src/get-registry-signing-keys.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { afterAll, beforeAll, expect, test } from "vitest";
import { testDb } from "../utils/test-db";
import { testData } from "../utils/test-data";
import { getRegistrySigningKeys } from "./get-registry-signing-keys";

const { loadIntoCache, updateFromCache } = testDb("get-registry-signing-keys");
const { loadIntoCache, updateFromCache } = testData("get-registry-signing-keys");

beforeAll(async () => {
await loadIntoCache();
Expand Down
4 changes: 2 additions & 2 deletions src/search-packages.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { afterAll, beforeAll, expect, test } from "vitest";
import { testDb } from "../utils/test-db";
import { testData } from "../utils/test-data";
import { searchPackages } from "./search-packages";

const { loadIntoCache, updateFromCache } = testDb("search-packages");
const { loadIntoCache, updateFromCache } = testData("search-packages");

beforeAll(async () => {
await loadIntoCache();
Expand Down
36 changes: 36 additions & 0 deletions utils/test-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { compressSync, decompressSync, strFromU8, strToU8 } from "fflate";
import fs from "node:fs/promises";
import { cache } from "../src/cache";
import { JsonStrip } from "./json-strip";

export const testData = (name: string) => {
const filename = `./data/test/${name}.json.gz`;
return {
loadIntoCache: async () => {
cache.clear();
if (process.env.UPDATE_TEST_DATA === "true") {
// Don't load old data into cache if we're updating test data with fresh data.
return;
}
const buf = await fs.readFile(filename);
const data = JSON.parse(strFromU8(decompressSync(buf))) as [string, unknown][];
if (data.length > 0) {
cache.resize(data.length);
for (const [key, value] of data) {
cache.set(key, value);
}
}
},
updateFromCache: async () => {
if (process.env.UPDATE_TEST_DATA === "true" && cache.size > 0) {
const entries = [...cache.entriesAscending()].map(([key, value]) => [
key,
JsonStrip.parse(value),
]);
const data = compressSync(strToU8(JSON.stringify(entries)));
await fs.writeFile(filename, data);
}
cache.clear();
},
};
};
33 changes: 0 additions & 33 deletions utils/test-db.ts

This file was deleted.

0 comments on commit 8be7ff9

Please sign in to comment.