Skip to content

Commit

Permalink
Fix unawaited promises
Browse files Browse the repository at this point in the history
Change-type: patch
  • Loading branch information
thgreasi committed Nov 8, 2023
1 parent 32fea29 commit eb155bd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
32 changes: 17 additions & 15 deletions lib/build/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,21 +174,23 @@ export default class Builder {
return await Promise.all([relPath, fs.stat(file), fs.readFile(file)]);
}),
);
await fileInfos.map(async (fileInfo: [string, fs.Stats, Buffer]) => {
await new Promise<void>((resolve, reject) =>
pack.entry(
{ name: fileInfo[0], size: fileInfo[1].size },
fileInfo[2],
(err) => {
if (err) {
reject(err);
} else {
resolve();
}
},
),
);
});
await Promise.all(
fileInfos.map(async (fileInfo) => {
await new Promise<void>((resolve, reject) =>
pack.entry(
{ name: fileInfo[0], size: fileInfo[1].size },
fileInfo[2],
(err) => {
if (err) {
reject(err);
} else {
resolve();
}
},
),
);
}),
);
// Tell the tar stream we're done
pack.finalize();
// Create a build stream to send the data to
Expand Down
4 changes: 2 additions & 2 deletions test/multibuild/stream.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ describe('Stream splitting', () => {
});

describe('Specifying a Dockerfile', () => {
it('should throw an error when a build object does not contain a context and dockerfile', (done) => {
it('should throw an error when a build object does not contain a context and dockerfile', async (done) => {
const composeObj = require('./test-files/stream/docker-compose-specified-dockerfile-no-context.json');
const comp = Compose.normalize(composeObj);

const stream = fs.createReadStream(
`${TEST_FILES_PATH}/stream/specified-dockerfile.tar`,
);

Promise.resolve(
await Promise.resolve(
splitBuildStream(comp, stream),
).should.be.rejected.and.notify(done);
});
Expand Down

0 comments on commit eb155bd

Please sign in to comment.