You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+86Lines changed: 86 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -97,6 +97,92 @@ test("foo bar", async (t) => {
97
97
98
98
## Advanced Usage
99
99
100
+
### Postgres container de-duping
101
+
102
+
In rare cases, you may want to spawn more than one Postgres container.
103
+
104
+
Internally, this library uses an AVA "shared worker". A shared worker is a singleton shared with the entire running test suite, and so one `ava-postgres` shared worker maps to exactly one Postgres container.
105
+
106
+
To spawn separate shared workers and thus additional Postgres containers, you have two options:
107
+
108
+
**Specify different version strings for the `postgresVersion` option in the factory function**:
Each unique key will map to a unique shared worker.
127
+
128
+
### Database de-duping
129
+
130
+
By default, `ava-postgres` will create a new database for each test. If you want to share a database between tests, you can use the `databaseDedupeKey` option:
Note that if unique parameters are passed to the `beforeTemplateIsBaked` (`null` in the above example), separate databases will still be created.
150
+
151
+
### "Nested" `beforeTemplateIsBaked` calls
152
+
153
+
In some cases, if you do extensive setup in your `beforeTemplateIsBaked` hook, you might want to obtain a separate, additional database within it if your application uses several databases for different purposes. This is possible by using the passed `beforeTemplateIsBaked` to your hook callback:
* Test workers will be de-duped by this key. You probably don't need to set this.
51
+
* In rare cases, you may want to spawn more than one Postgres container.
52
+
* Internally, this library uses an AVA "shared worker". A shared worker is a singleton shared with the entire running test suite, and so one `ava-postgres` shared worker maps to exactly one Postgres container.
53
+
* To spawn separate shared workers and thus additional Postgres containers, you can specify a custom key here.
54
+
* Each unique key will map to a unique shared worker/unique Postgres container.
* In some cases, if you do extensive setup in your `beforeTemplateIsBaked` hook, you might want to obtain a separate, additional database within it if your application uses several databases for different purposes. This is possible by using the passed `beforeTemplateIsBaked` to your hook callback.
64
+
* Be very careful when using this to avoid infinite loops.
* await fooDatabase.pool.query(`INSERT INTO "foo" DEFAULT VALUES`)
91
+
* },
92
+
* })
93
+
* ```
94
+
*/
58
95
beforeTemplateIsBaked: (
59
96
options: {
60
97
params: Params
@@ -71,6 +108,28 @@ export type GetTestPostgresDatabaseOptions = {
71
108
/**
72
109
* If `getTestPostgresDatabase()` is called multiple times with the same `key` and `params`, the same database is guaranteed to be returned.
73
110
*/
111
+
/**
112
+
* By default, `ava-postgres` will create a new database for each test. If you want to share a database between tests, you can use the `databaseDedupeKey` option.
113
+
* This works across the entire test suite.
114
+
*
115
+
* Note that if unique parameters are passed to the `beforeTemplateIsBaked` (`null` in the above example), separate databases will still be created.
0 commit comments