vitest-dynoxide runs your integration tests against a local [dynoxide] instance
instead of real DynamoDB.
Each test file gets its own in-memory database on its own port,
so test files can't see each other's data.
No Docker, no JVM, no shared local DynamoDB to reset between runs.
pnpm add --save-dev vitest-dynoxide@aws-sdk/client-dynamodb and vitest are peer dependencies,
so you'll already have them in an integration test setup.
Make sure to install dynoxide as a dev dependency if the repo does not use it yet.
Create a vitest-dynoxide-config.ts in your project root:
import { defineConfig } from 'vitest-dynoxide';
export default defineConfig({
tables: ['TestTable'],
});Each entry is either a table name, a full table ARN, or a full definition.
A table name or ARN acts as the source table identifier:
DescribeTable is called against the real table
and its key schema and indexes are copied into the local instance.
This needs AWS credentials and a table that exists,
but keeps the config to one line.
A bare table name targets the account associated with your AWS credentials. To infer a table from another account, use its full ARN:
export default defineConfig({
tables: ['arn:aws:dynamodb:ap-southeast-2:123456789012:table/TestTable'],
});The source table identifier is passed unchanged to DescribeTable.
The caller's identity policy and the table's resource policy must both allow
that operation. The local table uses the plain name returned by AWS, so
application code continues to access TestTable.
You may need a resource policy on the table.
This example lets any principal in your AWS Organization describe production
TestTable, so schema inference works while you are authenticated to any of
your accounts:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowDescribeTable",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": ["dynamodb:DescribeTable"],
"Resource": "arn:aws:dynamodb:ap-southeast-2:123456789012:table/TestTable",
"Condition": {
"StringEquals": {
"aws:PrincipalOrgID": "o-xxxxxxxxxx"
}
}
}
]
}A full definition is used as-is and makes no AWS calls, so your tests run offline:
import { defineConfig } from 'vitest-dynoxide';
export default defineConfig({
tables: [
'TestTable',
{
TableName: 'TestTableCatalogue',
AttributeDefinitions: [
{ AttributeName: 'pk', AttributeType: 'S' },
{ AttributeName: 'sk', AttributeType: 'S' },
],
KeySchema: [
{ AttributeName: 'pk', KeyType: 'HASH' },
{ AttributeName: 'sk', KeyType: 'RANGE' },
],
},
],
});You can also supply part of a definition. Anything you leave out is filled in from the real table, and anything you supply is never overwritten:
{
TableName: 'TestTableCatalogue',
// Inferred: AttributeDefinitions, GlobalSecondaryIndexes, LocalSecondaryIndexes
KeySchema: [{ AttributeName: 'pk', KeyType: 'HASH' }],
}One rule to know: supplying both
AttributeDefinitionsandKeySchemamarks a table as complete, and noDescribeTablecall is made for it. OmittingGlobalSecondaryIndexeson such a table means "this table has no GSIs", not "go and infer them".
Keep the indexes if your code queries them.
A Query with an IndexName fails against a table scaffolded without that index,
even though it works fine against real DynamoDB.
Specify the follow entry points in vitest.config.ts:
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
fileParallelism: true,
globalSetup: ['vitest-dynoxide/globalSetup'],
setupFiles: ['vitest-dynoxide/setupFile', 'vitest-dynoxide/clearTables'],
},
});The clearTables entry point deletes and recreates every configured table in a
beforeEach hook.
Construct the client normally:
const client = new DynamoDBClient();The setup file configures the AWS SDK through
AWS_ENDPOINT_URL_DYNAMODB, AWS_REGION, and local credentials.
It also exposes DYNAMODB_ENDPOINT for code that needs the URL directly.
Do not pass endpoint to the client in tests.
An explicit endpoint overrides AWS_ENDPOINT_URL_DYNAMODB,
so vitest-dynoxide cannot redirect your requests to its dynoxide instance.
If your clients read host and port from environment variables
and build an endpoint URL at module load time,
drop that wiring and let the SDK read AWS_ENDPOINT_URL_DYNAMODB instead.
Before in framework/aws.ts:
import { Env } from 'skuba-dive';
import { config } from '#src/config.js';
const dbEndpoints = {
testTable: {
host: Env.string('TEST_TABLE_DYNAMODB_HOST', { default: 'localhost' }),
port: Env.nonNegativeInteger('TEST_TABLE_DYNAMODB_PORT', {
default: '8003',
}),
},
// ...
};
const testTableOptions =
config.dynamodbEnvironment === 'local'
? {
region: 'local',
endpoint: `http://${dbEndpoints.testTable.host}:${dbEndpoints.testTable.port}`,
}
: {};
const testTableClient = new DynamoDBClient(testTableOptions);After:
const testTableClient = new DynamoDBClient();The setup file also sets AWS_REGION and local credentials,
so you can omit localOptions entirely and use new DynamoDBClient().
Some test snapshots may need updating after switching.
Dynoxide returns validation errors that match live AWS more closely
than DynamoDB Local β for example,
The number of conditions on the keys is invalid may become
The provided key element does not match the schema.
That is expected: see the DynamoDB conformance suite
for how dynoxide compares to DynamoDB Local and other emulators.
Then write tests as normal β each file starts with empty tables:
it('round-trips a test table', async () => {
await client.send(
new PutItemCommand({
TableName: 'TestTable',
Item: { pk: { S: 'primary-key-1' } },
}),
);
const { Item } = await client.send(
new GetItemCommand({
TableName: 'TestTable',
Key: { pk: { S: 'primary-key-1' } },
}),
);
expect(Item).toEqual({ pk: { S: 'primary-key-1' } });
});- Decide whether to gitignore
/vitest-dynoxide.schemas.json
Global setup writes /vitest-dynoxide.schemas.json to the project root
and reuses it between test runs.
Delete the file whenever you need to refresh the schema from AWS.
You may or may not want to gitignore it:
- Ignore it if inferred tables should always match live AWS. Clean CI checkouts generate a fresh schema, so those jobs need credentials.
- Commit it if tests should run offline, including in CI. The committed file is reused as-is until you delete it and regenerate.
Global setup runs once per vitest invocation.
If vitest-dynoxide.schemas.json does not exist,
it loads your config,
fills in any missing table definitions via DescribeTable,
and writes the file to your project root.
If the file already exists, it is reused without making AWS calls.
The setup file then runs once per test file.
It picks a random port,
spawns dynoxide --schema vitest-dynoxide.schemas.json on it,
waits until the instance accepts connections,
and exposes its IPv4 endpoint through the AWS SDK environment variables,
and kills the process in afterAll.
Because the schema is scaffolded fresh into an in-memory database each time,
test files never share state.
Types a vitest-dynoxide-config.ts default export.
It returns the config unchanged β
the value is only for editor completion and type checking.
import { defineConfig } from 'vitest-dynoxide';Exported types: VitestDynoxideConfig, TableConfig, TableSchema.
could not find a config file in <dir> β
the config must sit in the directory vitest runs from,
which is your Vitest root rather than the location of your test files.
must default export a valid vitest-dynoxide config β
the message names the offending field.
Because an entry may be either a name or a definition,
both possibilities are reported;
read past the expected string half:
β Invalid input: expected string, received object; KeySchema.0.KeyType: Invalid option: expected one of "HASH"|"RANGE"
β at default.tables[0]
Credential or ResourceNotFoundException errors during setup β
a bare table name triggers a live DescribeTable.
Either authenticate against the account holding that table,
use a full table ARN with cross-account permissions,
or spell the definition out in full to run offline.
- Node.js 24.19+
- pnpm
pnpm installpnpm test# Fix issues
pnpm format
# Check for issues
pnpm lint# Compile source
pnpm build
# Review bundle
pnpm packThis package is published to the public npm registry with a GitHub Actions release workflow. It depends on this repo being hosted on seek-oss with appropriate access; follow the OSS npm package guidance to set up publishing.
Releases are managed with changesets.
Run pnpm changeset to create a changeset file describing your change and its semver impact.
When merged to main, the release workflow will open a version bump PR.
Merging that PR publishes the new version to npm.
Snapshot releases let you publish a pre-release version from any branch without going through the full release process. To publish a snapshot, manually trigger the release workflow on your branch via the GitHub Actions UI. The snapshot will be published to npm under a unique version derived from the branch name.