Skip to content

Commit

Permalink
Rename parameters to make difference in functionality more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
itelo committed May 8, 2023
1 parent 805474d commit 32dd0de
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const getWorker = async (
) => {
const key = hash({
initialData,
key: options?.key,
key: options?.shared_database_dedupe_key,
})

if (process.env.IS_TESTING_AVA_POSTGRES) {
Expand Down Expand Up @@ -188,7 +188,7 @@ export const getTestPostgresDatabaseFactory = <
worker.publish({
type: "GET_TEST_DATABASE",
params,
key: getTestDatabaseOptions?.key,
key: getTestDatabaseOptions?.shared_worker_name,
} as MessageToWorker)
)
}
Expand Down
4 changes: 2 additions & 2 deletions src/public-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface GetTestPostgresDatabaseFactoryOptions<
/**
* Test workers will be de-duped by this key. You probably don't need to set this.
*/
key?: string
shared_database_dedupe_key?: string
beforeTemplateIsBaked?: (options: {
connection: ConnectionDetails
params: Params
Expand All @@ -50,7 +50,7 @@ export type GetTestPostgresDatabaseOptions = {
/**
* If `getTestPostgresDatabase()` is called multiple times with the same `key` and `params`, the same database is guaranteed to be returned.
*/
key?: string
shared_worker_name?: string
}

// https://github.com/microsoft/TypeScript/issues/23182#issuecomment-379091887
Expand Down
2 changes: 1 addition & 1 deletion src/tests/container-options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test("bind mounts", async (t) => {

const getTestPostgresDatabase = getTestPostgresDatabaseFactory({
postgresVersion: process.env.POSTGRES_VERSION,
key: "bindMounts",
shared_database_dedupe_key: "bindMounts",
container: {
bindMounts: [
{
Expand Down
10 changes: 5 additions & 5 deletions src/tests/hooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test("beforeTemplateIsBaked", async (t) => {

const getTestServer = getTestPostgresDatabaseFactory<TestFactoryParams>({
postgresVersion: process.env.POSTGRES_VERSION,
key: "beforeTemplateIsBaked",
shared_database_dedupe_key: "beforeTemplateIsBaked",
beforeTemplateIsBaked: async ({
connection: { pool },
params: { tableName },
Expand All @@ -34,7 +34,7 @@ test("beforeTemplateIsBaked (params are de-duped)", async (t) => {

const getTestServer = getTestPostgresDatabaseFactory<TestFactoryParams>({
postgresVersion: process.env.POSTGRES_VERSION,
key: "beforeTemplateIsBakedDedupeParams",
shared_database_dedupe_key: "beforeTemplateIsBakedDedupeParams",
beforeTemplateIsBaked: async ({
connection: { pool },
params: { tableName },
Expand Down Expand Up @@ -64,7 +64,7 @@ test("beforeTemplateIsBaked (get result of hook)", async (t) => {

const getTestServer = getTestPostgresDatabaseFactory<TestFactoryParams>({
postgresVersion: process.env.POSTGRES_VERSION,
key: "beforeTemplateIsBakedHookResult",
shared_database_dedupe_key: "beforeTemplateIsBakedHookResult",
beforeTemplateIsBaked: async ({ params: { tableName } }) => {
return { tableName }
},
Expand All @@ -86,7 +86,7 @@ test("beforeTemplateIsBaked (get result of hook)", async (t) => {
test("beforeTemplateIsBaked (if hook throws, worker doesn't crash)", async (t) => {
const getTestServer = getTestPostgresDatabaseFactory({
postgresVersion: process.env.POSTGRES_VERSION,
key: "beforeTemplateIsBakedHookThrows",
shared_database_dedupe_key: "beforeTemplateIsBakedHookThrows",
beforeTemplateIsBaked: async () => {
throw new Error("foo")
},
Expand All @@ -105,7 +105,7 @@ test("beforeTemplateIsBaked (if hook throws, worker doesn't crash)", async (t) =
test("beforeTemplateIsBaked (propagates error that isn't serializable)", async (t) => {
const getTestServer = getTestPostgresDatabaseFactory({
postgresVersion: process.env.POSTGRES_VERSION,
key: "beforeTemplateIsBakedHookThrowsNonSerializable",
shared_database_dedupe_key: "beforeTemplateIsBakedHookThrowsNonSerializable",
beforeTemplateIsBaked: async () => {
const error = new Error("foo")
// Typed arrays aren't serializable
Expand Down
22 changes: 11 additions & 11 deletions src/tests/keyed-database.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { getTestPostgresDatabaseFactory } from "~/index"
test("keyed", async (t) => {
const getTestDatabase = getTestPostgresDatabaseFactory({
postgresVersion: process.env.POSTGRES_VERSION,
key: "keyed",
shared_database_dedupe_key: "keyed",
})

const [database1, database2] = await Promise.all([
getTestDatabase(null, {
key: "foo",
shared_worker_name: "foo",
}),
getTestDatabase(null, {
key: "foo",
shared_worker_name: "foo",
}),
])

Expand All @@ -22,15 +22,15 @@ test("keyed", async (t) => {
test("defaults to different databases", async (t) => {
const getTestDatabase = getTestPostgresDatabaseFactory({
postgresVersion: process.env.POSTGRES_VERSION,
key: "notKeyedByDefault",
shared_database_dedupe_key: "notKeyedByDefault",
})

const [database1, database2, database3] = await Promise.all([
getTestDatabase(null, {
key: "foo",
shared_worker_name: "foo",
}),
getTestDatabase(null, {
key: "foo",
shared_worker_name: "foo",
}),
getTestDatabase(),
])
Expand All @@ -48,7 +48,7 @@ test("works with hooks", async (t) => {

const getTestDatabase = getTestPostgresDatabaseFactory<TestFactoryParams>({
postgresVersion: process.env.POSTGRES_VERSION,
key: "keyedWithHook",
shared_database_dedupe_key: "keyedWithHook",
beforeTemplateIsBaked: async ({
connection: { pool },
params: { tableName },
Expand All @@ -61,7 +61,7 @@ test("works with hooks", async (t) => {
const { pool } = await getTestDatabase(
{ tableName: "foo" },
{
key: "foo",
shared_worker_name: "foo",
}
)

Expand All @@ -72,19 +72,19 @@ test("works with hooks", async (t) => {
getTestDatabase(
{ tableName: "foo" },
{
key: "foo",
shared_worker_name: "foo",
}
),
getTestDatabase(
{ tableName: "foo" },
{
key: "foo",
shared_worker_name: "foo",
}
),
getTestDatabase(
{ tableName: "bar" },
{
key: "foo",
shared_worker_name: "foo",
}
),
])
Expand Down
4 changes: 2 additions & 2 deletions src/tests/keyed/1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import test from "ava"
import { getTestPostgresDatabaseFactory } from "~/index"

const getTestDatabase = getTestPostgresDatabaseFactory({
key: "keyed-across-workers",
shared_database_dedupe_key: "keyed-across-workers",
})

test("keyed returns same database across workers (1/2)", async (t) => {
const database = await getTestDatabase(null, {
key: "foo",
shared_worker_name: "foo",
})

console.log("connectionString:", database.connectionString)
Expand Down
4 changes: 2 additions & 2 deletions src/tests/keyed/2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import test from "ava"
import { getTestPostgresDatabaseFactory } from "~/index"

const getTestDatabase = getTestPostgresDatabaseFactory({
key: "keyed-across-workers",
shared_database_dedupe_key: "keyed-across-workers",
})

test("keyed returns same database across workers (2/2)", async (t) => {
const database = await getTestDatabase(null, {
key: "foo",
shared_worker_name: "foo",
})

console.log("connectionString:", database.connectionString)
Expand Down

0 comments on commit 32dd0de

Please sign in to comment.