diff --git a/.github/workflows/vitest.yml b/.github/workflows/vitest.yml new file mode 100644 index 0000000..7e03047 --- /dev/null +++ b/.github/workflows/vitest.yml @@ -0,0 +1,20 @@ +name: Run unit tests + +on: + - push + - pull_request + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - uses: pnpm/action-setup@v3 + with: + version: 8 + run_install: true + + - name: Run tests + run: pnpm test run diff --git a/src/lib/cosinePairings.test.ts b/src/lib/cosinePairings.test.ts index 1577c9b..6658106 100644 --- a/src/lib/cosinePairings.test.ts +++ b/src/lib/cosinePairings.test.ts @@ -7,20 +7,26 @@ import EmbeddingCache from "@/worker/EmbeddingCache"; const cityFactsDataset = exampleDatasets.cityFacts; -test("computeCosinePairings should produce groundtruth cosine values within 5 decimal places", async () => { - const cityFactsPairingsResult = await fetch(cityFactsDataset.datasetURL); - const cityFactsPairings = await cityFactsPairingsResult.json(); - const cityFactsEmbeddingsResult = await fetch(cityFactsDataset.embeddingsURL); - const cityFactsEmbeddings = await cityFactsEmbeddingsResult.json(); - const embeddingCache = new EmbeddingCache(); - embeddingCache.addToCache(cityFactsEmbeddings); +test( + "computeCosinePairings should produce groundtruth cosine values within 5 decimal places", + async () => { + const cityFactsPairingsResult = await fetch(cityFactsDataset.datasetURL); + const cityFactsPairings = await cityFactsPairingsResult.json(); + const cityFactsEmbeddingsResult = await fetch( + cityFactsDataset.embeddingsURL + ); + const cityFactsEmbeddings = await cityFactsEmbeddingsResult.json(); + const embeddingCache = new EmbeddingCache(); + embeddingCache.addToCache(cityFactsEmbeddings); - const tensorDataset = pairingToDataset(cityFactsPairings, embeddingCache); - const cosinePairings = await computeCosinePairings(tensorDataset); - for (let i = 0; i < cosinePairings.length; i++) { - expect( - cosinePairings[i][0], - `cosinePairings[${i}] is within 5 decimal places of groundtruth` - ).toBeCloseTo(citiesCosinePairingsGroundtruth[i][0], 5); - } -}); + const tensorDataset = pairingToDataset(cityFactsPairings, embeddingCache); + const cosinePairings = await computeCosinePairings(tensorDataset); + for (let i = 0; i < cosinePairings.length; i++) { + expect( + cosinePairings[i][0], + `cosinePairings[${i}] is within 5 decimal places of groundtruth` + ).toBeCloseTo(citiesCosinePairingsGroundtruth[i][0], 5); + } + }, + { timeout: 15000 } +);