3 more passing tests. yaayy

This commit is contained in:
snwy
2024-11-07 16:08:04 -08:00
parent 5bcd6bb18a
commit bb07e4a18c
3 changed files with 117 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
'use strict';
const common = require('../common');
const { Duplex } = require('stream');
const assert = require('assert');
{
const duplex = new Duplex({
readable: false
});
assert.strictEqual(duplex.readable, false);
duplex.push('asd');
duplex.on('error', common.mustCall((err) => {
assert.strictEqual(err.code, 'ERR_STREAM_PUSH_AFTER_EOF');
}));
duplex.on('data', common.mustNotCall());
duplex.on('end', common.mustNotCall());
}
{
const duplex = new Duplex({
writable: false,
write: common.mustNotCall()
});
assert.strictEqual(duplex.writable, false);
duplex.write('asd');
duplex.on('error', common.mustCall((err) => {
assert.strictEqual(err.code, 'ERR_STREAM_WRITE_AFTER_END');
}));
duplex.on('finish', common.mustNotCall());
}
{
const duplex = new Duplex({
readable: false
});
assert.strictEqual(duplex.readable, false);
duplex.on('data', common.mustNotCall());
duplex.on('end', common.mustNotCall());
async function run() {
for await (const chunk of duplex) {
assert(false, chunk);
}
}
run().then(common.mustCall());
}

View File

@@ -0,0 +1,19 @@
'use strict';
const common = require('../common');
const { Writable, Readable } = require('stream');
{
const writable = new Writable();
writable.on('error', common.mustCall());
writable.end();
writable.write('h');
writable.write('h');
}
{
const readable = new Readable();
readable.on('error', common.mustCall());
readable.push(null);
readable.push('h');
readable.push('h');
}

View File

@@ -0,0 +1,52 @@
'use strict';
const common = require('../common');
const { Writable } = require('stream');
{
// Sync + Sync
const writable = new Writable({
write: common.mustCall((buf, enc, cb) => {
cb();
cb();
})
});
writable.write('hi');
writable.on('error', common.expectsError({
code: 'ERR_MULTIPLE_CALLBACK',
name: 'Error'
}));
}
{
// Sync + Async
const writable = new Writable({
write: common.mustCall((buf, enc, cb) => {
cb();
process.nextTick(() => {
cb();
});
})
});
writable.write('hi');
writable.on('error', common.expectsError({
code: 'ERR_MULTIPLE_CALLBACK',
name: 'Error'
}));
}
{
// Async + Async
const writable = new Writable({
write: common.mustCall((buf, enc, cb) => {
process.nextTick(cb);
process.nextTick(() => {
cb();
});
})
});
writable.write('hi');
writable.on('error', common.expectsError({
code: 'ERR_MULTIPLE_CALLBACK',
name: 'Error'
}));
}