Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
265 commits
Select commit Hold shift + click to select a range
8c332b5
build @effection/core with tsc only
dagda1 Jul 15, 2021
983157b
most things passing
dagda1 Jul 15, 2021
dadf9b9
more tsconfig twiddling
dagda1 Jul 15, 2021
8131c27
copy references from tsconfig to tsconfig.dist
dagda1 Jul 15, 2021
92b89b3
get rid of src in dist
dagda1 Jul 15, 2021
b516408
Remove tsdx from all packages
minkimcello Jul 22, 2021
88481cf
Use preview version of @frontside/eslint-config
minkimcello Jul 23, 2021
7455965
Delete tsconfig.dist.tsbuildinfo
minkimcello Jul 23, 2021
54c6029
Return carets back for the deps
minkimcello Jul 23, 2021
8eec9de
Indent correction process package.json
minkimcello Jul 23, 2021
92f20f0
publish new versions
frontsidejack Jul 27, 2021
da0b0ec
Upgrade ts to 4.0.0 and bring typedoc to root
minkimcello Jun 22, 2021
42eec91
Configure typeDocEntry property per package
minkimcello Jun 23, 2021
3f1d8af
Add spawn operation directly to Task.
cowboyd Jul 26, 2021
cad5b5e
fix files array in @effection/atom (#459)
dagda1 Jul 28, 2021
45907f7
publish new versions (#456)
frontsidejack Jul 28, 2021
1a54843
🚨Fix linting errors
cowboyd Jul 27, 2021
8ee2dd9
Add esm build (#462)
dagda1 Aug 3, 2021
5f99b98
publish new versions
frontsidejack Aug 3, 2021
9a2f424
normalize to dist-cjs and dist-esm
jbolda Aug 3, 2021
6afa339
simply dist-*
jbolda Aug 3, 2021
c982c87
publish new versions
frontsidejack Aug 4, 2021
deeda7f
Add sideEffects field to package.json (#470)
dagda1 Aug 5, 2021
1321894
publish new versions (#471)
frontsidejack Aug 6, 2021
7a1dea5
Merge pull request #455 from thefrontside/scoped-spawn
jnicklas Aug 10, 2021
ae330b5
publish new versions
frontsidejack Aug 13, 2021
e9874a9
publish new versions
frontsidejack Aug 16, 2021
7a3e0b5
publish new versions
frontsidejack Aug 16, 2021
dc4da1e
Fix lint warnings
jnicklas Aug 27, 2021
7d8c185
publish new versions
frontsidejack Aug 30, 2021
50e3f26
label @effection/process Operations
jbolda Jul 20, 2021
39fc72b
Improve labelling of process things
jnicklas Aug 27, 2021
38a57d0
Improve naming scheme of exec labels
jnicklas Sep 6, 2021
f4fb258
publish new versions
frontsidejack Sep 7, 2021
e4358b8
publish new versions
frontsidejack Sep 10, 2021
51b6ffc
Update package homepage links
Sep 13, 2021
9d09d80
publish new versions
frontsidejack Sep 21, 2021
c872d37
Split `Stream` into its own package
jnicklas Sep 27, 2021
c71fc7f
Add package readmes
cowboyd Sep 28, 2021
c3f8c6a
Improve process streams
jnicklas Sep 22, 2021
0c4841a
Remove internal dev dependencies
jnicklas Sep 29, 2021
eaead68
publish new versions
frontsidejack Sep 29, 2021
8415621
publish new versions
frontsidejack Sep 30, 2021
9bc9376
publish new versions
frontsidejack Sep 30, 2021
05e0efc
publish new versions
frontsidejack Sep 30, 2021
ee7c29a
publish new versions
frontsidejack Oct 7, 2021
43c9782
Release 2.0.0
jnicklas Oct 7, 2021
0c818b6
update dependencies for core / non-core packages
cowboyd Oct 11, 2021
7c6c508
publish new versions
frontsidejack Oct 12, 2021
d918922
Upgrade ts-node
jnicklas Nov 8, 2021
49a33eb
publish new versions
frontsidejack Nov 29, 2021
26eca35
fix review comments
wKich Jan 12, 2022
199974a
return previous behaviour for `withLabel` to don't make breaking changes
wKich Jan 19, 2022
4492729
Fix review comments
wKich Jan 20, 2022
80f7a06
Remove node-fetch
minkimcello Jan 24, 2022
c5bce27
Replace node-fetch with effection fetch in process tests
minkimcello Jan 24, 2022
175063a
Use effection/mocha's captureError() in daemon test
minkimcello Jan 25, 2022
f24ae3c
publish new versions
frontsidejack Jan 25, 2022
8b30bb0
add changelog
wKich Jan 26, 2022
d2ee2a9
Merge branch 'v2' into add-operation-object
wKich Jan 26, 2022
0aa6c8b
publish new versions
frontsidejack Jan 31, 2022
721dfeb
execa within main test, v5
jbolda Mar 7, 2022
e449cea
execa v6 as separate suite (temp)
jbolda Mar 7, 2022
afa1028
execa tests in main test suite
jbolda Mar 28, 2022
b935282
remove separate execa test suite
jbolda Mar 28, 2022
d7a7220
remove execa tests from main test suite
jbolda Mar 28, 2022
e0e8710
add ability to specify a shell string
jbolda Mar 29, 2022
170fc9c
fix shell: false
jbolda Mar 29, 2022
2f83d1e
clarify some mac and linux returns
jbolda Mar 29, 2022
34a8eb0
mac needs squiggly brackets
jbolda Mar 29, 2022
ecfdb98
add another case
jbolda Mar 29, 2022
f8a488c
undo formatting changes
jbolda Apr 7, 2022
74d8d23
improve test string text
jbolda Apr 7, 2022
fd8ff25
update typedoc text
jbolda Apr 10, 2022
aa679ac
publish new versions
frontsidejack Apr 11, 2022
419113e
bump ctrlc-windows to 2.1.0
jbolda Sep 21, 2022
e8f1eab
publish new versions
frontsidejack Sep 27, 2022
dd85580
publish new versions
frontsidejack Oct 5, 2022
8a1e5aa
Moved @types/node to devDependencies in root
taras Dec 22, 2022
cb35fcd
Moved typescript to root
taras Dec 22, 2022
9dbb3ee
Fix types in process
taras Dec 22, 2022
da1db59
Fix types tests
taras Dec 22, 2022
c42f761
Fix types tests
taras Dec 22, 2022
3d3ea9d
Fix types tests
taras Dec 22, 2022
62b5675
Move mocha and @types/mocha to root
taras Dec 22, 2022
110f190
Move expect to root
taras Dec 22, 2022
582dfc9
Unnecessary errors
taras Dec 22, 2022
bea0da0
Moved ts-node to root
taras Dec 22, 2022
d18989d
Move @frontside/tsconfig to root
taras Dec 22, 2022
f1dadb9
publish new versions
frontsidejack Jun 8, 2023
00b6627
publish new versions
frontsidejack Oct 24, 2023
d2fc44e
Add 'process/' from commit '27d56ad6871641502dc9d098c606da2651aba25e'
Sep 6, 2025
9bd79e0
Uncomment and modernize remaining output-stream tests
Sep 6, 2025
fe53684
Modernize process module with Effection v5 APIs
Sep 6, 2025
6fc788a
Add null safety for child process streams and clean up tests
Sep 6, 2025
c7eadd3
Added helpers
Sep 7, 2025
3744f19
Added spawning tests
Sep 7, 2025
ef0d10b
Refactor to use forEach with return
Sep 7, 2025
87af0c4
Refactored to use deno testing bdd
Sep 8, 2025
e85213e
All happy path tests are passing
Sep 8, 2025
d130621
Failure paths are working
Sep 8, 2025
5db6b86
All posix tests are passing
Sep 8, 2025
4163cae
Refactored stream expect to expectMatch
Sep 8, 2025
d7ceeaa
Revert "Refactored stream expect to expectMatch"
Sep 8, 2025
e51eb2c
Refactored waiting for 'listening' to use expectMatch
Sep 8, 2025
04c3e9b
Fix daemon test is passing
Sep 8, 2025
baa89ab
Daemon tests are passing
Sep 9, 2025
6e950a2
watch tests are passing
Sep 10, 2025
bd3240c
Fixed stdout draining
Sep 10, 2025
31dd3af
All of the tests are passing
Sep 11, 2025
5abc6bd
Added chooser between posix and win32
Sep 11, 2025
acbd585
Fixed formatting
Sep 11, 2025
f2b3067
Fixed all lint errors and normalized on effection ^3 -> 3.6.0
Sep 11, 2025
1b664d9
Removed unused @
Sep 11, 2025
f8c550d
Additional cleanup
Sep 11, 2025
7c9c534
Add docs for for-each
Sep 11, 2025
8b5baf5
Added jsdoc to for-each
Sep 14, 2025
c4efb63
Refactored on to use unknown[] args
Sep 14, 2025
401ca22
Replaced onceEmit with once
Sep 14, 2025
3013b86
Replaced once with onceEmit
Sep 14, 2025
9f66491
Changed createOutputStreamFromEventEmitter to createOutputStreamFromR…
Sep 14, 2025
db5b5eb
stream-helpers: Add forEach documentation and bump to v0.3.0
Sep 14, 2025
bdda082
Use forEach from stream-helpers in process
Sep 14, 2025
8e66031
stream-helpers: Refactor tests to use @effectionx/deno-testing-bdd
Sep 14, 2025
e23ed54
signals: Refactor tests to use @effectionx/deno-testing-bdd
Sep 14, 2025
679f8f9
task-buffer: Refactor tests to use @effectionx/deno-testing-bdd
Sep 14, 2025
337051c
timebox: Refactor tests to use @effectionx/deno-testing-bdd
Sep 14, 2025
f97bc63
deno-testing-bdd: Add comprehensive README and version bump
Sep 14, 2025
b866982
Merge branch 'main' into tm/add-process
Sep 16, 2025
c17f700
Fix merge
Sep 16, 2025
e3b22e7
Add version to process
Sep 17, 2025
b9aabcb
Added license
Sep 17, 2025
553884f
Merge branch 'main' into tm/add-process
Sep 17, 2025
b8cd7ca
Rename package to @effectionx/bdd
Sep 17, 2025
420e388
Use @effectionx/bdd from npm
Sep 17, 2025
2cc4312
Switched everything to explicit dependencies
Sep 17, 2025
4bee7d2
Remove bad merge
Sep 18, 2025
810f489
Downgraded worker to v3 but with failure
Sep 18, 2025
05d5a4f
Refactored into separate files
Sep 18, 2025
11fe026
All worker tests are passing
Sep 18, 2025
7ebfe53
Removed unused import
Sep 18, 2025
86b929e
[context-api] Switched to effectionx/bdd
Sep 18, 2025
f6cdd38
[process] removed only
Sep 18, 2025
6df9547
[fx] refactored tests to use @effectionx/bdd
Sep 18, 2025
01696d4
[fx] removed dependency on external service in tests
Sep 18, 2025
9ae1bc6
[jsonl-store] Switched to @effectionx/bdd
Sep 18, 2025
f33ee4d
[jsonl-store] Removed reference to effection v4
Sep 18, 2025
b5b8519
[websocket] Downgraded to v3 and switched to @effectionx/bdd
Sep 18, 2025
1eae373
[stream-helpers] Bumped version of @effectionx/signals
Sep 18, 2025
4ac6b42
[watch] Switched to @effectionx/bdd
Sep 18, 2025
235db75
[raf] switched to @effectionx/bdd
Sep 18, 2025
d23a445
[timebox] removed unused @std/testing import
Sep 18, 2025
a605550
[stream-helpers] switched remaining test to @effectionx/bdd
Sep 18, 2025
803749f
[signals] Removed unused @std/testing
Sep 18, 2025
4568ca4
[process] refactor remaining tests to @effectionx/bdd
Sep 18, 2025
59f634c
[process] Removed unused @std/testing import
Sep 18, 2025
acb8396
Fix lint errors
Sep 19, 2025
1acbcce
Added license to bdd
Sep 19, 2025
d9162a9
Added windows and mac to verify
Sep 19, 2025
6417aaa
Change the batch test to be hopefully less flaky
Sep 19, 2025
e9a4060
Add .gitattributes to enforce LF line endings
Sep 19, 2025
77e9431
Refactored process outputs and crash on spawn fail
Sep 19, 2025
ae37f9e
Cleaned up formatting
Sep 19, 2025
2a66dcc
[process] Deleted unnecessary kill child process
Sep 19, 2025
e8124fc
WIP added some logs
Sep 19, 2025
6032f9e
Try isolate a failing test
Sep 19, 2025
329d12c
Try without helper
Sep 19, 2025
ad63931
more logs
Sep 19, 2025
2bed5da
Try logging on stderr
Sep 20, 2025
7efef03
Added pid to log output
Sep 20, 2025
cec301e
What happens if I sleep before terminating
Sep 20, 2025
d28ba51
Add more delay
Sep 20, 2025
c741b98
Add even more delay
Sep 20, 2025
f1f2e10
Try to resolve async instead
Sep 20, 2025
abc86d6
Run all tests
Sep 20, 2025
2c42561
Run process and watch tests
Sep 20, 2025
d044fd8
Allow --allow-ffi
Sep 20, 2025
11b89f8
Refactored to use Deno as echo-server instead of node
Sep 20, 2025
3d6a254
Include SystemRoom for window
Sep 20, 2025
c7cf90c
Added the delay to win32
Sep 20, 2025
6243e42
Process tests are passing on windows, linux & mac
Sep 20, 2025
4446b06
Added logs
Sep 21, 2025
99ffee2
Added more logs
Sep 21, 2025
f2aefce
Convert URL to filepath
Sep 21, 2025
694d5e1
Run all processes
Sep 21, 2025
9e24ae5
Added logs
Sep 21, 2025
af41d2d
Catch results
Sep 21, 2025
806b88a
Fix formatting
Sep 21, 2025
c13057c
Run tests on powershell and bash
Sep 21, 2025
6a932bb
Give request a minute to finish
taras Sep 25, 2025
865dca0
Remove the JS echo-server
taras Sep 28, 2025
ee7f279
Fix tests on PowerShell
taras Sep 28, 2025
02b0ccf
Fix platform-specific shell behavior in exec tests
taras Sep 28, 2025
5a624cd
Fixed formatting
Sep 28, 2025
4b7897c
Improve Windows shell detection and test reliability
taras Sep 28, 2025
14b379e
Fixed formatting
taras Sep 29, 2025
c0df99c
Adding env inline
taras Sep 29, 2025
0dfe784
Fix shell-specific environment variable setting in Windows workflow
taras Sep 29, 2025
6474cec
Use localhost instead of hostname in WebSocket test
taras Sep 29, 2025
5a7fb00
Fix request test to use localhost
taras Sep 29, 2025
4e23819
Replace echo with Node.js script for reliable cross-platform testing
taras Sep 29, 2025
61fd6db
Fixed formatting
taras Sep 29, 2025
b2119b3
fix(process): ensure exec tests pass on all platforms
taras Sep 29, 2025
9c2671a
fix(process): increase timeout in echo-server to fix race condition
taras Sep 30, 2025
f42e4ac
Using dump-args utility to eliminate ambguity introduced by different…
taras Sep 30, 2025
83c7fe0
fix(jsonl-store): ensure correct path handling on Windows
taras Sep 30, 2025
672dc3d
test(task-buffer): use FakeTime to make tests deterministic
taras Sep 30, 2025
fd9b35c
Fixed fmting
taras Sep 30, 2025
e56e2e1
Fixed lint
taras Sep 30, 2025
f79093d
Deleted flaky test and make batch less flaky (i hope)
taras Sep 30, 2025
499e10a
Fixed one watch test and commented out the other
taras Oct 1, 2025
88e1558
Fix formatting
taras Oct 1, 2025
7be4ce1
Remove only from test
taras Oct 7, 2025
e57fc19
All tests passing on windows bash
taras Oct 7, 2025
6d76029
Added graceful shutdown test
taras Oct 7, 2025
cb5b0b0
Added graceful shutdown test
Oct 7, 2025
64ff743
All watch tests are passing on win32
taras Oct 7, 2025
d8966d1
Merge branch 'main' into tm/add-process
Oct 7, 2025
a17ad2c
Merge branch 'tm/add-process' of github.com:thefrontside/effectionx i…
Oct 7, 2025
0e4f930
Fixed fmt and lint errors
Oct 7, 2025
36f99d6
Try removing stdinStream.end() out because streams are already closing
taras Oct 7, 2025
4dc9014
Merge branch 'tm/add-process' of https://github.com/thefrontside/effe…
taras Oct 7, 2025
484b7e6
Trace leaks
taras Oct 7, 2025
1d395ba
Try waiting for process to finish
taras Oct 7, 2025
6d8d36c
Try waiting for process to finish
taras Oct 7, 2025
b69a306
Merge branch 'tm/add-process' of https://github.com/thefrontside/effe…
taras Oct 7, 2025
9e596df
Removed unusd race
taras Oct 7, 2025
7bfd643
Removed unecessary graceful shutdown test because it's covered in oth…
taras Oct 7, 2025
f3d6839
Close stdint again
taras Oct 7, 2025
fabd2e0
Remove stdoutDone and stderrDone when streams complete
taras Oct 7, 2025
0fbe77a
Close stdout and stderr stream after finish iterating it
Oct 7, 2025
d5a2d23
Check that streams are closed after close event
taras Oct 7, 2025
ec4eed2
Wait for stdout and stderr to drain on posix too
taras Oct 7, 2025
3fcd7ce
No longer wait for streams to become readable
taras Oct 7, 2025
7c83a75
Ignore stderr for exist status in windows
taras Oct 7, 2025
0d20921
Try not killing the proces when it was killed
taras Oct 7, 2025
111fc6c
Try to wait for process to close
taras Oct 7, 2025
a084af8
Log status of last command
taras Oct 7, 2025
64f481b
Continue on error
taras Oct 7, 2025
326966d
Only run bash and cmd shells on windows
taras Oct 7, 2025
08030f4
Try ungraceful teardown win32 when all else fails
taras Oct 7, 2025
be0710a
trace leaks
taras Oct 7, 2025
09e0ef1
Try all tests
taras Oct 7, 2025
a53ea00
Revert "Try all tests"
taras Oct 7, 2025
9adb83d
Downgrade 8 packages to unpublished versions
Oct 17, 2025
32a8f7c
Update dependencies for downgraded packages
Oct 17, 2025
0be432a
Replace path dependencies with JSR and fix bdd version references
Oct 17, 2025
7b79069
Renamed downgraded dependencies analysis file
Oct 17, 2025
d8ff4aa
Fix missing version constraint in @ts-types directive
Oct 17, 2025
01ec8b8
Try shutdown
Oct 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Ensure consistent line endings
* text=auto eol=lf

# Binary files
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.ico binary
*.woff binary
*.woff2 binary
*.ttf binary
*.otf binary
*.eot binary
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
name: Verify
name: Verify (POSIX)

on:
push:
branches: main
branches:
- main
pull_request:
branches: main
branches:
- main

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}

steps:
- name: checkout
Expand All @@ -21,7 +26,6 @@ jobs:
uses: denoland/setup-deno@v2
with:
deno-version: v2.x

- name: reload dependencies
run: deno cache --reload **/mod.ts

Expand All @@ -31,4 +35,4 @@ jobs:

- run: deno lint

- run: deno test --allow-net --allow-read --allow-write --allow-env --allow-run
- run: deno test --allow-net --allow-read --allow-write --allow-env --allow-run --allow-ffi
60 changes: 60 additions & 0 deletions .github/workflows/verify-windows.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Verify (Windows)

on:
push:
branches:
- main
pull_request:
branches:
- main

permissions:
contents: read

jobs:
test:
runs-on: windows-latest
strategy:
matrix:
shell:
# tests pass in all shells, but in powershell and pwsh, they `echo $?` as false
# this causes tests to fail in CI. We'll need to run only bash and cmd until
# we figure this out.
# - powershell
# - pwsh
- bash
- cmd
defaults:
run:
shell: ${{matrix.shell}}

steps:
- name: checkout
uses: actions/checkout@v4

- name: setup deno
uses: denoland/setup-deno@v2
with:
deno-version: v2.x

- run: deno fmt --check

- run: deno lint

- name: "Test (${{matrix.shell}})"
if: matrix.shell == 'powershell' || matrix.shell == 'pwsh'
run: |
$env:SHELL = "${{matrix.shell}}"
deno test --allow-net --allow-read --allow-write --allow-env --allow-run --allow-ffi --trace-leaks

- name: "Test (${{matrix.shell}})"
if: matrix.shell == 'cmd'
run: |
set SHELL=${{matrix.shell}}
deno test --allow-net --allow-read --allow-write --allow-env --allow-run --allow-ffi --trace-leaks

- name: "Test (${{matrix.shell}})"
if: matrix.shell == 'bash'
run: |
export SHELL=${{matrix.shell}}
deno test --allow-net --allow-read --allow-write --allow-env --allow-run --allow-ffi --trace-leaks
2 changes: 2 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Always check syntax after making code changes. Always run `deno fmt` and
`deno lint` before commiting.
2 changes: 1 addition & 1 deletion bdd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Add to your `deno.json` imports:
```json
{
"imports": {
"@effectionx/bdd": "npm:@effectionx/bdd"
"@effectionx/bdd": "jsr:@effectionx/bdd"
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion bdd/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "MIT",
"imports": {
"effection": "npm:effection@^3",
"@effectionx/test-adapter": "npm:@effectionx/test-adapter@^0.5.1",
"@effectionx/test-adapter": "jsr:@effectionx/test-adapter@^0.1.0",
"@std/testing": "jsr:@std/testing@^1"
}
}
123 changes: 52 additions & 71 deletions context-api/context-api.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { describe, it } from "bdd";
import { expect } from "@std/expect";
import { type Operation, run, scoped } from "effection";
import { type Operation, scoped } from "effection";
import { describe, it } from "@effectionx/bdd";
import { createApi } from "@effectionx/context-api";

describe("context api", () => {
it("can invoke a handler from anywhere", async () => {
it("can invoke a handler from anywhere", function* () {
let { one, two } = createApi("numbers", {
*one() {
return 1;
Expand All @@ -14,27 +14,22 @@ describe("context api", () => {
},
}).operations;

await run(function* () {
expect(yield* one()).toEqual(1);
expect(yield* two()).toEqual(2);
});
expect(yield* one()).toEqual(1);
expect(yield* two()).toEqual(2);
});

it("can have handlers that are not functions", async () => {
it("can have handlers that are not functions", function* () {
let { one } = createApi("one", {
one: {
*[Symbol.iterator]() {
return 1;
},
},
}).operations;

await run(function* () {
expect(yield* one).toEqual(1);
});
expect(yield* one).toEqual(1);
});

it("can add middleware around operations and operation functions", async () => {
it("can add middleware around operations and operation functions", function* () {
let numbers = createApi("numbers", {
one: {
*[Symbol.iterator]() {
Expand All @@ -47,105 +42,91 @@ describe("context api", () => {
});

let { one, two } = numbers.operations;
yield* numbers.around({
*one(args, next) {
return (yield* next(...args)) * 2;
},
*two(args, next) {
return (yield* next(...args)) * 2;
},
});

await run(function* () {
yield* numbers.around({
*one(args, next) {
return (yield* next(...args)) * 2;
},
*two(args, next) {
return (yield* next(...args)) * 2;
},
});
expect(yield* one).toEqual(2);
expect(yield* two()).toEqual(4);
});

expect(yield* one).toEqual(2);
expect(yield* two()).toEqual(4);
it("passes arguments to an operation", function* () {
const math = createApi("math", {
*add(left: number, right: number): Operation<number> {
return left + right;
},
});

const { add } = math.operations;
expect(yield* add(1, 1)).toEqual(2);
});

it("passes arguments to an operation", async () => {
it("can modify arguments to operations with middleware", function* () {
const math = createApi("math", {
*add(left: number, right: number): Operation<number> {
return left + right;
},
});

const { add } = math.operations;

await run(function* () {
expect(yield* add(1, 1)).toEqual(2);
yield* math.around({
*add([left, right], next) {
return yield* next(left + 1, right + 1);
},
});

expect(yield* add(1, 1)).toEqual(4);
});

it("can modify arguments to operations with middleware", async () => {
it("treats the middleware contextually", function* () {
const math = createApi("math", {
*add(left: number, right: number): Operation<number> {
return left + right;
},
});

const { add } = math.operations;

await run(function* () {
yield* scoped(function* () {
yield* math.around({
*add([left, right], next) {
return yield* next(left + 1, right + 1);
},
});

expect(yield* add(1, 1)).toEqual(4);
});

expect(yield* add(1, 1)).toEqual(2);
});

it("treats the middleware contextually", async () => {
it("chains multiple middleware", function* () {
const math = createApi("math", {
*add(left: number, right: number): Operation<number> {
return left + right;
},
});
const { add } = math.operations;

await run(function* () {
yield* scoped(function* () {
yield* math.around({
*add([left, right], next) {
return yield* next(left + 1, right + 1);
},
});
expect(yield* add(1, 1)).toEqual(4);
});

expect(yield* add(1, 1)).toEqual(2);
yield* math.around({
*add([left, right], next) {
return 10 + (yield* next(left, right));
},
});
});

it("chains multiple middleware", async () => {
const math = createApi("math", {
*add(left: number, right: number): Operation<number> {
return left + right;
yield* math.around({
*add([left, right], next) {
return 100 + (yield* next(left, right));
},
});

await run(function* () {
yield* math.around({
*add([left, right], next) {
return 10 + (yield* next(left, right));
},
});

yield* math.around({
*add([left, right], next) {
return 100 + (yield* next(left, right));
},
});

yield* math.around({
*add([left, right], next) {
return 20 + (yield* next(left, right));
},
});

expect(yield* math.operations.add(5, 15)).toEqual(150);
yield* math.around({
*add([left, right], next) {
return 20 + (yield* next(left, right));
},
});

expect(yield* math.operations.add(5, 15)).toEqual(150);
});
});
3 changes: 2 additions & 1 deletion context-api/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"exports": "./mod.ts",
"imports": {
"effection": "npm:effection@^3",
"@std/expect": "jsr:@std/expect"
"@std/expect": "jsr:@std/expect@^1",
"@effectionx/bdd": "jsr:@effectionx/bdd@0.2.2"
}
}
5 changes: 2 additions & 3 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"imports": {
"bdd": "jsr:@std/testing@1/bdd",
"expect": "jsr:@std/expect@1",
"effection": "npm:effection@^3",
"@deno/dnt": "jsr:@deno/dnt@0.42.3",
"@std/path": "jsr:@std/path@^1",
Expand Down Expand Up @@ -39,6 +37,7 @@
"./websocket",
"./worker",
"./stream-helpers",
"./signals"
"./signals",
"./process"
]
}
Loading