Skip to content

Commit

Permalink
move testing to vitest (#83)
Browse files Browse the repository at this point in the history
Still failing a test on wait_for_project_lock.
<!-- ELLIPSIS_HIDDEN -->


----

> [!IMPORTANT]
> Migrate testing framework from `uvu` to `vitest`, updating test scripts, dependencies, and test files accordingly.
> 
>   - **Testing Framework Migration**:
>     - Replace `uvu` with `vitest` in `package.json` test scripts.
>     - Remove `uvu` and related dependencies; add `vitest`.
>     - Add `vitest.config.ts` for configuration.
>   - **Test Files**:
>     - Convert test files from `.js` to `.ts` (e.g., `arrow.test.js` to `arrow.ts`).
>     - Update test syntax from `uvu` to `vitest` in `embedding.test.ts`, `neighbors.test.ts`, `project.test.ts`, and `user.test.ts`.
>     - Replace `assert` with `expect` in test assertions.
>   - **Miscellaneous**:
>     - Remove `project.test.js` and replace with `project.test.ts` with updated test cases.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=nomic-ai%2Fts-nomic&utm_source=github&utm_medium=referral)<sup> for ecd2422. It will automatically update as commits are pushed.</sup>


<!-- ELLIPSIS_HIDDEN -->
  • Loading branch information
bmschmidt authored Nov 4, 2024
1 parent d5893f3 commit 528867c
Show file tree
Hide file tree
Showing 10 changed files with 2,312 additions and 543 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ etc/openapi.json
private
dist
docs
.vscode
coverage
2,583 changes: 2,199 additions & 384 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 3 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
},
"scripts": {
"pretest": "npm run build",
"test": "env-cmd --file .env uvu tests -r esbuild-register",
"test:file": "env-cmd --file .env uvu -r esbuild-register tests",
"test:embeddings": "npm run test:file -- embedding.test.js",
"test": "vitest",
"build-types": "openapi-typescript https://staging-api-atlas.nomic.ai/v1/api-reference/openapi.json -o ./src/type-gen/openapi.ts --empty-objects-unknown | npx prettier ./src/type-gen/openapi.ts --write",
"build": "tsc",
"build:watch": "tsc -w",
Expand All @@ -29,30 +27,26 @@
"devDependencies": {
"@auth0/auth0-react": "^2.1.1",
"@types/jasmine": "^4.3.1",
"@types/jest": "^29.5.1",
"@types/node": "^18.13.0",
"dotenv": "^16.4.5",
"env-cmd": "^10.1.0",
"esbuild": "^0.17.17",
"esbuild-jest": "^0.4.0",
"esbuild-register": "^3.4.2",
"husky": "^8.0.3",
"jasmine": "^3.99.0",
"jasmine-ts": "^0.4.0",
"jest": "^29.5.0",
"openapi-typescript": "^6.7.6",
"prettier": "^2.8.8",
"pretty-quick": "^3.1.3",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"ts-node-dev": "^2.0.0",
"tsconfig-paths": "^4.2.0",
"typedoc": "^0.25.13",
"typescript": "^4.9.5",
"uvu": "^0.5.6"
"vitest": "^2.1.4"
},
"dependencies": {
"apache-arrow": "^12.0.1",
"dotenv": "^16.0.3",
"js-yaml": "^4.1.0"
}
}
1 change: 0 additions & 1 deletion tests/arrow.test.js → tests/arrow.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { test } from 'uvu';
import * as arrow from 'apache-arrow';

/**
Expand Down
21 changes: 11 additions & 10 deletions tests/embedding.test.js → tests/embedding.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { test } from 'uvu';
import { test } from 'vitest';
import { embed, Embedder } from '../dist/embedding.js';
import { AtlasUser } from '../dist/user.js';
import * as assert from 'uvu/assert';

test('Embed a point from an env token', async () => {
const strings = [
Expand All @@ -16,7 +15,7 @@ test('Embed a point from an env token', async () => {
// Pulling the API key from env variable.
const values = await embed(strings);

assert.is(values.length, 3);
expect(values.length).toBe(3);

// Taking the dot product and assert sentences 0 and 1 are closer than sentences 0 and 2

Expand All @@ -35,7 +34,7 @@ test('Embed a point from an env token', async () => {
}
similarityMatrix.push(ds);
}
assert.is(similarityMatrix[0][1] > similarityMatrix[0][2], true);
expect(similarityMatrix[0][1]).toBeGreaterThan(similarityMatrix[0][2]);

const olderVersion = new Embedder(process.env.ATLAS_API_KEY, {
model: 'nomic-embed-text-v1',
Expand All @@ -49,10 +48,12 @@ test('Embed a point from an env token', async () => {
const dogs1 = await olderVersion.embed(strings[0]);
const dogs2 = await differentTerms.embed(strings[0]);

assert.is(dogs1.length, 768);
assert.is(dogs2.length, 768);
assert.is(dot(dogs1, dogs2) < 0.9, true);
assert.is(dot(values[0], dogs1) < 0.9, true);
//assert.is(dogs1.length, 768);
// assert.is(dogs2.length, 768);
// assert.is(dot(dogs1, dogs2) < 0.9, true);
// assert.is(dot(values[0], dogs1) < 0.9, true);
expect(dogs1.length).toBe(768);
expect(dogs2.length).toBe(768);
expect(dot(dogs1, dogs2) < 0.9).toBe(true);
expect(dot(values[0], dogs1) < 0.9).toBe(true);
});

test.run();
5 changes: 2 additions & 3 deletions tests/neighbors.test.js → tests/neighbors.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { test } from 'uvu';
import { test, expect } from 'vitest';
import { AtlasProjection } from '../dist/projection.js';
import { AtlasUser } from '../dist/user.js';
import * as assert from 'uvu/assert';

test.skip('Neighbors', async () => {
// get user
Expand All @@ -19,5 +18,5 @@ test.skip('Neighbors', async () => {
queries: [vec],
k: 25,
});
assert.is(result[0].length, 25);
expect(result[0].length).toBe(25);
});
128 changes: 0 additions & 128 deletions tests/project.test.js

This file was deleted.

72 changes: 72 additions & 0 deletions tests/project.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { expect, test, describe } from 'vitest';

import { AtlasDataset } from '../src/project';
import { make_test_table } from './arrow';
import { AtlasProjection } from '../src/projection';
import { AtlasUser } from '../src/user';
import { AtlasViewer } from '../src/viewer';
import { AtlasOrganization } from '../src/organization';

describe('Project Flow Suite', () => {
let viewer: AtlasViewer;
let user: AtlasUser;
let organization: AtlasOrganization;
let project: AtlasDataset;
let index: any;
let projection: AtlasProjection;

beforeAll(async () => {
viewer = await new AtlasViewer({ useEnvToken: true });
user = await new AtlasUser(viewer).withLoadedAttributes();
const orgId = user.attr.organizations[0].organization_id;
organization = new AtlasOrganization(orgId, viewer);
});

afterAll(async () => {
if (project) await project.delete();
});

test('Verify organization has no attributes initially', async () => {
expect(organization.attr).toBe(undefined);
await organization.fetchAttributes();
expect(organization.attr).toBeInstanceOf(Object);
});

test('Create project in organization', async () => {
project = await organization.create_project({
project_name: 'test-a typescript test text project',
unique_id_field: 'id',
modality: 'text',
});

const fetchedProject = await new AtlasDataset(
project.id,
viewer
).withLoadedAttributes();
expect(fetchedProject.id).toBe(project.id);
});

test('Upload arrow table to project', async () => {
const table = make_test_table({ length: 50, modality: 'text' });
await project.uploadArrow(table).catch((err) => {
console.error(err);
throw err;
});
});

test('Create index on project and verify it', async () => {
const index = await project.createIndex({
index_name: 'test index',
indexed_field: 'text',
colorable_fields: [],
});
});
});

test('test_arrow_text', () => {
const tb = make_test_table({ length: 32, modality: 'text' });
});

test('test_arrow_embeddings', () => {
const tb = make_test_table({ length: 32, modality: 'embedding' });
});
14 changes: 6 additions & 8 deletions tests/user.test.js → tests/user.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from 'uvu';
import * as assert from 'uvu/assert';
import { expect, test } from 'vitest';

import { AtlasUser } from '../dist/user.js';
import { AtlasViewer } from '../dist/viewer.js';
import { AtlasOrganization } from '../dist/organization.js';
Expand All @@ -17,7 +17,7 @@ test('AtlasOrganization test', async () => {
info.organizations[0].organization_id,
user
);
assert.is(organization.id, info.organizations[0].organization_id);
expect(info.organizations[0].organization_id).toBe(organization.id);
});

test('AtlasUser from env variables', async () => {
Expand All @@ -26,7 +26,7 @@ test('AtlasUser from env variables', async () => {
const user = await new AtlasUser({
useEnvToken: true,
}).withLoadedAttributes();
assert.type(user.attr, 'object');
expect(user.attr).toBeInstanceOf(Object);
});

test('AtlasUser from api key', async () => {
Expand All @@ -37,7 +37,7 @@ test('AtlasUser from api key', async () => {
const user = await new AtlasUser({
useEnvToken: true,
}).withLoadedAttributes();
assert.type(user.attr, 'object');
expect(user.attr).toBeInstanceOf(Object);
});

test('AtlasUser from AtlasViewer', async () => {
Expand All @@ -49,10 +49,8 @@ test('AtlasUser from AtlasViewer', async () => {
useEnvToken: true,
});
const user = await new AtlasUser(viewer).withLoadedAttributes();
assert.type(user.attr, 'object');
expect(user.attr).toBeInstanceOf(Object);
});

// TODO - tests for bearer token login
// TODO - tests for anon account

test.run();
17 changes: 17 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { defineConfig } from 'vitest/config';
import { resolve } from 'path';

export default defineConfig({
root: '.',
esbuild: {
tsconfigRaw: '{}',
},
test: {
clearMocks: true,
globals: true,
setupFiles: ['dotenv/config'], //this line,
},
resolve: {
alias: [{ find: '~', replacement: resolve(__dirname, 'src') }],
},
});

0 comments on commit 528867c

Please sign in to comment.