Skip to content

Commit a58764f

Browse files
authored
Merge pull request #99 from thefrontside/tm/try-v4
### Motivation All `@effectionx` extensions were migrated to v3 in #87, but we now want to ensure compatibility with effection v4. This PR adds the infrastructure to run tests against both v3 and v4 versions of effection, and prepares all packages for publishing with dual version support. ### Changes #### Import Map Generation - Created `tasks/generate-importmap.ts` that **dynamically fetches the latest v4 version** from the npm registry at generation time - The import map automatically collects all external dependencies from workspace packages - Maps `@effectionx/*` packages to their local paths for testing #### CI Workflow Updates - Refactored `.github/workflows/verify-posix.yaml` and `.github/workflows/verify-windows.yaml` to use `workflow_call` for reusability - CI now runs both **V3 Tests** and **V4 Tests** on every PR and push to main - Added `--trace-leaks` flag to v4 tests for better debugging - Updated publish workflow to require verification jobs before publishing #### NPM Peer Dependency - Updated `tasks/build-npm.ts` to use `"effection": "^3 || ^4.0.0-0"` to support v4 prereleases #### Version Bumps All 16 packages received minor version bumps to publish with v3/v4 compatibility: | Package | New Version | |---------|-------------| | @effectionx/context-api | 0.2.0 | | @effectionx/deno-deploy | 0.3.0 | | @effectionx/bdd | 0.3.0 | | @effectionx/jsonl-store | 0.3.0 | | @effectionx/fx | 0.3.0 | | @effectionx/raf | 0.1.0 | | @effectionx/task-buffer | 1.2.0 | | @effectionx/test-adapter | 0.6.0 | | @effectionx/timebox | 0.3.0 | | @effectionx/tinyexec | 0.3.0 | | @effectionx/watch | 0.3.0 | | @effectionx/websocket | 2.2.0 | | @effectionx/worker | 0.3.0 | | @effectionx/stream-helpers | 0.4.0 | | @effectionx/signals | 0.4.0 | | @effectionx/process | 0.6.0 | #### Test Adapter Enhancements - Added sanitization options to test functions for disabling operation and resource sanitization when needed #### Resource Refactoring - Converted process to use resource pattern (required for v4 compatibility) - Refactored inspector into a resource #### Test Compatibility Fixes Multiple test files were updated to work with both v3 and v4: - Added `sleep(0)` calls to give the operation tree time to set up subscriptions - Wrapped operations in `spawn` where v4's stricter lifecycle management requires it - Fixed `batch` stream completion handling for proper done state propagation #### Documentation - Added testing instructions to root `README.md` for running v3 and v4 tests - Rewrote `process/README.md` with comprehensive documentation ### How to Use 1. Generate the v4 import map: ```bash deno task generate-importmap ``` 2. Run tests with v4: ```bash deno test --import-map v4.importmap.json -A ``` 3. Run tests with v3 (default): ```bash deno test -A ``` ### Summary - **53 files changed**, 1,211 insertions(+), 489 deletions(-) - Key packages affected: `stream-helpers`, `signals`, `task-buffer`, `watch`, `process`, `test-adapter`, `fx`
2 parents 6a91984 + 53bd33c commit a58764f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1227
-494
lines changed

.github/workflows/publish.yaml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ on:
55
- main
66

77
jobs:
8+
verify-posix:
9+
uses: ./.github/workflows/verify-posix.yaml
10+
11+
verify-windows:
12+
uses: ./.github/workflows/verify-windows.yaml
13+
814
generate-matrix:
15+
needs: [verify-posix, verify-windows]
916
name: Generate Job Matrix
1017
runs-on: ubuntu-latest
1118
outputs:
@@ -23,7 +30,7 @@ jobs:
2330
id: set-matrix
2431

2532
jsr:
26-
if: fromJSON(needs.generate-matrix.outputs.exists)
33+
if: github.ref == 'refs/heads/main' && fromJSON(needs.generate-matrix.outputs.exists)
2734
name: Publish ${{ matrix.name }}@${{matrix.version}} to JSR
2835
runs-on: ubuntu-latest
2936

@@ -46,7 +53,7 @@ jobs:
4653
working-directory: ${{ matrix.workspace }}
4754

4855
npm:
49-
if: fromJSON(needs.generate-matrix.outputs.exists)
56+
if: github.ref == 'refs/heads/main' && fromJSON(needs.generate-matrix.outputs.exists)
5057
name: Publish ${{ matrix.name }}@${{matrix.version}} to NPM
5158
runs-on: ubuntu-latest
5259

@@ -77,7 +84,7 @@ jobs:
7784
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
7885

7986
tag:
80-
if: fromJSON(needs.generate-matrix.outputs.exists)
87+
if: github.ref == 'refs/heads/main' && fromJSON(needs.generate-matrix.outputs.exists)
8188
name: "Tag Release"
8289
runs-on: ubuntu-latest
8390
needs: [generate-matrix, jsr, npm]

.github/workflows/verify-posix.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
name: Verify (POSIX)
22

33
on:
4-
push:
5-
branches:
6-
- main
4+
workflow_call:
75
pull_request:
86
branches:
97
- main
@@ -34,5 +32,11 @@ jobs:
3432
- run: deno fmt --check
3533

3634
- run: deno lint
35+
- run: deno task generate-importmap "^3" v3.importmap.json
36+
- run: deno task generate-importmap v4 v4.importmap.json
37+
38+
- name: V3 Tests
39+
run: deno test --import-map v3.importmap.json --allow-net --allow-read --allow-write --allow-env --allow-run --allow-ffi
3740

38-
- run: deno test --allow-net --allow-read --allow-write --allow-env --allow-run --allow-ffi
41+
- name: V4 Tests
42+
run: deno test --import-map v4.importmap.json --allow-net --allow-read --allow-write --allow-env --allow-run --allow-ffi --trace-leaks

.github/workflows/verify-windows.yaml

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
name: Verify (Windows)
22

33
on:
4-
push:
5-
branches:
6-
- main
4+
workflow_call:
75
pull_request:
86
branches:
97
- main
@@ -41,20 +39,41 @@ jobs:
4139

4240
- run: deno lint
4341

44-
- name: "Test (${{matrix.shell}})"
42+
- run: deno task generate-importmap "^3" v3.importmap.json
43+
- run: deno task generate-importmap v4 v4.importmap.json
44+
45+
- name: "Test V3 (${{matrix.shell}})"
46+
if: matrix.shell == 'powershell' || matrix.shell == 'pwsh'
47+
run: |
48+
$env:SHELL = "${{matrix.shell}}"
49+
deno test --import-map v3.importmap.json --allow-net --allow-read --allow-write --allow-env --allow-run --allow-ffi --trace-leaks
50+
51+
- name: "Test V4 (${{matrix.shell}})"
4552
if: matrix.shell == 'powershell' || matrix.shell == 'pwsh'
4653
run: |
4754
$env:SHELL = "${{matrix.shell}}"
48-
deno test --allow-net --allow-read --allow-write --allow-env --allow-run --allow-ffi --trace-leaks
55+
deno test --import-map v4.importmap.json --allow-net --allow-read --allow-write --allow-env --allow-run --allow-ffi --trace-leaks
4956
50-
- name: "Test (${{matrix.shell}})"
57+
- name: "Test V3 (${{matrix.shell}})"
5158
if: matrix.shell == 'cmd'
5259
run: |
5360
set SHELL=${{matrix.shell}}
54-
deno test --allow-net --allow-read --allow-write --allow-env --allow-run --allow-ffi --trace-leaks
61+
deno test --import-map v3.importmap.json --allow-net --allow-read --allow-write --allow-env --allow-run --allow-ffi --trace-leaks
62+
63+
- name: "Test V4 (${{matrix.shell}})"
64+
if: matrix.shell == 'cmd'
65+
run: |
66+
set SHELL=${{matrix.shell}}
67+
deno test --import-map v4.importmap.json --allow-net --allow-read --allow-write --allow-env --allow-run --allow-ffi --trace-leaks
68+
69+
- name: "Test V3 (${{matrix.shell}})"
70+
if: matrix.shell == 'bash'
71+
run: |
72+
export SHELL=${{matrix.shell}}
73+
deno test --import-map v3.importmap.json --allow-net --allow-read --allow-write --allow-env --allow-run --allow-ffi --trace-leaks
5574
56-
- name: "Test (${{matrix.shell}})"
75+
- name: "Test V4 (${{matrix.shell}})"
5776
if: matrix.shell == 'bash'
5877
run: |
5978
export SHELL=${{matrix.shell}}
60-
deno test --allow-net --allow-read --allow-write --allow-env --allow-run --allow-ffi --trace-leaks
79+
deno test --import-map v4.importmap.json --allow-net --allow-read --allow-write --allow-env --allow-run --allow-ffi --trace-leaks

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/deno.lock
22
/**/build/
3+
/v3.importmap.json
4+
/v4.importmap.json
35

46
.vscode

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,33 @@ more than a few times are welcome.
1515
5. Add doc strings to your source code - they will be used for documentation on
1616
the site.
1717

18+
## Testing
19+
20+
All packages are tested against both effection v3 and v4 to ensure
21+
compatibility.
22+
23+
### Generate import maps
24+
25+
```bash
26+
# Generate v3 import map
27+
deno task generate-importmap "^3" v3.importmap.json
28+
29+
# Generate v4 import map (fetches latest v4 from npm)
30+
deno task generate-importmap v4 v4.importmap.json
31+
```
32+
33+
### Running tests with v3
34+
35+
```bash
36+
deno test --import-map v3.importmap.json -A
37+
```
38+
39+
### Running tests with v4
40+
41+
```bash
42+
deno test --import-map v4.importmap.json -A
43+
```
44+
1845
## To publish a new project
1946

2047
1. Member of [jsr.io/@effectionx](https://jsr.io/@effectionx) has to add that

bdd/deno.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "@effectionx/bdd",
33
"exports": "./mod.ts",
4-
"version": "0.2.2",
4+
"version": "0.3.0",
55
"license": "MIT",
66
"imports": {
77
"effection": "npm:effection@^3",
8-
"@effectionx/test-adapter": "jsr:@effectionx/test-adapter@^0.1.0",
8+
"@effectionx/test-adapter": "jsr:@effectionx/test-adapter@^0.5.1",
99
"@std/testing": "jsr:@std/testing@^1"
1010
}
1111
}

bdd/mod.ts

Lines changed: 74 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,65 @@ import {
66
it as $it,
77
} from "@std/testing/bdd";
88

9+
/**
10+
* Sanitization options for test cases and test suites.
11+
* These options control Deno's test sanitizers.
12+
*/
13+
export interface SanitizeOptions {
14+
/** Ensure the test case does not prematurely cause the process to exit. Defaults to true. */
15+
sanitizeExit?: boolean;
16+
/** Check that the number of async completed ops after the test is the same as number of dispatched ops. Defaults to true. */
17+
sanitizeOps?: boolean;
18+
/** Ensure the test case does not "leak" resources - ie. the resource table after the test has exactly the same contents as before the test. Defaults to true. */
19+
sanitizeResources?: boolean;
20+
}
21+
922
let current: TestAdapter | undefined;
1023

11-
export function describe(name: string, body: () => void) {
24+
export function describe(
25+
name: string,
26+
body: () => void,
27+
options?: SanitizeOptions,
28+
) {
1229
const original = current;
1330
try {
1431
const child = current = createTestAdapter({ name, parent: original });
1532

16-
$describe(name, () => {
17-
$afterAll(() => child.destroy());
18-
body();
33+
$describe({
34+
name,
35+
fn: () => {
36+
$afterAll(() => child.destroy());
37+
body();
38+
},
39+
...options,
1940
});
2041
} finally {
2142
current = original;
2243
}
2344
}
2445

2546
describe.skip = $describe.skip;
26-
describe.only = $describe.only;
47+
describe.only = function (
48+
name: string,
49+
body: () => void,
50+
options?: SanitizeOptions,
51+
): void {
52+
const original = current;
53+
try {
54+
const child = current = createTestAdapter({ name, parent: original });
55+
56+
$describe.only({
57+
name,
58+
fn: () => {
59+
$afterAll(() => child.destroy());
60+
body();
61+
},
62+
...options,
63+
});
64+
} finally {
65+
current = original;
66+
}
67+
};
2768

2869
export function beforeAll(body: () => Operation<void>) {
2970
current?.addOnetimeSetup(body);
@@ -33,17 +74,25 @@ export function beforeEach(body: () => Operation<void>) {
3374
current?.addSetup(body);
3475
}
3576

36-
export function it(desc: string, body?: () => Operation<void>): void {
77+
export function it(
78+
desc: string,
79+
body?: () => Operation<void>,
80+
options?: SanitizeOptions,
81+
): void {
3782
const adapter = current!;
3883
if (!body) {
3984
$it.skip(desc, () => {});
4085
return;
4186
}
42-
$it(desc, async () => {
43-
const result = await adapter.runTest(body);
44-
if (!result.ok) {
45-
throw result.error;
46-
}
87+
$it({
88+
name: desc,
89+
fn: async () => {
90+
const result = await adapter.runTest(body);
91+
if (!result.ok) {
92+
throw result.error;
93+
}
94+
},
95+
...options,
4796
});
4897
}
4998

@@ -52,12 +101,20 @@ it.skip = (...args: Parameters<typeof it>): ReturnType<typeof it> => {
52101
return $it.skip(desc, () => {});
53102
};
54103

55-
it.only = (desc: string, body: () => Operation<void>): void => {
104+
it.only = (
105+
desc: string,
106+
body: () => Operation<void>,
107+
options?: SanitizeOptions,
108+
): void => {
56109
const adapter = current!;
57-
$it.only(desc, async () => {
58-
const result = await adapter.runTest(body);
59-
if (!result.ok) {
60-
throw result.error;
61-
}
110+
$it.only({
111+
name: desc,
112+
fn: async () => {
113+
const result = await adapter.runTest(body);
114+
if (!result.ok) {
115+
throw result.error;
116+
}
117+
},
118+
...options,
62119
});
63120
};

context-api/deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@effectionx/context-api",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"license": "MIT",
55
"exports": "./mod.ts",
66
"imports": {

deno-deploy/deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@effectionx/deno-deploy",
3-
"version": "0.2.0",
3+
"version": "0.3.0",
44
"exports": "./mod.ts",
55
"license": "MIT",
66
"imports": {

deno.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"effection": "npm:effection@^3",
44
"@deno/dnt": "jsr:@deno/[email protected]",
55
"@std/path": "jsr:@std/path@^1",
6-
"zod": "npm:[email protected]"
6+
"zod": "npm:[email protected]",
7+
"@std/fs": "jsr:@std/fs@^1"
78
},
89
"compilerOptions": {
910
"lib": [
@@ -20,7 +21,10 @@
2021
"prefer-const",
2122
"require-yield"
2223
]
23-
}
24+
},
25+
"exclude": [
26+
"tasks"
27+
]
2428
},
2529
"workspace": [
2630
"./context-api",
@@ -39,5 +43,8 @@
3943
"./stream-helpers",
4044
"./signals",
4145
"./process"
42-
]
46+
],
47+
"tasks": {
48+
"generate-importmap": "deno run --allow-read --allow-write --allow-net tasks/generate-importmap.ts"
49+
}
4350
}

0 commit comments

Comments
 (0)