Skip to content

stream: test explicit resource management implicitly #58296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import nodeCore from './tools/eslint/eslint-plugin-node-core.js';
const { globalIgnores } = await importEslintTool('eslint/config');
const { default: js } = await importEslintTool('@eslint/js');
const { default: babelEslintParser } = await importEslintTool('@babel/eslint-parser');
const babelPluginProposalExplicitResourceManagement =
resolveEslintTool('@babel/plugin-proposal-explicit-resource-management');
const babelPluginSyntaxImportAttributes = resolveEslintTool('@babel/plugin-syntax-import-attributes');
const babelPluginSyntaxImportSource = resolveEslintTool('@babel/plugin-syntax-import-source');
const { default: jsdoc } = await importEslintTool('eslint-plugin-jsdoc');
Expand Down Expand Up @@ -103,6 +105,7 @@ export default [
parserOptions: {
babelOptions: {
plugins: [
babelPluginProposalExplicitResourceManagement,
babelPluginSyntaxImportAttributes,
babelPluginSyntaxImportSource,
],
Expand Down
14 changes: 14 additions & 0 deletions test/parallel/test-stream-duplex-destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,17 @@ const assert = require('assert');
duplex.on('close', common.mustCall());
duplex[Symbol.asyncDispose]().then(common.mustCall());
}

(async () => {
// Check Symbol.asyncDispose implicitly
await using duplex = new Duplex({
write(chunk, enc, cb) { cb(); },
read() {},
});
duplex.on('error', common.mustCall(function(e) {
assert.strictEqual(e.name, 'AbortError');
assert.strictEqual(this.destroyed, true);
assert.strictEqual(this.errored.name, 'AbortError');
}));
duplex.on('close', common.mustCall());
})().then(common.mustCall());
15 changes: 15 additions & 0 deletions test/parallel/test-stream-readable-dispose.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,18 @@ const assert = require('assert');
assert.strictEqual(read.destroyed, true);
}));
}

(async () => {
await using read = new Readable({
read() {}
});
read.resume();

read.on('end', common.mustNotCall('no end event'));
read.on('close', common.mustCall());
read.on('error', common.mustCall(function(err) {
assert.strictEqual(err.name, 'AbortError');
assert.strictEqual(this.errored.name, 'AbortError');
assert.strictEqual(this.destroyed, true);
}));
})().then(common.mustCall());
12 changes: 12 additions & 0 deletions test/parallel/test-stream-transform-destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,15 @@ const assert = require('assert');
transform.on('close', common.mustCall());
transform[Symbol.asyncDispose]().then(common.mustCall());
}

(async () => {
await using transform = new Transform({
transform(chunk, enc, cb) {}
});
transform.on('error', common.mustCall(function(err) {
assert.strictEqual(err.name, 'AbortError');
assert.strictEqual(this.destroyed, true);
assert.strictEqual(this.errored.name, 'AbortError');
}));
transform.on('close', common.mustCall());
})().then(common.mustCall());
14 changes: 14 additions & 0 deletions test/parallel/test-stream-writable-destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,3 +499,17 @@ const assert = require('assert');
}));
write[Symbol.asyncDispose]().then(common.mustCall());
}

(async () => {
await using write = new Writable({
write(chunk, enc, cb) { cb(); }
});

write.on('error', common.mustCall(function(e) {
assert.strictEqual(e.name, 'AbortError');
assert.strictEqual(this.destroyed, true);
assert.strictEqual(this.errored.name, 'AbortError');
}));
write.on('close', common.mustCall());
write.on('finish', common.mustNotCall('no finish event'));
})().then(common.mustCall());
16 changes: 16 additions & 0 deletions tools/eslint/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tools/eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@babel/eslint-parser": "^7.27.1",
"@babel/plugin-syntax-import-attributes": "^7.27.1",
"@babel/plugin-syntax-import-source": "^7.27.1",
"@babel/plugin-proposal-explicit-resource-management": "^7.27.1",
"@stylistic/eslint-plugin-js": "^4.2.0",
"eslint": "^9.25.1",
"eslint-formatter-tap": "^8.40.0",
Expand Down
Loading