UNPKG

@debonet/es6pacts

Version:

Releasable/cancellable and Reporting Promises for Javascript ES6

63 lines (48 loc) 3.43 kB
# es6pacts — v2 Test-Suite Continuity (v3-v2compat) ## TL;DR * The single v2 test from `/Users/jsd/@aios/tmp/v2ref/es6pacts/test/es6pacts.test.js` PORTs into `test/v2compat.test.js` with the constructor edit only; its expected progress string `"0, 0.01, 0.02, "` SURVIVES under the microtask/observer model (ruling below). * The no-jest polyfill shim is DROPPED (jest is the declared runner per `specs/v3-composition.md`). * The existing expanded v3 suite in `test/es6pacts.test.js` is untouched; this file is ADDITIVE. ## Purpose Prove v2 behavioral continuity for the composition by porting its one v2 test with minimum modification. ## Disposition | # | v2 test | Disposition | Modification | |---|---------|-------------|--------------| | 1 | simple resolve | PORT | helper constructor edit only (below); test body verbatim | | — | no-jest shim (`global.test` / `expect` polyfill) | DROP | dead weight under the declared jest runner; `specs/v3-composition.md` (Build and Test) already drops shims | Helper port (two-arg constructor → executor-returned cleanup; `timeout` moves into executor scope): ```javascript function fpPactDelay( dtm, dtmReport = 100 ){ return new Pact(( fResolve, fReject, fReport ) => { let timeout; let dtmSlept = 0; let f = () => { let r = dtm > 0 ? dtmSlept / dtm : 0; fReport( r ); if ( dtmSlept < ( dtm - dtmReport )){ dtmSlept += dtmReport; timeout = setTimeout( f, dtmReport ); } else if ( dtmSlept < dtm ){ timeout = setTimeout( f, dtm - dtmSlept ); dtmSlept = dtm; } else{ fResolve( dtm ); } } f(); return () => clearTimeout( timeout ); }); } ``` ## Ruling: the expected string "0, 0.01, 0.02, " under the observer model The v2 expectation depends on three timing facts; each survives, so this is a PORT, not an ADAPT: * **The synchronous first report (`0`).** `fReport( 0 )` fires during construction, before `.progress` attaches. v2 delivered it via the replay buffer. v3 has no replay, but delivery is a microtask and the observer list is read at DELIVERY time (`../es6tasks/specs/v3-reporting.md`, Delivery) — `.progress` attaches in the same synchronous expression, so the observer receives `0`. Same output, different mechanism. * **No transformer replay needed.** The v2 test attaches exactly one observer in the construction tick; nothing relied on the deleted transformer chain. * **The 300ms boundary.** `p1.resolve( "faster" )` is scheduled at t=0 for 300ms; the third tick's timer (which would report `0.03`) is scheduled at ~200ms for 300ms. The release timer was registered first and fires first; the release pipeline runs the cleanup (`clearTimeout`) before dispatch settles the pact, and post-settle suppression backstops any straggler. Same race resolution as v2; `0.03` never appears. Note: `p1` here IS the source (`.progress` returns `this`), so `p1.resolve( "faster" )` is a source release — no cancel-at-source adaptation is needed. `await p1` yields `"faster"` via dispatch. ## Build and Test * File: `/Users/jsd/@aios/tmp/es6pacts/test/v2compat.test.js` (new; 1 test), header comment citing the v2 source for provenance. Runner: jest `^29`, `npm test`. * Depends on `@debonet/es6pledges ^3.0.0` and `@debonet/es6tasks ^3.0.0` (version-family alignment; see `specs/v3-composition.md`). * The existing v3 suite (`test/es6pacts.test.js`) is untouched and must stay green alongside this file.