@fabrika/cli 0.9.0-dev.18 → 0.9.0-dev.19
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/package.json +13 -13
- package/src/db.ts +9 -201
- package/src/index.ts +1 -1
- package/types/src/db.d.ts +1 -3
- package/src/junit.ts +0 -37
- package/types/src/junit.d.ts +0 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabrika/cli",
|
|
3
|
-
"version": "0.9.0-dev.
|
|
3
|
+
"version": "0.9.0-dev.19",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -31,20 +31,20 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"zod": "^3.25.76",
|
|
34
|
-
"@fabrika/app": "0.9.0-dev.
|
|
35
|
-
"@fabrika/auth-core": "0.9.0-dev.
|
|
36
|
-
"@fabrika/control-contract": "0.9.0-dev.
|
|
37
|
-
"@fabrika/operations-contract": "0.9.0-dev.
|
|
38
|
-
"@fabrika/provider-contract": "0.9.0-dev.
|
|
39
|
-
"@fabrika/db": "0.9.0-dev.
|
|
40
|
-
"@fabrika/platform": "0.9.0-dev.
|
|
41
|
-
"@fabrika/platform-node": "0.9.0-dev.
|
|
42
|
-
"@fabrika/check": "0.9.0-dev.
|
|
34
|
+
"@fabrika/app": "0.9.0-dev.19",
|
|
35
|
+
"@fabrika/auth-core": "0.9.0-dev.19",
|
|
36
|
+
"@fabrika/control-contract": "0.9.0-dev.19",
|
|
37
|
+
"@fabrika/operations-contract": "0.9.0-dev.19",
|
|
38
|
+
"@fabrika/provider-contract": "0.9.0-dev.19",
|
|
39
|
+
"@fabrika/db": "0.9.0-dev.19",
|
|
40
|
+
"@fabrika/platform": "0.9.0-dev.19",
|
|
41
|
+
"@fabrika/platform-node": "0.9.0-dev.19",
|
|
42
|
+
"@fabrika/check": "0.9.0-dev.19"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@fabrika/builder": "0.9.0-dev.
|
|
46
|
-
"@fabrika/provider-cloudflare": "0.9.0-dev.
|
|
47
|
-
"@fabrika/provider-zerops": "0.9.0-dev.
|
|
45
|
+
"@fabrika/builder": "0.9.0-dev.19",
|
|
46
|
+
"@fabrika/provider-cloudflare": "0.9.0-dev.19",
|
|
47
|
+
"@fabrika/provider-zerops": "0.9.0-dev.19"
|
|
48
48
|
},
|
|
49
49
|
"peerDependenciesMeta": {
|
|
50
50
|
"@fabrika/builder": {
|
package/src/db.ts
CHANGED
|
@@ -1,42 +1,22 @@
|
|
|
1
1
|
import { applicationMigrations as sqliteApplicationMigrations } from '@fabrika/app/build'
|
|
2
|
-
import {
|
|
3
|
-
type ApplicationDialect,
|
|
4
|
-
applicationDialect,
|
|
5
|
-
CONFIG_FILE,
|
|
6
|
-
type Finding,
|
|
7
|
-
formatFinding,
|
|
8
|
-
GENERATED_TEST_HEADER,
|
|
9
|
-
type GeneratedTest,
|
|
10
|
-
generatedTests,
|
|
11
|
-
missingEndpointFixtures,
|
|
12
|
-
readApplicationTree,
|
|
13
|
-
scaffoldInputs,
|
|
14
|
-
} from '@fabrika/check'
|
|
2
|
+
import { type ApplicationDialect, applicationDialect, CONFIG_FILE } from '@fabrika/check'
|
|
15
3
|
import { CodegenError, type GeneratedModule, generateSchema, leftOutText, SCHEMA_FILE } from '@fabrika/db/codegen'
|
|
16
4
|
import { generateSqliteSchema } from '@fabrika/db/codegen-sqlite'
|
|
17
5
|
import { FRAMEWORK_MIGRATION_BUNDLE, FRAMEWORK_MIGRATIONS } from '@fabrika/db/migrations'
|
|
18
6
|
import { SQLITE_FRAMEWORK_MIGRATIONS } from '@fabrika/db/migrations-sqlite'
|
|
19
7
|
import {
|
|
20
8
|
APPLICATION_MIGRATION_BUNDLE,
|
|
21
|
-
CONNECTION_CAPACITY_MESSAGE,
|
|
22
9
|
ConnectionCapacityError,
|
|
23
|
-
createTestProvisioner,
|
|
24
10
|
DEFAULT_MIGRATION_LOCK_TIMEOUT_MS,
|
|
25
11
|
DEFAULT_MIGRATION_STATEMENT_TIMEOUT_MS,
|
|
26
12
|
definePostgresApplicationMigrations,
|
|
27
13
|
type PostgresApplicationMigrations,
|
|
28
14
|
PostgresMigrationError,
|
|
29
15
|
postgresMigrationResultMessage,
|
|
30
|
-
type TestProvisioner,
|
|
31
|
-
TOO_MANY_CONNECTIONS,
|
|
32
|
-
withConnectionCapacity,
|
|
33
16
|
} from '@fabrika/platform-node'
|
|
34
17
|
import { SQL } from 'bun'
|
|
35
|
-
import { mkdir,
|
|
36
|
-
import { tmpdir } from 'node:os'
|
|
18
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises'
|
|
37
19
|
import { dirname, join } from 'node:path'
|
|
38
|
-
import { fileURLToPath } from 'node:url'
|
|
39
|
-
import { readJunitCases } from './junit'
|
|
40
20
|
|
|
41
21
|
/** The checker's `migration-name` contract (`@fabrika/check`, `db/migrations/`). */
|
|
42
22
|
const MIGRATIONS_DIR = 'db/migrations'
|
|
@@ -48,8 +28,6 @@ Usage:
|
|
|
48
28
|
fabrika db new <slug> Write ${MIGRATIONS_DIR}/<UTC YYYYMMDDHHMMSS>_<slug>.sql; the slug is lowercase snake_case.
|
|
49
29
|
fabrika db migrate Apply the framework's tables, then ${MIGRATIONS_DIR}, to the application's schema app_<id>.
|
|
50
30
|
fabrika db codegen [--verify] Write ${SCHEMA_FILE} from the migrated schema; --verify only fails when it is stale.
|
|
51
|
-
fabrika db test-scaffold Write the generated tests: a policy isolation test per table a store reaches, the endpoint access test.
|
|
52
|
-
fabrika db test-isolation [--verbose] Run the generated tests on a throwaway schema; fail unless every case the scaffold wrote passed.
|
|
53
31
|
|
|
54
32
|
Run from the application root. \`migrate\` and \`codegen\` read FABRIKA_APP_ID and FABRIKA_APP_DATABASE_URL from
|
|
55
33
|
the environment only. FABRIKA_APP_DATABASE_URL is the provisioning credential: \`migrate\` uses it only to create
|
|
@@ -57,19 +35,10 @@ the application's roles (app_<id> owns the schema, run_<id> gets DML on its tabl
|
|
|
57
35
|
roles. It applies the files as app_<id>, holds a lock derived from the application id, runs each file in one
|
|
58
36
|
transaction with lock_timeout ${DEFAULT_MIGRATION_LOCK_TIMEOUT_MS} ms and statement_timeout ${DEFAULT_MIGRATION_STATEMENT_TIMEOUT_MS} ms, and fails when a
|
|
59
37
|
file that already ran has changed: an applied migration is immutable, so a change is a new file.
|
|
60
|
-
\`test-scaffold\` reads fabrika.contract.ts and src/db/tables.ts as the checker does, rewrites every generated test and
|
|
61
|
-
deletes a generated one the scaffold no longer writes, printing each path, or that it wrote none; @fabrika/check refuses
|
|
62
|
-
one that is missing, edited or stale.
|
|
63
|
-
\`test-isolation\` is the platform's run of them: with FABRIKA_APP_DATABASE_URL it creates a throwaway provisioner
|
|
64
|
-
(CREATEROLE, CREATE on the database, nothing of any application) that the tests get instead, ignores the application's
|
|
65
|
-
bunfig.toml, and checks the JUnit report against the case names the scaffold wrote. It first drops the provisioners
|
|
66
|
-
that killed runs left behind: expired, and without a session of their own or of a role they created. A database at its
|
|
67
|
-
connection limit (SQLSTATE ${TOO_MANY_CONNECTIONS}) is waited for; one that never frees a slot fails the run saying so,
|
|
68
|
-
never as failed cases.
|
|
69
38
|
|
|
70
39
|
An application whose ${CONFIG_FILE} default-exports @fabrika/provider-cloudflare's defineApp runs on SQLite in its
|
|
71
40
|
Durable Object, which applies the migrations itself when it boots: \`migrate\` refuses, \`codegen\` applies them to an
|
|
72
|
-
in-memory database
|
|
41
|
+
in-memory database; neither needs a database URL.
|
|
73
42
|
`
|
|
74
43
|
|
|
75
44
|
export interface DbCommandDependencies {
|
|
@@ -196,177 +165,16 @@ const codegen = async (argv: readonly string[], deps: DbCommandDependencies): Pr
|
|
|
196
165
|
deps.write(`${SCHEMA_FILE}\n`)
|
|
197
166
|
}
|
|
198
167
|
|
|
199
|
-
const expectedTests = async (
|
|
200
|
-
cwd: string,
|
|
201
|
-
): Promise<
|
|
202
|
-
{ readonly files: ReadonlyMap<string, string>; readonly tests: ReadonlyMap<string, GeneratedTest>; readonly missing: readonly Finding[] }
|
|
203
|
-
> => {
|
|
204
|
-
const { files } = await readApplicationTree(cwd)
|
|
205
|
-
const inputs = scaffoldInputs(files)
|
|
206
|
-
return {
|
|
207
|
-
files,
|
|
208
|
-
tests: await generatedTests(inputs.policies, inputs.artifact, inputs.fixtures, inputs.dialect),
|
|
209
|
-
missing: missingEndpointFixtures(inputs),
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
const testScaffold = async (argv: readonly string[], deps: DbCommandDependencies): Promise<void> => {
|
|
214
|
-
refuseArguments('test-scaffold', argv)
|
|
215
|
-
const { files, tests, missing } = await expectedTests(deps.cwd)
|
|
216
|
-
for (const [path, text] of files) {
|
|
217
|
-
if (text.startsWith(GENERATED_TEST_HEADER) && !tests.has(path)) {
|
|
218
|
-
await rm(join(deps.cwd, path))
|
|
219
|
-
deps.write(`removed ${path}\n`)
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
for (const [path, { text, notes }] of tests) {
|
|
223
|
-
await mkdir(dirname(join(deps.cwd, path)), { recursive: true })
|
|
224
|
-
await writeFile(join(deps.cwd, path), text)
|
|
225
|
-
deps.write(`${path}\n`)
|
|
226
|
-
for (const note of notes) deps.write(`not checked: ${note}\n`)
|
|
227
|
-
}
|
|
228
|
-
if (missing.length > 0) {
|
|
229
|
-
throw new Error(`db test-scaffold: the endpoint access tests are incomplete\n${missing.map(formatFinding).join('\n')}`)
|
|
230
|
-
}
|
|
231
|
-
if (tests.size === 0) {
|
|
232
|
-
deps.write('no generated tests: they start with the first table a store reaches, and the application has none; write the first test yourself\n')
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Only what Bun needs to run; on Postgres the URL arrives as the kit's own variable, and no framework variable is passed
|
|
238
|
-
* on. It is a throwaway provisioner's, never FABRIKA_APP_DATABASE_URL: the generated tests load application code. The
|
|
239
|
-
* SQLite kit opens an in-memory database and needs none.
|
|
240
|
-
*/
|
|
241
|
-
const testEnvironment = (source: DbCommandDependencies['source'], url: string | undefined): Record<string, string> => {
|
|
242
|
-
const environment: Record<string, string> = url === undefined ? {} : { FABRIKA_TEST_POSTGRES_URL: url, FABRIKA_TEST_POSTGRES_REQUIRED: '1' }
|
|
243
|
-
for (const name of ['PATH', 'HOME', 'TMPDIR']) {
|
|
244
|
-
const value = source[name]
|
|
245
|
-
if (value !== undefined) environment[name] = value
|
|
246
|
-
}
|
|
247
|
-
return environment
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* The server's own words for a refused connection (SQLSTATE 53300) and the test kit's report of one it gave up on. A
|
|
252
|
-
* run whose tests met one says so instead of counting cases: a case that could not connect proved nothing.
|
|
253
|
-
*/
|
|
254
|
-
const EXHAUSTED_CONNECTIONS = [
|
|
255
|
-
CONNECTION_CAPACITY_MESSAGE,
|
|
256
|
-
'remaining connection slots are reserved',
|
|
257
|
-
'too many clients already',
|
|
258
|
-
'too many connections for role',
|
|
259
|
-
'too many connections for database',
|
|
260
|
-
]
|
|
261
|
-
|
|
262
|
-
/** Whether the tests' output reports a connection the database refused for lack of a free slot. */
|
|
263
|
-
export const reportsExhaustedConnections = (output: string): boolean => EXHAUSTED_CONNECTIONS.some((text) => output.includes(text))
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* Runs exactly the generated tests, with an empty `bunfig.toml` so that no preload, root or ignore pattern of the
|
|
267
|
-
* application applies, and the platform's preload, which captures Bun's test functions before the application loads.
|
|
268
|
-
* Fails unless every case the scaffold wrote is reported as passed with an assertion. The child's output is never
|
|
269
|
-
* printed, because a dependency may write a credential into it; `--verbose`, which the platform never passes, prints it.
|
|
270
|
-
* On Postgres they run as a throwaway provisioner, dropped afterwards; on SQLite with no database URL at all.
|
|
271
|
-
*/
|
|
272
|
-
const testIsolation = async (argv: readonly string[], deps: DbCommandDependencies): Promise<void> => {
|
|
273
|
-
const verbose = argv.includes('--verbose')
|
|
274
|
-
refuseArguments('test-isolation', argv.filter((arg) => arg !== '--verbose'))
|
|
275
|
-
const sqlite = (await dialectAt(deps.cwd)) === 'sqlite'
|
|
276
|
-
const url = sqlite ? undefined : required(deps.source, 'FABRIKA_APP_DATABASE_URL')
|
|
277
|
-
const { files, tests, missing } = await expectedTests(deps.cwd)
|
|
278
|
-
if (missing.length > 0) throw new Error(`db test-isolation: the endpoint access tests are incomplete\n${missing.map(formatFinding).join('\n')}`)
|
|
279
|
-
for (const [path, { text }] of tests) {
|
|
280
|
-
if (files.get(path) !== text) throw new Error(`db test-isolation: ${path} is not the test fabrika db test-scaffold writes; run it`)
|
|
281
|
-
}
|
|
282
|
-
if (tests.size === 0) {
|
|
283
|
-
deps.write('no generated tests\n')
|
|
284
|
-
return
|
|
285
|
-
}
|
|
286
|
-
if (url === undefined) {
|
|
287
|
-
await runGeneratedTests(tests, verbose, testEnvironment(deps.source, undefined), deps)
|
|
288
|
-
return
|
|
289
|
-
}
|
|
290
|
-
let provisioner: TestProvisioner
|
|
291
|
-
try {
|
|
292
|
-
provisioner = await withConnectionCapacity(() => createTestProvisioner(url))
|
|
293
|
-
} catch (error) {
|
|
294
|
-
throw reportable(error)
|
|
295
|
-
}
|
|
296
|
-
if (provisioner.swept.length > 0) deps.write(`dropped the test provisioners earlier runs left behind: ${provisioner.swept.join(', ')}\n`)
|
|
297
|
-
try {
|
|
298
|
-
await runGeneratedTests(tests, verbose, testEnvironment(deps.source, provisioner.url), deps)
|
|
299
|
-
} finally {
|
|
300
|
-
await withConnectionCapacity(() => provisioner.drop()).catch((error: unknown) => {
|
|
301
|
-
throw reportable(error)
|
|
302
|
-
})
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
const runGeneratedTests = async (
|
|
307
|
-
tests: ReadonlyMap<string, GeneratedTest>,
|
|
308
|
-
verbose: boolean,
|
|
309
|
-
env: Record<string, string>,
|
|
310
|
-
deps: DbCommandDependencies,
|
|
311
|
-
): Promise<void> => {
|
|
312
|
-
const scratch = await mkdtemp(join(tmpdir(), 'fabrika-test-isolation-'))
|
|
313
|
-
try {
|
|
314
|
-
await writeFile(join(scratch, 'bunfig.toml'), '')
|
|
315
|
-
const report = join(scratch, 'junit.xml')
|
|
316
|
-
const child = Bun.spawn(
|
|
317
|
-
[
|
|
318
|
-
process.execPath,
|
|
319
|
-
`--config=${join(scratch, 'bunfig.toml')}`,
|
|
320
|
-
'test',
|
|
321
|
-
`--preload=${fileURLToPath(import.meta.resolve('@fabrika/app/testing/preload'))}`,
|
|
322
|
-
...[...tests.keys()].map((path) => `./${path}`),
|
|
323
|
-
'--reporter=junit',
|
|
324
|
-
`--reporter-outfile=${report}`,
|
|
325
|
-
],
|
|
326
|
-
{ cwd: deps.cwd, env, stdout: 'pipe', stderr: 'pipe' },
|
|
327
|
-
)
|
|
328
|
-
const [stdout, stderr, code] = await Promise.all([new Response(child.stdout).text(), new Response(child.stderr).text(), child.exited])
|
|
329
|
-
if (verbose) deps.write(`${stdout}${stderr}\n`)
|
|
330
|
-
const reported = readJunitCases(await readFile(report, 'utf8').catch(() => ''))
|
|
331
|
-
const failed: string[] = []
|
|
332
|
-
let total = 0
|
|
333
|
-
for (const [path, { cases }] of tests) {
|
|
334
|
-
for (const name of cases) {
|
|
335
|
-
total++
|
|
336
|
-
const reportedCase = reported.find((item) => item.file === path && item.name === name)
|
|
337
|
-
const outcome = reportedCase === undefined
|
|
338
|
-
? 'not run'
|
|
339
|
-
: reportedCase.outcome === 'passed' && reportedCase.assertions === 0
|
|
340
|
-
? 'no assertion'
|
|
341
|
-
: reportedCase.outcome
|
|
342
|
-
if (outcome !== 'passed') failed.push(`${path}: ${name} (${outcome})`)
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
if ((code !== 0 || failed.length > 0) && reportsExhaustedConnections(`${stdout}${stderr}`)) {
|
|
346
|
-
throw new Error(
|
|
347
|
-
`db test-isolation: ${CONNECTION_CAPACITY_MESSAGE} for the generated tests (SQLSTATE ${TOO_MANY_CONNECTIONS}), so they reached no verdict; other processes hold the database's connections: free them or give the database more, then run it again`,
|
|
348
|
-
)
|
|
349
|
-
}
|
|
350
|
-
if (code !== 0 || failed.length > 0) {
|
|
351
|
-
const rerun = verbose ? '' : '; rerun with --verbose locally to see the test output'
|
|
352
|
-
throw new Error(
|
|
353
|
-
`db test-isolation: ${total - failed.length} of ${total} generated cases passed (exit ${code})${rerun}${
|
|
354
|
-
failed.map((line) => `\n- ${line}`).join('')
|
|
355
|
-
}`,
|
|
356
|
-
)
|
|
357
|
-
}
|
|
358
|
-
deps.write(`${total} generated cases passed\n`)
|
|
359
|
-
} finally {
|
|
360
|
-
await rm(scratch, { recursive: true, force: true })
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
|
|
364
168
|
export const runDbCommand = async (command: string | undefined, argv: readonly string[], deps: DbCommandDependencies): Promise<void> => {
|
|
365
169
|
if (command === 'new') return newMigration(argv, deps)
|
|
366
170
|
if (command === 'migrate') return migrate(argv, deps)
|
|
367
171
|
if (command === 'codegen') return codegen(argv, deps)
|
|
368
|
-
|
|
369
|
-
|
|
172
|
+
// A platform release up to 0.9.0-dev.18 still runs this init command against the application's own CLI, and its
|
|
173
|
+
// reader admits a newer prerelease of the same version (ADR-0062): the command stays, and runs nothing.
|
|
174
|
+
if (command === 'test-isolation') {
|
|
175
|
+
deps.write('db test-isolation: nothing to run; this release generates no tests\n')
|
|
176
|
+
return
|
|
177
|
+
}
|
|
370
178
|
throw new Error(`Unknown db command: ${command ?? '(missing)'}\n\n${DB_USAGE}`)
|
|
371
179
|
}
|
|
372
180
|
|
package/src/index.ts
CHANGED
|
@@ -29,7 +29,7 @@ Usage:
|
|
|
29
29
|
fabrika env <inspect|maintenance|operations|recover|backups|restore> <app> <env> [arguments] [--json]
|
|
30
30
|
fabrika operations <issues|issue|releases|health> [options] [--json]
|
|
31
31
|
fabrika builder <init|next|advance|gate|ensure-daemon|induce|build> [options]
|
|
32
|
-
fabrika db <new|migrate|codegen
|
|
32
|
+
fabrika db <new|migrate|codegen> [options]
|
|
33
33
|
fabrika job run <name>
|
|
34
34
|
fabrika connect <add|pull> <app>/<export>@<version> --consumer=<app> --env=<env> [--url=<control origin>]
|
|
35
35
|
|
package/types/src/db.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const DB_USAGE = "fabrika db \u2014 an application's database schema: Postgres, or SQLite on Cloudflare\n\nUsage:\n fabrika db new <slug> Write db/migrations/<UTC YYYYMMDDHHMMSS>_<slug>.sql; the slug is lowercase snake_case.\n fabrika db migrate Apply the framework's tables, then db/migrations, to the application's schema app_<id>.\n fabrika db codegen [--verify] Write src/db/schema.generated.ts from the migrated schema; --verify only fails when it is stale.\n
|
|
1
|
+
export declare const DB_USAGE = "fabrika db \u2014 an application's database schema: Postgres, or SQLite on Cloudflare\n\nUsage:\n fabrika db new <slug> Write db/migrations/<UTC YYYYMMDDHHMMSS>_<slug>.sql; the slug is lowercase snake_case.\n fabrika db migrate Apply the framework's tables, then db/migrations, to the application's schema app_<id>.\n fabrika db codegen [--verify] Write src/db/schema.generated.ts from the migrated schema; --verify only fails when it is stale.\n\nRun from the application root. `migrate` and `codegen` read FABRIKA_APP_ID and FABRIKA_APP_DATABASE_URL from\nthe environment only. FABRIKA_APP_DATABASE_URL is the provisioning credential: `migrate` uses it only to create\nthe application's roles (app_<id> owns the schema, run_<id> gets DML on its tables) and fails when it cannot create\nroles. It applies the files as app_<id>, holds a lock derived from the application id, runs each file in one\ntransaction with lock_timeout 5000 ms and statement_timeout 60000 ms, and fails when a\nfile that already ran has changed: an applied migration is immutable, so a change is a new file.\n\nAn application whose fabrika.config.ts default-exports @fabrika/provider-cloudflare's defineApp runs on SQLite in its\nDurable Object, which applies the migrations itself when it boots: `migrate` refuses, `codegen` applies them to an\nin-memory database; neither needs a database URL.\n";
|
|
2
2
|
export interface DbCommandDependencies {
|
|
3
3
|
/** The application root. */
|
|
4
4
|
readonly cwd: string;
|
|
@@ -6,7 +6,5 @@ export interface DbCommandDependencies {
|
|
|
6
6
|
readonly now: () => Date;
|
|
7
7
|
readonly write: (line: string) => void;
|
|
8
8
|
}
|
|
9
|
-
/** Whether the tests' output reports a connection the database refused for lack of a free slot. */
|
|
10
|
-
export declare const reportsExhaustedConnections: (output: string) => boolean;
|
|
11
9
|
export declare const runDbCommand: (command: string | undefined, argv: readonly string[], deps: DbCommandDependencies) => Promise<void>;
|
|
12
10
|
export declare const runDbCli: (command: string | undefined, argv: readonly string[]) => Promise<void>;
|
package/src/junit.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// The test cases of a `bun test --reporter=junit` report: which ran, and how each ended. Only what `fabrika db
|
|
2
|
-
// test-isolation` needs to tell a passed case from a skipped, failed or missing one.
|
|
3
|
-
|
|
4
|
-
export type CaseOutcome = 'passed' | 'failed' | 'skipped'
|
|
5
|
-
|
|
6
|
-
export interface ReportedCase {
|
|
7
|
-
/** The test file, relative to the directory `bun test` ran in. */
|
|
8
|
-
readonly file: string
|
|
9
|
-
readonly name: string
|
|
10
|
-
readonly outcome: CaseOutcome
|
|
11
|
-
/** The `expect` calls the case ran, as Bun reports them; `null` when the report does not say. */
|
|
12
|
-
readonly assertions: number | null
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const ENTITIES: Readonly<Record<string, string>> = { quot: '"', apos: "'", lt: '<', gt: '>', amp: '&' }
|
|
16
|
-
|
|
17
|
-
const unescape = (text: string): string => text.replace(/&(quot|apos|lt|gt|amp);/g, (_, name: string) => ENTITIES[name] ?? '')
|
|
18
|
-
|
|
19
|
-
const attribute = (attributes: string, name: string): string | undefined => {
|
|
20
|
-
const match = new RegExp(`\\s${name}="([^"]*)"`).exec(attributes)
|
|
21
|
-
return match?.[1] === undefined ? undefined : unescape(match[1])
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function readJunitCases(xml: string): ReportedCase[] {
|
|
25
|
-
const cases: ReportedCase[] = []
|
|
26
|
-
for (const match of xml.matchAll(/<testcase\b([^>]*?)(\/>|>([\s\S]*?)<\/testcase>)/g)) {
|
|
27
|
-
const attributes = match[1] ?? ''
|
|
28
|
-
const content = match[3] ?? ''
|
|
29
|
-
const file = attribute(attributes, 'file')
|
|
30
|
-
const name = attribute(attributes, 'name')
|
|
31
|
-
if (file === undefined || name === undefined) continue
|
|
32
|
-
const outcome: CaseOutcome = /<(failure|error)\b/.test(content) ? 'failed' : /<skipped\b/.test(content) ? 'skipped' : 'passed'
|
|
33
|
-
const assertions = attribute(attributes, 'assertions')
|
|
34
|
-
cases.push({ file: file.replace(/^\.\//, ''), name, outcome, assertions: assertions === undefined ? null : Number(assertions) })
|
|
35
|
-
}
|
|
36
|
-
return cases
|
|
37
|
-
}
|
package/types/src/junit.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export type CaseOutcome = 'passed' | 'failed' | 'skipped';
|
|
2
|
-
export interface ReportedCase {
|
|
3
|
-
/** The test file, relative to the directory `bun test` ran in. */
|
|
4
|
-
readonly file: string;
|
|
5
|
-
readonly name: string;
|
|
6
|
-
readonly outcome: CaseOutcome;
|
|
7
|
-
/** The `expect` calls the case ran, as Bun reports them; `null` when the report does not say. */
|
|
8
|
-
readonly assertions: number | null;
|
|
9
|
-
}
|
|
10
|
-
export declare function readJunitCases(xml: string): ReportedCase[];
|