Skip to content

Commit 115d734

Browse files
committed
test: fix flaky change stream test
1 parent 7c23641 commit 115d734

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

test/functional/change_stream.test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,20 +1601,21 @@ describe('Change Streams', function() {
16011601
const collection = database.collection('MongoNetworkErrorTestPromises');
16021602
const changeStream = collection.watch(pipeline);
16031603

1604-
const outStream = fs.createWriteStream(filename);
1604+
const outStream = fs.createWriteStream(filename, { flags: 'w' });
16051605
this.defer(() => outStream.close());
16061606

1607-
changeStream.stream({ transform: JSON.stringify }).pipe(outStream);
1607+
changeStream
1608+
.stream({ transform: change => JSON.stringify(change) + '\n' })
1609+
.pipe(outStream);
16081610
this.defer(() => changeStream.close());
16091611
// Listen for changes to the file
16101612
const watcher = fs.watch(filename, eventType => {
16111613
this.defer(() => watcher.close());
16121614
expect(eventType).to.equal('change');
16131615

16141616
const fileContents = fs.readFileSync(filename, 'utf8');
1615-
const parsedFileContents = JSON.parse(fileContents);
1617+
const parsedFileContents = JSON.parse(fileContents.split(/\n/)[0]);
16161618
expect(parsedFileContents).to.have.nested.property('fullDocument.a', 1);
1617-
16181619
done();
16191620
});
16201621
});

0 commit comments

Comments
 (0)