Files
turso/packages/turso-serverless/integration-tests/compat.test.mjs
Pekka Enberg 7765bafb13 Add @tursodatabase/serverless package
This package is for serverless access to the Turso Cloud using SQL over
HTTP protocol. The purpose of this package is to provide the same
interface as `@tursodatabase/turso`, but for serverless environments
that cannot host the database engine.

The package also provides a `@libsql/client` compatibility layer in the
`@tursodatabase/serverless/compat` module for drop-in replacement for
existing clients.
2025-07-21 22:03:43 +03:00

54 lines
1.6 KiB
JavaScript

import test from 'ava';
import { createClient, LibsqlError } from '../dist/compat/index.js';
test.serial('createClient validates supported config options', async t => {
// Valid config should work
t.notThrows(() => {
const client = createClient({
url: process.env.TURSO_DATABASE_URL,
authToken: process.env.TURSO_AUTH_TOKEN,
});
client.close();
});
});
test.serial('createClient rejects unsupported config options', async t => {
const error = t.throws(() => {
createClient({
url: process.env.TURSO_DATABASE_URL,
authToken: process.env.TURSO_AUTH_TOKEN,
encryptionKey: 'some-key',
syncUrl: 'https://sync.example.com',
});
}, { instanceOf: LibsqlError });
t.is(error.code, 'UNSUPPORTED_CONFIG');
t.regex(error.message, /encryptionKey.*syncUrl/);
t.regex(error.message, /Only 'url' and 'authToken' are supported/);
});
test.serial('createClient requires url config option', async t => {
const error = t.throws(() => {
createClient({
authToken: process.env.TURSO_AUTH_TOKEN,
});
}, { instanceOf: LibsqlError });
t.is(error.code, 'MISSING_URL');
t.regex(error.message, /Missing required 'url'/);
});
test.serial('createClient works with basic libSQL API', async t => {
const client = createClient({
url: process.env.TURSO_DATABASE_URL,
authToken: process.env.TURSO_AUTH_TOKEN,
});
// Test basic functionality
const result = await client.execute('SELECT 42 as answer');
t.is(result.rows[0][0], 42);
t.is(result.columns[0], 'answer');
client.close();
t.true(client.closed);
});