**test(tests): enhance test clarity, isolation, and robustness**
- **Test Improvements**: - Introduced data-clearing steps (`.clear()`) across critical test cases for ensuring better test isolation and preventing state leakage. - Extended support for overriding global utilities (`testUtils`) and added fallback behaviors for test vector creation. - **Configuration Updates**: - Added support for `distanceFunction` as an alternative to `metric` in vector operations for consistency. - Adjusted and unified asynchronous `timeout` handling across test suites for predictability. - **Purpose**: - These updates improve reliability, maintainability, and clarity in test cases while ensuring compatibility across diverse test environments.
This commit is contained in:
parent
8ffc7115a5
commit
5958502cf3
5 changed files with 170 additions and 126 deletions
|
|
@ -53,7 +53,10 @@ describe('Brainy in Browser Environment', () => {
|
|||
it('should create database and add vector data', async () => {
|
||||
const db = new brainy.BrainyData({
|
||||
dimensions: 3,
|
||||
metric: 'euclidean'
|
||||
metric: 'euclidean',
|
||||
storage: {
|
||||
forceMemoryStorage: true
|
||||
}
|
||||
})
|
||||
|
||||
await db.init()
|
||||
|
|
@ -70,29 +73,39 @@ describe('Brainy in Browser Environment', () => {
|
|||
expect(results[0].metadata.id).toBe('item1')
|
||||
})
|
||||
|
||||
it('should handle text data with embeddings', async () => {
|
||||
const db = new brainy.BrainyData({
|
||||
embeddingFunction: brainy.createEmbeddingFunction(),
|
||||
metric: 'cosine'
|
||||
})
|
||||
it(
|
||||
'should handle text data with embeddings',
|
||||
async () => {
|
||||
const db = new brainy.BrainyData({
|
||||
embeddingFunction: brainy.createEmbeddingFunction(),
|
||||
metric: 'cosine',
|
||||
storage: {
|
||||
forceMemoryStorage: true
|
||||
}
|
||||
})
|
||||
|
||||
await db.init()
|
||||
await db.init()
|
||||
|
||||
// Add text items as a consumer would
|
||||
await db.addItem('Hello browser world', { id: 'greeting' })
|
||||
await db.addItem('Goodbye browser world', { id: 'farewell' })
|
||||
// Add text items as a consumer would
|
||||
await db.addItem('Hello browser world', { id: 'greeting' })
|
||||
await db.addItem('Goodbye browser world', { id: 'farewell' })
|
||||
|
||||
// Search with text
|
||||
const results = await db.search('Hi there', 1)
|
||||
expect(results).toBeDefined()
|
||||
expect(results.length).toBeGreaterThan(0)
|
||||
expect(results[0].metadata).toHaveProperty('id')
|
||||
}, testUtils.timeout)
|
||||
// Search with text
|
||||
const results = await db.search('Hi there', 1)
|
||||
expect(results).toBeDefined()
|
||||
expect(results.length).toBeGreaterThan(0)
|
||||
expect(results[0].metadata).toHaveProperty('id')
|
||||
},
|
||||
globalThis.testUtils?.timeout || 30000
|
||||
)
|
||||
|
||||
it('should handle multiple data types', async () => {
|
||||
const db = new brainy.BrainyData({
|
||||
dimensions: 2,
|
||||
metric: 'euclidean'
|
||||
metric: 'euclidean',
|
||||
storage: {
|
||||
forceMemoryStorage: true
|
||||
}
|
||||
})
|
||||
|
||||
await db.init()
|
||||
|
|
@ -111,7 +124,11 @@ describe('Brainy in Browser Environment', () => {
|
|||
// Search should return relevant results
|
||||
const results = await db.search([1.5, 1.5], 2)
|
||||
expect(results.length).toBe(2)
|
||||
expect(results.every(r => r.metadata.type === 'point')).toBe(true)
|
||||
expect(
|
||||
results.every(
|
||||
(r: { metadata: { type: string } }) => r.metadata.type === 'point'
|
||||
)
|
||||
).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
@ -125,7 +142,10 @@ describe('Brainy in Browser Environment', () => {
|
|||
it('should handle search on empty database', async () => {
|
||||
const db = new brainy.BrainyData({
|
||||
dimensions: 2,
|
||||
metric: 'euclidean'
|
||||
metric: 'euclidean',
|
||||
storage: {
|
||||
forceMemoryStorage: true
|
||||
}
|
||||
})
|
||||
|
||||
await db.init()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue