Home / Function/ tests() — drizzle-orm Function Reference

tests() — drizzle-orm Function Reference

Architecture documentation for the tests() function in mysql-common-cache.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  86aa434f_528e_fe0f_107e_2f26b378d3d2["tests()"]
  cccbc47d_c2bb_d1ee_3a7e_546f7279bf7e["mysql-common-cache.ts"]
  86aa434f_528e_fe0f_107e_2f26b378d3d2 -->|defined in| cccbc47d_c2bb_d1ee_3a7e_546f7279bf7e
  style 86aa434f_528e_fe0f_107e_2f26b378d3d2 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

integration-tests/tests/mysql/mysql-common-cache.ts lines 101–379

export function tests() {
	describe('common_cache', () => {
		beforeEach(async (ctx) => {
			const { db, dbGlobalCached } = ctx.cachedMySQL;
			await db.execute(sql`drop table if exists users`);
			await db.execute(sql`drop table if exists posts`);
			await db.$cache?.invalidate({ tables: 'users' });
			await dbGlobalCached.$cache?.invalidate({ tables: 'users' });
			// public users
			await db.execute(
				sql`
					create table users (
						id serial primary key,
						name text not null,
						verified boolean not null default false,
						jsonb json,
						created_at timestamp not null default now()
					)
				`,
			);
			await db.execute(
				sql`
					create table posts (
						id serial primary key,
						description text not null,
						user_id int
					)
				`,
			);
		});

		test('test force invalidate', async (ctx) => {
			const { db } = ctx.cachedMySQL;

			const spyInvalidate = vi.spyOn(db.$cache, 'invalidate');
			await db.$cache?.invalidate({ tables: 'users' });
			expect(spyInvalidate).toHaveBeenCalledTimes(1);
		});

		test('default global config - no cache should be hit', async (ctx) => {
			const { db } = ctx.cachedMySQL;

			// @ts-expect-error
			const spyPut = vi.spyOn(db.$cache, 'put');
			// @ts-expect-error
			const spyGet = vi.spyOn(db.$cache, 'get');
			// @ts-expect-error
			const spyInvalidate = vi.spyOn(db.$cache, 'onMutate');

			await db.select().from(usersTable);

			expect(spyPut).toHaveBeenCalledTimes(0);
			expect(spyGet).toHaveBeenCalledTimes(0);
			expect(spyInvalidate).toHaveBeenCalledTimes(0);
		});

		test('default global config + enable cache on select: get, put', async (ctx) => {
			const { db } = ctx.cachedMySQL;

			// @ts-expect-error
			const spyPut = vi.spyOn(db.$cache, 'put');
			// @ts-expect-error
			const spyGet = vi.spyOn(db.$cache, 'get');
			// @ts-expect-error
			const spyInvalidate = vi.spyOn(db.$cache, 'onMutate');

			await db.select().from(usersTable).$withCache();

			expect(spyPut).toHaveBeenCalledTimes(1);
			expect(spyGet).toHaveBeenCalledTimes(1);
			expect(spyInvalidate).toHaveBeenCalledTimes(0);
		});

		test('default global config + enable cache on select + write: get, put, onMutate', async (ctx) => {
			const { db } = ctx.cachedMySQL;

			// @ts-expect-error
			const spyPut = vi.spyOn(db.$cache, 'put');
			// @ts-expect-error
			const spyGet = vi.spyOn(db.$cache, 'get');
			// @ts-expect-error

Domain

Subdomains

Frequently Asked Questions

What does tests() do?
tests() is a function in the drizzle-orm codebase, defined in integration-tests/tests/mysql/mysql-common-cache.ts.
Where is tests() defined?
tests() is defined in integration-tests/tests/mysql/mysql-common-cache.ts at line 101.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free