@strav/testing 0.1.0 → 0.1.1
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/README.md +6 -6
- package/package.json +1 -1
- package/src/factory.ts +1 -1
- package/src/test_case.ts +9 -9
package/README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @strav/testing
|
|
2
2
|
|
|
3
|
-
Testing utilities for the [Strav](https://www.npmjs.com/package/@
|
|
3
|
+
Testing utilities for the [Strav](https://www.npmjs.com/package/@strav/core) framework. Provides HTTP testing helpers, authentication simulation, transaction-based test isolation, and model factories.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
bun add -d @
|
|
8
|
+
bun add -d @strav/testing
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
Requires `@
|
|
11
|
+
Requires `@strav/core` as a peer dependency.
|
|
12
12
|
|
|
13
13
|
## TestCase
|
|
14
14
|
|
|
@@ -16,7 +16,7 @@ Boots the app, provides HTTP helpers, and wraps each test in a rolled-back trans
|
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
import { describe, test, expect } from 'bun:test'
|
|
19
|
-
import { TestCase } from '@
|
|
19
|
+
import { TestCase } from '@strav/testing'
|
|
20
20
|
|
|
21
21
|
const t = await TestCase.boot({
|
|
22
22
|
auth: true,
|
|
@@ -62,7 +62,7 @@ t.withoutAuth() // clear auth token
|
|
|
62
62
|
Lightweight model factory for test data seeding.
|
|
63
63
|
|
|
64
64
|
```ts
|
|
65
|
-
import { Factory } from '@
|
|
65
|
+
import { Factory } from '@strav/testing'
|
|
66
66
|
|
|
67
67
|
const UserFactory = Factory.define(User, (seq) => ({
|
|
68
68
|
pid: crypto.randomUUID(),
|
package/package.json
CHANGED
package/src/factory.ts
CHANGED
package/src/test_case.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { SQL, ReservedSQL } from 'bun'
|
|
2
|
-
import { app, Configuration, ExceptionHandler } from '@
|
|
3
|
-
import { Database, BaseModel } from '@
|
|
4
|
-
import { Router } from '@
|
|
2
|
+
import { app, Configuration, ExceptionHandler } from '@strav/kernel'
|
|
3
|
+
import { Database, BaseModel } from '@strav/database'
|
|
4
|
+
import { Router } from '@strav/http'
|
|
5
5
|
import { Factory } from './factory.ts'
|
|
6
6
|
|
|
7
7
|
export interface TestCaseOptions {
|
|
@@ -22,7 +22,7 @@ export interface TestCaseOptions {
|
|
|
22
22
|
* transaction for full isolation.
|
|
23
23
|
*
|
|
24
24
|
* @example
|
|
25
|
-
* import { TestCase, Factory } from '@
|
|
25
|
+
* import { TestCase, Factory } from '@strav/testing'
|
|
26
26
|
*
|
|
27
27
|
* const t = await TestCase.boot({
|
|
28
28
|
* auth: true,
|
|
@@ -70,8 +70,8 @@ export class TestCase {
|
|
|
70
70
|
|
|
71
71
|
// Auth + Session
|
|
72
72
|
if (this.options.auth) {
|
|
73
|
-
const { SessionManager } = await import('@
|
|
74
|
-
const { Auth } = await import('@
|
|
73
|
+
const { SessionManager } = await import('@strav/http')
|
|
74
|
+
const { Auth } = await import('@strav/http')
|
|
75
75
|
|
|
76
76
|
if (!app.has(SessionManager)) app.singleton(SessionManager)
|
|
77
77
|
if (!app.has(Auth)) app.singleton(Auth)
|
|
@@ -89,8 +89,8 @@ export class TestCase {
|
|
|
89
89
|
|
|
90
90
|
// View engine
|
|
91
91
|
if (this.options.views) {
|
|
92
|
-
const { ViewEngine } = await import('@
|
|
93
|
-
const { Context } = await import('@
|
|
92
|
+
const { ViewEngine } = await import('@strav/view')
|
|
93
|
+
const { Context } = await import('@strav/http')
|
|
94
94
|
|
|
95
95
|
if (!app.has(ViewEngine)) app.singleton(ViewEngine)
|
|
96
96
|
const viewEngine = app.resolve(ViewEngine)
|
|
@@ -193,7 +193,7 @@ export class TestCase {
|
|
|
193
193
|
* Creates a real AccessToken in the database.
|
|
194
194
|
*/
|
|
195
195
|
async actingAs(user: unknown, tokenName = 'test-token'): Promise<this> {
|
|
196
|
-
const { AccessToken } = await import('@
|
|
196
|
+
const { AccessToken } = await import('@strav/http')
|
|
197
197
|
const { token } = await AccessToken.create(user, tokenName)
|
|
198
198
|
this._token = token
|
|
199
199
|
return this
|