@coexist/testing 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Coaction
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # @coexist/testing
2
+
3
+ > Testing helper facade for [Coexist](../../README.md). Re-exports `testApp` and its types from [`@coexist/core`](../core) under a dedicated, intention-revealing import for test files.
4
+
5
+ Importing `testApp` from `@coexist/testing` keeps test setup separate from production imports. The behavior is identical to `@coexist/core`'s `testApp`.
6
+
7
+ ## Installation
8
+
9
+ ```sh
10
+ pnpm add -D @coexist/testing
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { afterEach, describe, expect, it } from "vitest";
17
+ import { defineModule, provide } from "@coexist/core";
18
+ import { testApp, type TestApp } from "@coexist/testing";
19
+
20
+ abstract class Logger {
21
+ abstract info(message: string): void;
22
+ }
23
+
24
+ class MemoryLogger implements Logger {
25
+ readonly messages: string[] = [];
26
+ info(message: string): void {
27
+ this.messages.push(message);
28
+ }
29
+ }
30
+
31
+ class Counter {
32
+ count = 0;
33
+ constructor(readonly logger: Logger) {}
34
+ increase(step = 1): void {
35
+ this.count += step;
36
+ this.logger.info(`count:${this.count}`);
37
+ }
38
+ }
39
+
40
+ defineModule(Counter, {
41
+ actions: ["increase"],
42
+ deps: [Logger],
43
+ name: "counter",
44
+ state: ["count"],
45
+ });
46
+
47
+ let app: TestApp | undefined;
48
+
49
+ afterEach(async () => {
50
+ await app?.dispose();
51
+ app = undefined;
52
+ });
53
+
54
+ describe("Counter", () => {
55
+ it("records actions and overrides providers", () => {
56
+ const logger = new MemoryLogger();
57
+ app = testApp({
58
+ providers: [Counter, provide(Logger, { useValue: console })],
59
+ overrides: [provide(Logger, { useValue: logger })],
60
+ strictActions: true,
61
+ });
62
+
63
+ app.getModule(Counter).increase(2);
64
+
65
+ expect(logger.messages).toEqual(["count:2"]);
66
+ expect(app.test.getActions()).toMatchObject([{ method: "increase", module: "counter" }]);
67
+ expect(app.test.getState()).toEqual({ counter: { count: 2 } });
68
+ });
69
+ });
70
+ ```
71
+
72
+ ## API
73
+
74
+ `testApp(options)` is overloaded:
75
+
76
+ - `testApp(options?)` → `TestApp` (synchronous).
77
+ - `testApp({ autoStart: true, ... })` → `Promise<TestApp>` (resolves after `start()`).
78
+
79
+ Options extend `createApp` options with:
80
+
81
+ | Option | Type | Description |
82
+ | --------------- | ----------------- | -------------------------------------------------------------------------------- |
83
+ | `overrides` | `ProviderInput[]` | Replace providers discovered from `providers`. Cannot add a brand-new `@Module`. |
84
+ | `autoStart` | `boolean` | Start the app and return a promise. |
85
+ | `strictActions` | `boolean` | Enforce action boundaries on all state writes. |
86
+
87
+ The `app.test` inspector exposes `getActions()`, `getState()`, `getPatches()`, `clearActions()`, `clearPatches()`, and `flushEffects()`.
88
+
89
+ ## Exports
90
+
91
+ `testApp`, and the `TestApp`, `TestAppOptions`, `AutoStartedTestAppOptions`, `ManualTestAppOptions` types.
92
+
93
+ ## License
94
+
95
+ [MIT](../../LICENSE) © Coaction
@@ -0,0 +1,2 @@
1
+ import { AutoStartedTestAppOptions, ManualTestAppOptions, TestApp, TestAppOptions, testApp } from "@coexist/core";
2
+ export { type AutoStartedTestAppOptions, type ManualTestAppOptions, type TestApp, type TestAppOptions, testApp };
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import { testApp } from "@coexist/core";
2
+ export { testApp };
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@coexist/testing",
3
+ "version": "0.2.0",
4
+ "description": "Testing helpers for Coexist.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/coactionjs/coexist.git",
9
+ "directory": "packages/testing"
10
+ },
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "type": "module",
15
+ "sideEffects": false,
16
+ "module": "./dist/index.mjs",
17
+ "types": "./dist/index.d.mts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.mts",
21
+ "import": "./dist/index.mjs"
22
+ }
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "dependencies": {
28
+ "@coexist/core": "0.2.0"
29
+ },
30
+ "devDependencies": {
31
+ "tsdown": "0.22.3",
32
+ "typescript": "6.0.3",
33
+ "vitest": "4.1.9",
34
+ "@coexist/tsconfig": "0.1.0"
35
+ },
36
+ "scripts": {
37
+ "build": "tsdown",
38
+ "clean": "rm -rf coverage dist .turbo",
39
+ "dev": "tsdown --watch",
40
+ "test": "cd ../.. && vitest run --project @coexist/testing",
41
+ "test:coverage": "cd ../.. && vitest run --coverage --project @coexist/testing",
42
+ "typecheck": "tsc -p tsconfig.json --noEmit"
43
+ }
44
+ }