Skip to content

Commit

Permalink
fix(sandbox): do not return empty object result when it is undefined (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf authored Oct 26, 2023
1 parent b026a3a commit 308db7f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/classes/child-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ export class ChildProcessor {
this.currentJobPromise = (async () => {
try {
const job = this.wrapJob(jobJson, this.send);
const result = (await this.processor(job, token)) || {};
const result = await this.processor(job, token);
await this.send({
cmd: ParentCommand.Completed,
value: result,
value: typeof result === 'undefined' ? null : result,
});
} catch (err) {
await this.send({
Expand Down
4 changes: 3 additions & 1 deletion tests/test_sandboxed_process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function sandboxProcessTests(
const completing = new Promise<void>((resolve, reject) => {
worker.on('completed', async (job: Job, value: any) => {
try {
expect(job.returnvalue).to.be.eql(42);
expect(job.data).to.be.eql({ foo: 'bar' });
expect(value).to.be.eql(42);
expect(Object.keys(worker['childPool'].retained)).to.have.lengthOf(
Expand Down Expand Up @@ -770,8 +771,9 @@ function sandboxProcessTests(
});

const completing = new Promise<void>((resolve, reject) => {
worker.on('completed', async () => {
worker.on('completed', async job => {
try {
expect(job.returnvalue).to.be.undefined;
expect(Object.keys(worker['childPool'].retained)).to.have.lengthOf(
0,
);
Expand Down

0 comments on commit 308db7f

Please sign in to comment.