Skip to content

Commit

Permalink
fix test: Wait for resources to be properly released
Browse files Browse the repository at this point in the history
  • Loading branch information
segayuu committed Oct 8, 2018
1 parent 3d0f4f7 commit 234b049
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,8 @@ describe('fs', () => {
stream.path.should.eql(target);

const streamPromise = new Promise((resolve, reject) => {
stream.on('finish', resolve).on('error', reject);
stream.on('error', reject);
stream.on('close', resolve);
});

stream.end();
Expand All @@ -997,26 +998,27 @@ describe('fs', () => {

fs.ensureWriteStream(target, tiferr(callback, stream => {
stream.path.should.eql(target);

stream.on('error', callback);
stream.on('finish', () => {
stream.on('close', () => {
fs.unlink(target, callback);
});

stream.end();
}));
});

it('ensureWriteStreamSync()', () => {
it('ensureWriteStreamSync()', callback => {
const target = pathFn.join(tmpDir, 'foo', 'bar.txt');
const stream = fs.ensureWriteStreamSync(target);

stream.path.should.eql(target);

const streamPromise = new Promise((resolve, reject) => {
stream.on('finish', resolve).on('error', reject);
stream.on('error', callback);
stream.on('close', () => {
fs.rmdir(pathFn.dirname(target), callback);
});

stream.end();
return streamPromise.then(() => fs.rmdir(pathFn.dirname(target)));
});
});

0 comments on commit 234b049

Please sign in to comment.