Skip to content

Commit

Permalink
Change tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lxsmnsyc committed Jan 7, 2025
1 parent beb143f commit 38558a2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
16 changes: 8 additions & 8 deletions packages/seroval/test/__snapshots__/abort-signal.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,56 +10,56 @@ exports[`AbortSignal > crossSerialize > supports future AbortSignal 1`] = `"$R[0

exports[`AbortSignal > crossSerializeAsync > scoped > supports aborted AbortSignal 1`] = `"($R=>$R[0]=Promise.resolve($R[1]=AbortSignal.abort("aborted!")))($R["example"])"`;

exports[`AbortSignal > crossSerializeAsync > scoped > supports future AbortSignal 1`] = `"($R=>$R[0]=AbortSignal.abort($R[1]=Object.assign(new Error("The operation was aborted due to timeout"),{name:"TimeoutError",stack:"TimeoutError: The operation was aborted due to timeout\\n at new DOMException (node:internal/per_context/domexception:53:5)\\n at Timeout._onTimeout (node:internal/abort_controller:130:9)\\n at listOnTimeout (node:internal/timers:573:17)\\n at processTimers (node:internal/timers:514:7)"})))($R["example"])"`;
exports[`AbortSignal > crossSerializeAsync > scoped > supports future AbortSignal 1`] = `"($R=>$R[0]=AbortSignal.abort("aborted!"))($R["example"])"`;

exports[`AbortSignal > crossSerializeAsync > supports aborted AbortSignal 1`] = `"$R[0]=Promise.resolve($R[1]=AbortSignal.abort("aborted!"))"`;

exports[`AbortSignal > crossSerializeAsync > supports future AbortSignal 1`] = `"$R[0]=AbortSignal.abort($R[1]=Object.assign(new Error("The operation was aborted due to timeout"),{name:"TimeoutError",stack:"TimeoutError: The operation was aborted due to timeout\\n at new DOMException (node:internal/per_context/domexception:53:5)\\n at Timeout._onTimeout (node:internal/abort_controller:130:9)\\n at listOnTimeout (node:internal/timers:573:17)\\n at processTimers (node:internal/timers:514:7)"}))"`;
exports[`AbortSignal > crossSerializeAsync > supports future AbortSignal 1`] = `"$R[0]=AbortSignal.abort("aborted!")"`;

exports[`AbortSignal > crossSerializeStream > scoped > supports aborted AbortSignal 1`] = `"($R=>$R[0]=($R[1]=(s,f,p)=>((p=new Promise((a,b)=>{s=a,f=b})).s=s,p.f=f,p))())($R["example"])"`;

exports[`AbortSignal > crossSerializeStream > scoped > supports aborted AbortSignal 2`] = `"($R=>($R[3]=(p,d)=>{p.s(d),p.status="success",p.value=d;delete p.s;delete p.f})($R[0],$R[2]=AbortSignal.abort("aborted!")))($R["example"])"`;

exports[`AbortSignal > crossSerializeStream > scoped > supports future AbortSignal 1`] = `"($R=>$R[0]=($R[1]=(a,s)=>((s=(a=new AbortController).signal).a=a,s))())($R["example"])"`;

exports[`AbortSignal > crossSerializeStream > scoped > supports future AbortSignal 2`] = `"($R=>($R[3]=(s,r)=>{s.a.abort(r);delete s.a})($R[0],$R[2]=Object.assign(new Error("The operation was aborted due to timeout"),{name:"TimeoutError",stack:"TimeoutError: The operation was aborted due to timeout\\n at new DOMException (node:internal/per_context/domexception:53:5)\\n at Timeout._onTimeout (node:internal/abort_controller:130:9)\\n at listOnTimeout (node:internal/timers:573:17)\\n at processTimers (node:internal/timers:514:7)"})))($R["example"])"`;
exports[`AbortSignal > crossSerializeStream > scoped > supports future AbortSignal 2`] = `"($R=>($R[2]=(s,r)=>{s.a.abort(r);delete s.a})($R[0],"aborted!"))($R["example"])"`;

exports[`AbortSignal > crossSerializeStream > supports aborted AbortSignal 1`] = `"$R[0]=($R[1]=(s,f,p)=>((p=new Promise((a,b)=>{s=a,f=b})).s=s,p.f=f,p))()"`;

exports[`AbortSignal > crossSerializeStream > supports aborted AbortSignal 2`] = `"($R[3]=(p,d)=>{p.s(d),p.status="success",p.value=d;delete p.s;delete p.f})($R[0],$R[2]=AbortSignal.abort("aborted!"))"`;

exports[`AbortSignal > crossSerializeStream > supports future AbortSignal 1`] = `"$R[0]=($R[1]=(a,s)=>((s=(a=new AbortController).signal).a=a,s))()"`;

exports[`AbortSignal > crossSerializeStream > supports future AbortSignal 2`] = `"($R[3]=(s,r)=>{s.a.abort(r);delete s.a})($R[0],$R[2]=Object.assign(new Error("The operation was aborted due to timeout"),{name:"TimeoutError",stack:"TimeoutError: The operation was aborted due to timeout\\n at new DOMException (node:internal/per_context/domexception:53:5)\\n at Timeout._onTimeout (node:internal/abort_controller:130:9)\\n at listOnTimeout (node:internal/timers:573:17)\\n at processTimers (node:internal/timers:514:7)"}))"`;
exports[`AbortSignal > crossSerializeStream > supports future AbortSignal 2`] = `"($R[2]=(s,r)=>{s.a.abort(r);delete s.a})($R[0],"aborted!")"`;

exports[`AbortSignal > serialize > supports aborted AbortSignal 1`] = `"AbortSignal.abort("aborted!")"`;

exports[`AbortSignal > serialize > supports future AbortSignal 1`] = `"(h=>((a,s)=>((s=(a=new AbortController).signal).a=a,s))())()"`;

exports[`AbortSignal > serializeAsync > supports aborted AbortSignal 1`] = `"Promise.resolve(AbortSignal.abort("aborted!"))"`;

exports[`AbortSignal > serializeAsync > supports future AbortSignal 1`] = `"AbortSignal.abort(Object.assign(new Error("The operation was aborted due to timeout"),{name:"TimeoutError",stack:"TimeoutError: The operation was aborted due to timeout\\n at new DOMException (node:internal/per_context/domexception:53:5)\\n at Timeout._onTimeout (node:internal/abort_controller:130:9)\\n at listOnTimeout (node:internal/timers:573:17)\\n at processTimers (node:internal/timers:514:7)"}))"`;
exports[`AbortSignal > serializeAsync > supports future AbortSignal 1`] = `"AbortSignal.abort("aborted!")"`;

exports[`AbortSignal > toCrossJSON > supports aborted AbortSignal 1`] = `"{"t":37,"i":0,"f":{"t":1,"s":"aborted!"}}"`;

exports[`AbortSignal > toCrossJSON > supports future AbortSignal 1`] = `"{"t":35,"i":0,"f":{"t":26,"i":1,"s":5}}"`;

exports[`AbortSignal > toCrossJSONAsync > supports aborted AbortSignal 1`] = `"{"t":12,"i":0,"s":1,"f":{"t":37,"i":1,"f":{"t":1,"s":"aborted!"}}}"`;

exports[`AbortSignal > toCrossJSONAsync > supports future AbortSignal 1`] = `"{"t":37,"i":0,"f":{"t":13,"i":1,"s":0,"m":"The operation was aborted due to timeout","p":{"k":["name","stack"],"v":[{"t":1,"s":"TimeoutError"},{"t":1,"s":"TimeoutError: The operation was aborted due to timeout\\\\n at new DOMException (node:internal/per_context/domexception:53:5)\\\\n at Timeout._onTimeout (node:internal/abort_controller:130:9)\\\\n at listOnTimeout (node:internal/timers:573:17)\\\\n at processTimers (node:internal/timers:514:7)"}],"s":2}}}"`;
exports[`AbortSignal > toCrossJSONAsync > supports future AbortSignal 1`] = `"{"t":37,"i":0,"f":{"t":1,"s":"aborted!"}}"`;

exports[`AbortSignal > toCrossJSONStream > supports aborted AbortSignal 1`] = `"{"t":22,"i":0,"f":{"t":26,"i":1,"s":1}}"`;

exports[`AbortSignal > toCrossJSONStream > supports aborted AbortSignal 2`] = `"{"t":23,"i":0,"a":[{"t":26,"i":3,"s":2},{"t":37,"i":2,"f":{"t":1,"s":"aborted!"}}]}"`;

exports[`AbortSignal > toCrossJSONStream > supports future AbortSignal 1`] = `"{"t":35,"i":0,"f":{"t":26,"i":1,"s":5}}"`;

exports[`AbortSignal > toCrossJSONStream > supports future AbortSignal 2`] = `"{"t":36,"i":0,"a":[{"t":26,"i":3,"s":6},{"t":13,"i":2,"s":0,"m":"The operation was aborted due to timeout","p":{"k":["name","stack"],"v":[{"t":1,"s":"TimeoutError"},{"t":1,"s":"TimeoutError: The operation was aborted due to timeout\\\\n at new DOMException (node:internal/per_context/domexception:53:5)\\\\n at Timeout._onTimeout (node:internal/abort_controller:130:9)\\\\n at listOnTimeout (node:internal/timers:573:17)\\\\n at processTimers (node:internal/timers:514:7)"}],"s":2}}]}"`;
exports[`AbortSignal > toCrossJSONStream > supports future AbortSignal 2`] = `"{"t":36,"i":0,"a":[{"t":26,"i":2,"s":6},{"t":1,"s":"aborted!"}]}"`;

exports[`AbortSignal > toJSON > supports aborted AbortSignal 1`] = `"{"t":{"t":37,"i":0,"f":{"t":1,"s":"aborted!"}},"f":47,"m":[]}"`;

exports[`AbortSignal > toJSON > supports future AbortSignal 1`] = `"{"t":{"t":35,"i":0,"f":{"t":26,"i":1,"s":5}},"f":47,"m":[]}"`;

exports[`AbortSignal > toJSONAsync > supports aborted AbortSignal 1`] = `"{"t":{"t":12,"i":0,"s":1,"f":{"t":37,"i":1,"f":{"t":1,"s":"aborted!"}}},"f":47,"m":[]}"`;

exports[`AbortSignal > toJSONAsync > supports future AbortSignal 1`] = `"{"t":{"t":37,"i":0,"f":{"t":13,"i":1,"s":0,"m":"The operation was aborted due to timeout","p":{"k":["name","stack"],"v":[{"t":1,"s":"TimeoutError"},{"t":1,"s":"TimeoutError: The operation was aborted due to timeout\\\\n at new DOMException (node:internal/per_context/domexception:53:5)\\\\n at Timeout._onTimeout (node:internal/abort_controller:130:9)\\\\n at listOnTimeout (node:internal/timers:573:17)\\\\n at processTimers (node:internal/timers:514:7)"}],"s":2}}},"f":47,"m":[]}"`;
exports[`AbortSignal > toJSONAsync > supports future AbortSignal 1`] = `"{"t":{"t":37,"i":0,"f":{"t":1,"s":"aborted!"}},"f":47,"m":[]}"`;
34 changes: 21 additions & 13 deletions packages/seroval/test/abort-signal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ import {
toJSONAsync,
} from '../src';

const delayedAbortSignal = () => {
const controller = new AbortController();
setTimeout(() => {
controller.abort('aborted!');
}, 100);
return controller.signal;
};

const SYNC_EXAMPLE = AbortSignal.abort('aborted!');

describe('AbortSignal', () => {
Expand All @@ -27,7 +35,7 @@ describe('AbortSignal', () => {
expect(back.reason).toBe(SYNC_EXAMPLE.reason);
});
it('supports future AbortSignal', () => {
const instance = AbortSignal.timeout(100);
const instance = delayedAbortSignal();
const result = serialize(instance);
expect(result).toMatchSnapshot();
const back = deserialize<typeof instance>(result);
Expand All @@ -43,7 +51,7 @@ describe('AbortSignal', () => {
expect(back.reason).toBe(SYNC_EXAMPLE.reason);
});
it('supports future AbortSignal', async () => {
const instance = AbortSignal.timeout(100);
const instance = delayedAbortSignal();
const result = await serializeAsync(instance);
expect(result).toMatchSnapshot();
const back = await deserialize<Promise<typeof instance>>(result);
Expand All @@ -59,7 +67,7 @@ describe('AbortSignal', () => {
expect(back.reason).toBe(SYNC_EXAMPLE.reason);
});
it('supports future AbortSignal', () => {
const instance = AbortSignal.timeout(100);
const instance = delayedAbortSignal();
const result = toJSON(instance);
expect(JSON.stringify(result)).toMatchSnapshot();
const back = fromJSON<typeof instance>(result);
Expand All @@ -75,7 +83,7 @@ describe('AbortSignal', () => {
expect(back.reason).toBe(SYNC_EXAMPLE.reason);
});
it('supports future AbortSignal', async () => {
const instance = AbortSignal.timeout(100);
const instance = delayedAbortSignal();
const result = await toJSONAsync(instance);
expect(JSON.stringify(result)).toMatchSnapshot();
const back = fromJSON<typeof instance>(result);
Expand All @@ -89,7 +97,7 @@ describe('AbortSignal', () => {
expect(result).toMatchSnapshot();
});
it('supports future AbortSignal', () => {
const instance = AbortSignal.timeout(100);
const instance = delayedAbortSignal();
const result = crossSerialize(instance);
expect(result).toMatchSnapshot();
});
Expand All @@ -99,7 +107,7 @@ describe('AbortSignal', () => {
expect(result).toMatchSnapshot();
});
it('supports future AbortSignal', () => {
const instance = AbortSignal.timeout(100);
const instance = delayedAbortSignal();
const result = crossSerialize(instance, { scopeId: 'example' });
expect(result).toMatchSnapshot();
});
Expand All @@ -111,7 +119,7 @@ describe('AbortSignal', () => {
expect(result).toMatchSnapshot();
});
it('supports future AbortSignal', async () => {
const instance = AbortSignal.timeout(100);
const instance = delayedAbortSignal();
const result = await crossSerializeAsync(instance);
expect(result).toMatchSnapshot();
});
Expand All @@ -126,7 +134,7 @@ describe('AbortSignal', () => {
expect(result).toMatchSnapshot();
});
it('supports future AbortSignal', async () => {
const instance = AbortSignal.timeout(100);
const instance = delayedAbortSignal();
const result = await crossSerializeAsync(instance, {
scopeId: 'example',
});
Expand All @@ -151,7 +159,7 @@ describe('AbortSignal', () => {
}));
it('supports future AbortSignal', async () =>
new Promise<void>((resolve, reject) => {
const instance = AbortSignal.timeout(100);
const instance = delayedAbortSignal();
crossSerializeStream(instance, {
onSerialize(data) {
expect(data).toMatchSnapshot();
Expand Down Expand Up @@ -182,7 +190,7 @@ describe('AbortSignal', () => {
}));
it('supports future AbortSignal', async () =>
new Promise<void>((resolve, reject) => {
const instance = AbortSignal.timeout(100);
const instance = delayedAbortSignal();
crossSerializeStream(instance, {
scopeId: 'example',
onSerialize(data) {
Expand All @@ -209,7 +217,7 @@ describe('AbortSignal', () => {
expect(back.reason).toBe(SYNC_EXAMPLE.reason);
});
it('supports future AbortSignal', () => {
const instance = AbortSignal.timeout(100);
const instance = delayedAbortSignal();
const result = toCrossJSON(instance);
expect(JSON.stringify(result)).toMatchSnapshot();
const back = fromCrossJSON<typeof instance>(result, {
Expand All @@ -229,7 +237,7 @@ describe('AbortSignal', () => {
expect(back.reason).toBe(SYNC_EXAMPLE.reason);
});
it('supports future AbortSignal', async () => {
const instance = AbortSignal.timeout(100);
const instance = delayedAbortSignal();
const result = await toCrossJSONAsync(instance);
expect(JSON.stringify(result)).toMatchSnapshot();
const back = fromCrossJSON<typeof SYNC_EXAMPLE>(result, {
Expand All @@ -255,7 +263,7 @@ describe('AbortSignal', () => {
}));
it('supports future AbortSignal', async () =>
new Promise<void>((resolve, reject) => {
const instance = AbortSignal.timeout(100);
const instance = delayedAbortSignal();
toCrossJSONStream(instance, {
onParse(data) {
expect(JSON.stringify(data)).toMatchSnapshot();
Expand Down

0 comments on commit 38558a2

Please sign in to comment.