joist-test-utils 2.0.3-next.9 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/seed.d.ts +4 -5
- package/build/seed.d.ts.map +1 -1
- package/build/seed.js +10 -11
- package/build/seed.js.map +1 -1
- package/package.json +4 -4
package/build/seed.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import "dotenv/config";
|
|
2
2
|
import { Driver, EntityManager } from "joist-core";
|
|
3
|
-
import
|
|
3
|
+
import pg from "pg";
|
|
4
4
|
export interface SeedConfig {
|
|
5
|
-
/** A factory function to create a Driver from a
|
|
6
|
-
createDriver: (
|
|
5
|
+
/** A factory function to create a Driver from a pg Pool. */
|
|
6
|
+
createDriver: (pool: pg.Pool) => Driver;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* Allows easily seeding your local database with test data from the factories.
|
|
@@ -13,7 +13,6 @@ export interface SeedConfig {
|
|
|
13
13
|
*
|
|
14
14
|
* We currently make a lot of assumptions:
|
|
15
15
|
*
|
|
16
|
-
* - That the project is using knex (all Joist projects do atm)
|
|
17
16
|
* - That the project is using postgres (all Joist projects do atm)
|
|
18
17
|
* - That the project does not have a context, or at least does not require a context to seed
|
|
19
18
|
*
|
|
@@ -24,7 +23,7 @@ export interface SeedConfig {
|
|
|
24
23
|
* import { seed } from "joist-test-utils";
|
|
25
24
|
* import { PostgresDriver } from "joist-orm";
|
|
26
25
|
*
|
|
27
|
-
* seed({ createDriver: (
|
|
26
|
+
* seed({ createDriver: (pool) => new PostgresDriver(pool) }, async (em) => {
|
|
28
27
|
* // seed your data here
|
|
29
28
|
* });
|
|
30
29
|
* ```
|
package/build/seed.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../src/seed.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AACvB,OAAO,EAAE,MAAM,EAAE,aAAa,EAAyB,MAAM,YAAY,CAAC;AAC1E,OAAO,
|
|
1
|
+
{"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../src/seed.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AACvB,OAAO,EAAE,MAAM,EAAE,aAAa,EAAyB,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,MAAM,WAAW,UAAU;IACzB,4DAA4D;IAC5D,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,MAAM,CAAC;CACzC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CA0BpH"}
|
package/build/seed.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.seed = seed;
|
|
4
7
|
require("dotenv/config");
|
|
5
8
|
const joist_core_1 = require("joist-core");
|
|
6
|
-
const
|
|
9
|
+
const pg_1 = __importDefault(require("pg"));
|
|
7
10
|
/**
|
|
8
11
|
* Allows easily seeding your local database with test data from the factories.
|
|
9
12
|
*
|
|
@@ -12,7 +15,6 @@ const knex_1 = require("knex");
|
|
|
12
15
|
*
|
|
13
16
|
* We currently make a lot of assumptions:
|
|
14
17
|
*
|
|
15
|
-
* - That the project is using knex (all Joist projects do atm)
|
|
16
18
|
* - That the project is using postgres (all Joist projects do atm)
|
|
17
19
|
* - That the project does not have a context, or at least does not require a context to seed
|
|
18
20
|
*
|
|
@@ -23,7 +25,7 @@ const knex_1 = require("knex");
|
|
|
23
25
|
* import { seed } from "joist-test-utils";
|
|
24
26
|
* import { PostgresDriver } from "joist-orm";
|
|
25
27
|
*
|
|
26
|
-
* seed({ createDriver: (
|
|
28
|
+
* seed({ createDriver: (pool) => new PostgresDriver(pool) }, async (em) => {
|
|
27
29
|
* // seed your data here
|
|
28
30
|
* });
|
|
29
31
|
* ```
|
|
@@ -33,13 +35,10 @@ function seed(config, fn) {
|
|
|
33
35
|
if (env !== "local" && env !== "test") {
|
|
34
36
|
throw new Error("seed will only run with NODE_ENV=local or NODE_ENV=test because it resets the database");
|
|
35
37
|
}
|
|
36
|
-
|
|
37
|
-
// knex & postgres, but at some point these will be configurable...
|
|
38
|
-
// Maybe we can detect it in the `DATABASE_URL` or what not.
|
|
39
|
-
const knex = (0, knex_1.knex)({ client: "pg", connection: (0, joist_core_1.newPgConnectionConfig)() });
|
|
38
|
+
const pool = new pg_1.default.Pool((0, joist_core_1.newPgConnectionConfig)());
|
|
40
39
|
async function seed() {
|
|
41
|
-
await
|
|
42
|
-
const driver = config.createDriver(
|
|
40
|
+
await pool.query("SELECT flush_database()");
|
|
41
|
+
const driver = config.createDriver(pool);
|
|
43
42
|
const em = new joist_core_1.EntityManager({}, { driver });
|
|
44
43
|
await fn(em);
|
|
45
44
|
await em.flush();
|
|
@@ -47,11 +46,11 @@ function seed(config, fn) {
|
|
|
47
46
|
seed()
|
|
48
47
|
.then(async () => {
|
|
49
48
|
console.log("Seeded!");
|
|
50
|
-
await
|
|
49
|
+
await pool.end();
|
|
51
50
|
})
|
|
52
51
|
.catch(async (err) => {
|
|
53
52
|
console.error(err);
|
|
54
|
-
await
|
|
53
|
+
await pool.end();
|
|
55
54
|
process.exit(1);
|
|
56
55
|
});
|
|
57
56
|
}
|
package/build/seed.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seed.js","sourceRoot":"","sources":["../src/seed.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version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
|
|
|
1
1
|
{
|
|
2
2
|
"name": "joist-test-utils",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
"build"
|
|
12
12
|
],
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"joist-core": "2.0
|
|
15
|
-
"joist-utils": "2.0
|
|
16
|
-
"
|
|
14
|
+
"joist-core": "2.1.0",
|
|
15
|
+
"joist-utils": "2.1.0",
|
|
16
|
+
"pg": "^8.16.3"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@swc/core": "^1.13.20",
|