mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
test: ensure assertions are reached on more tests
PR-URL: https://github.com/nodejs/node/pull/60726 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
@@ -194,7 +194,7 @@ export default [
|
||||
].join(',')}}/**/*.{js,mjs,cjs}`,
|
||||
`test/parallel/test-{${
|
||||
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'a*,b*,…'
|
||||
Array.from({ length: 4 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',')
|
||||
Array.from({ length: 7 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',')
|
||||
},http-*,http2-*,${
|
||||
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'z*,y*,…'
|
||||
Array.from({ length: 7 }, (_, i) => String.fromCharCode(0x61 + 25 - i, 42)).join(',')
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const { strictEqual } = require('node:assert');
|
||||
const assert = require('node:assert');
|
||||
const { formatList } = require('internal/errors');
|
||||
|
||||
if (!common.hasIntl) common.skip('missing Intl');
|
||||
@@ -14,7 +14,7 @@ if (!common.hasIntl) common.skip('missing Intl');
|
||||
const input = ['apple', 'banana', 'orange', 'pear'];
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
const slicedInput = input.slice(0, i);
|
||||
strictEqual(formatList(slicedInput), and.format(slicedInput));
|
||||
strictEqual(formatList(slicedInput, 'or'), or.format(slicedInput));
|
||||
assert.strictEqual(formatList(slicedInput), and.format(slicedInput));
|
||||
assert.strictEqual(formatList(slicedInput, 'or'), or.format(slicedInput));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ const fixtures = require('../common/fixtures');
|
||||
function errExec(script, option, callback) {
|
||||
callback = typeof option === 'function' ? option : callback;
|
||||
option = typeof option === 'string' ? option : '';
|
||||
return exec(...common.escapePOSIXShell`"${process.execPath}" ${option} "${fixtures.path(script)}"`, (err, stdout, stderr) => {
|
||||
return exec(...common.escapePOSIXShell`"${process.execPath}" ${option} "${fixtures.path(script)}"`, common.mustCall((err, stdout, stderr) => {
|
||||
// There was some error
|
||||
assert.ok(err);
|
||||
|
||||
@@ -37,7 +37,7 @@ function errExec(script, option, callback) {
|
||||
|
||||
// Proxy the args for more tests.
|
||||
callback(err, stdout, stderr);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
const syntaxErrorMessage = /\bSyntaxError\b/;
|
||||
|
||||
@@ -1,211 +1,211 @@
|
||||
// Flags: --expose-internals
|
||||
|
||||
import '../common/index.mjs';
|
||||
import { strictEqual } from 'node:assert';
|
||||
import assert from 'node:assert';
|
||||
import errorsModule from 'internal/errors';
|
||||
|
||||
|
||||
const { determineSpecificType } = errorsModule;
|
||||
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(1n),
|
||||
'type bigint (1n)',
|
||||
);
|
||||
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(true),
|
||||
'type boolean (true)',
|
||||
);
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(false),
|
||||
'type boolean (false)',
|
||||
);
|
||||
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(2),
|
||||
'type number (2)',
|
||||
);
|
||||
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(NaN),
|
||||
'type number (NaN)',
|
||||
);
|
||||
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(Infinity),
|
||||
'type number (Infinity)',
|
||||
);
|
||||
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType({ __proto__: null }),
|
||||
'[Object: null prototype] {}',
|
||||
);
|
||||
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(''),
|
||||
"type string ('')",
|
||||
);
|
||||
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(''),
|
||||
"type string ('')",
|
||||
);
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType("''"),
|
||||
"type string (\"''\")",
|
||||
);
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor'),
|
||||
"type string ('Lorem ipsum dolor sit ame...')",
|
||||
);
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor'"),
|
||||
"type string ('Lorem ipsum dolor sit ame...')",
|
||||
);
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType("Lorem' ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor"),
|
||||
"type string (\"Lorem' ipsum dolor sit am...\")",
|
||||
);
|
||||
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(Symbol('foo')),
|
||||
'type symbol (Symbol(foo))',
|
||||
);
|
||||
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(function foo() {}),
|
||||
'function foo',
|
||||
);
|
||||
|
||||
const implicitlyNamed = function() {}; // eslint-disable-line func-style
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(implicitlyNamed),
|
||||
'function implicitlyNamed',
|
||||
);
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(() => {}),
|
||||
'function ',
|
||||
);
|
||||
function noName() {}
|
||||
delete noName.name;
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
noName.name,
|
||||
'',
|
||||
);
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(noName),
|
||||
'function ',
|
||||
);
|
||||
|
||||
function * generatorFn() {}
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(generatorFn),
|
||||
'function generatorFn',
|
||||
);
|
||||
|
||||
async function asyncFn() {}
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(asyncFn),
|
||||
'function asyncFn',
|
||||
);
|
||||
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(null),
|
||||
'null',
|
||||
);
|
||||
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(undefined),
|
||||
'undefined',
|
||||
);
|
||||
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType([]),
|
||||
'an instance of Array',
|
||||
);
|
||||
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(new Array()),
|
||||
'an instance of Array',
|
||||
);
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(new BigInt64Array()),
|
||||
'an instance of BigInt64Array',
|
||||
);
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(new BigUint64Array()),
|
||||
'an instance of BigUint64Array',
|
||||
);
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(new Int8Array()),
|
||||
'an instance of Int8Array',
|
||||
);
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(new Int16Array()),
|
||||
'an instance of Int16Array',
|
||||
);
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(new Int32Array()),
|
||||
'an instance of Int32Array',
|
||||
);
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(new Float32Array()),
|
||||
'an instance of Float32Array',
|
||||
);
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(new Float64Array()),
|
||||
'an instance of Float64Array',
|
||||
);
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(new Uint8Array()),
|
||||
'an instance of Uint8Array',
|
||||
);
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(new Uint8ClampedArray()),
|
||||
'an instance of Uint8ClampedArray',
|
||||
);
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(new Uint16Array()),
|
||||
'an instance of Uint16Array',
|
||||
);
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(new Uint32Array()),
|
||||
'an instance of Uint32Array',
|
||||
);
|
||||
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(new Date()),
|
||||
'an instance of Date',
|
||||
);
|
||||
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(new Map()),
|
||||
'an instance of Map',
|
||||
);
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(new WeakMap()),
|
||||
'an instance of WeakMap',
|
||||
);
|
||||
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType({}),
|
||||
'an instance of Object',
|
||||
);
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(new Object()),
|
||||
'an instance of Object',
|
||||
);
|
||||
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(Promise.resolve('foo')),
|
||||
'an instance of Promise',
|
||||
);
|
||||
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(new Set()),
|
||||
'an instance of Set',
|
||||
);
|
||||
strictEqual(
|
||||
assert.strictEqual(
|
||||
determineSpecificType(new WeakSet()),
|
||||
'an instance of WeakSet',
|
||||
);
|
||||
|
||||
@@ -2,30 +2,27 @@
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const {
|
||||
strictEqual,
|
||||
throws,
|
||||
} = require('assert');
|
||||
const assert = require('assert');
|
||||
const { AbortError } = require('internal/errors');
|
||||
|
||||
{
|
||||
const err = new AbortError();
|
||||
strictEqual(err.message, 'The operation was aborted');
|
||||
strictEqual(err.cause, undefined);
|
||||
assert.strictEqual(err.message, 'The operation was aborted');
|
||||
assert.strictEqual(err.cause, undefined);
|
||||
}
|
||||
|
||||
{
|
||||
const cause = new Error('boom');
|
||||
const err = new AbortError('bang', { cause });
|
||||
strictEqual(err.message, 'bang');
|
||||
strictEqual(err.cause, cause);
|
||||
assert.strictEqual(err.message, 'bang');
|
||||
assert.strictEqual(err.cause, cause);
|
||||
}
|
||||
|
||||
{
|
||||
throws(() => new AbortError('', false), {
|
||||
assert.throws(() => new AbortError('', false), {
|
||||
code: 'ERR_INVALID_ARG_TYPE'
|
||||
});
|
||||
throws(() => new AbortError('', ''), {
|
||||
assert.throws(() => new AbortError('', ''), {
|
||||
code: 'ERR_INVALID_ARG_TYPE'
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Flags: --expose-internals
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const common = require('../common');
|
||||
const { hideStackFrames, codes } = require('internal/errors');
|
||||
const { validateInteger } = require('internal/validators');
|
||||
const assert = require('assert');
|
||||
@@ -209,19 +209,15 @@ const assert = require('assert');
|
||||
|
||||
{
|
||||
// Binding passes the value of this to the wrapped function.
|
||||
let called = false;
|
||||
function a() {
|
||||
b.bind({ key: 'value' })();
|
||||
}
|
||||
|
||||
const b = hideStackFrames(function b() {
|
||||
const b = hideStackFrames(common.mustCall(function b() {
|
||||
assert.strictEqual(this.key, 'value');
|
||||
called = true;
|
||||
});
|
||||
}));
|
||||
|
||||
a();
|
||||
|
||||
assert.strictEqual(called, true);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -231,10 +227,10 @@ const assert = require('assert');
|
||||
b.withoutStackTrace.bind({ key: 'value' })();
|
||||
}
|
||||
|
||||
const b = hideStackFrames(function b() {
|
||||
const b = hideStackFrames(common.mustCall(function b() {
|
||||
assert.strictEqual(this.key, 'value');
|
||||
called = true;
|
||||
});
|
||||
}));
|
||||
|
||||
a();
|
||||
|
||||
|
||||
@@ -46,11 +46,11 @@ const EventEmitter = require('events');
|
||||
assert.strictEqual(b, 'b');
|
||||
});
|
||||
|
||||
ee.once('newListener', function(name, listener) {
|
||||
ee.once('newListener', common.mustCall(function(name, listener) {
|
||||
assert.strictEqual(name, 'hello');
|
||||
assert.strictEqual(listener, hello);
|
||||
assert.deepStrictEqual(this.listeners('hello'), []);
|
||||
});
|
||||
}));
|
||||
|
||||
ee.on('hello', hello);
|
||||
ee.once('foo', assert.fail);
|
||||
@@ -72,13 +72,13 @@ const EventEmitter = require('events');
|
||||
const listen2 = () => {};
|
||||
const ee = new EventEmitter();
|
||||
|
||||
ee.once('newListener', function() {
|
||||
ee.once('newListener', common.mustCall(() => {
|
||||
assert.deepStrictEqual(ee.listeners('hello'), []);
|
||||
ee.once('newListener', function() {
|
||||
ee.once('newListener', common.mustCall(() => {
|
||||
assert.deepStrictEqual(ee.listeners('hello'), []);
|
||||
});
|
||||
}));
|
||||
ee.on('hello', listen2);
|
||||
});
|
||||
}));
|
||||
ee.on('hello', listen1);
|
||||
// The order of listeners on an event is not always the order in which the
|
||||
// listeners were added.
|
||||
|
||||
@@ -28,8 +28,8 @@ const E = events.EventEmitter.prototype;
|
||||
assert.strictEqual(E.constructor.name, 'EventEmitter');
|
||||
assert.strictEqual(E.on, E.addListener); // Same method.
|
||||
assert.strictEqual(E.off, E.removeListener); // Same method.
|
||||
Object.getOwnPropertyNames(E).forEach(function(name) {
|
||||
for (const name of Object.getOwnPropertyNames(E)) {
|
||||
if (name === 'constructor' || name === 'on' || name === 'off') return;
|
||||
if (typeof E[name] !== 'function') return;
|
||||
assert.strictEqual(E[name].name, name);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -87,9 +87,9 @@ function expect(expected) {
|
||||
{
|
||||
const ee = new events.EventEmitter();
|
||||
let expectLength = 2;
|
||||
ee.on('removeListener', function(name, noop) {
|
||||
ee.on('removeListener', common.mustCallAtLeast(function(name, noop) {
|
||||
assert.strictEqual(expectLength--, this.listeners('baz').length);
|
||||
});
|
||||
}));
|
||||
ee.on('baz', common.mustNotCall());
|
||||
ee.on('baz', common.mustNotCall());
|
||||
ee.on('baz', common.mustNotCall());
|
||||
|
||||
@@ -7,11 +7,7 @@ const {
|
||||
executionAsyncId,
|
||||
} = require('async_hooks');
|
||||
|
||||
const {
|
||||
deepStrictEqual,
|
||||
strictEqual,
|
||||
throws,
|
||||
} = require('assert');
|
||||
const assert = require('assert');
|
||||
|
||||
const {
|
||||
setImmediate: tick,
|
||||
@@ -67,15 +63,15 @@ function makeHook(trackedTypes) {
|
||||
foo.on('someEvent', common.mustCall());
|
||||
foo.emit('someEvent');
|
||||
|
||||
deepStrictEqual([foo.asyncId], [...tracer.ids()]);
|
||||
strictEqual(foo.triggerAsyncId, origExecutionAsyncId);
|
||||
strictEqual(foo.asyncResource.eventEmitter, foo);
|
||||
assert.deepStrictEqual([foo.asyncId], [...tracer.ids()]);
|
||||
assert.strictEqual(foo.triggerAsyncId, origExecutionAsyncId);
|
||||
assert.strictEqual(foo.asyncResource.eventEmitter, foo);
|
||||
|
||||
foo.emitDestroy();
|
||||
|
||||
await tick();
|
||||
|
||||
deepStrictEqual(tracer.done(), new Set([
|
||||
assert.deepStrictEqual(tracer.done(), new Set([
|
||||
[
|
||||
{
|
||||
name: 'init',
|
||||
@@ -99,7 +95,7 @@ function makeHook(trackedTypes) {
|
||||
|
||||
const foo = new Foo('ResourceName');
|
||||
|
||||
deepStrictEqual(tracer.done(), new Set([
|
||||
assert.deepStrictEqual(tracer.done(), new Set([
|
||||
[
|
||||
{
|
||||
name: 'init',
|
||||
@@ -120,7 +116,7 @@ function makeHook(trackedTypes) {
|
||||
|
||||
const foo = new Foo({ name: 'ResourceName' });
|
||||
|
||||
deepStrictEqual(tracer.done(), new Set([
|
||||
assert.deepStrictEqual(tracer.done(), new Set([
|
||||
[
|
||||
{
|
||||
name: 'init',
|
||||
@@ -132,18 +128,18 @@ function makeHook(trackedTypes) {
|
||||
]));
|
||||
})().then(common.mustCall());
|
||||
|
||||
throws(
|
||||
assert.throws(
|
||||
() => EventEmitterAsyncResource.prototype.emit(),
|
||||
{ name: 'TypeError', message: /Cannot read private member/ }
|
||||
);
|
||||
|
||||
throws(
|
||||
assert.throws(
|
||||
() => EventEmitterAsyncResource.prototype.emitDestroy(),
|
||||
{ name: 'TypeError', message: /Cannot read private member/ }
|
||||
);
|
||||
|
||||
['asyncId', 'triggerAsyncId', 'asyncResource'].forEach((getter) => {
|
||||
throws(
|
||||
assert.throws(
|
||||
() => Reflect.get(EventEmitterAsyncResource.prototype, getter, {}),
|
||||
{
|
||||
name: 'TypeError',
|
||||
|
||||
@@ -3,44 +3,44 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const { ok, strictEqual, deepStrictEqual, throws } = require('node:assert');
|
||||
const assert = require('node:assert');
|
||||
const { inspect } = require('node:util');
|
||||
const { Event, EventTarget, CustomEvent } = require('internal/event_target');
|
||||
|
||||
{
|
||||
ok(CustomEvent);
|
||||
assert.ok(CustomEvent);
|
||||
|
||||
// Default string
|
||||
const tag = Object.prototype.toString.call(new CustomEvent('$'));
|
||||
strictEqual(tag, '[object CustomEvent]');
|
||||
assert.strictEqual(tag, '[object CustomEvent]');
|
||||
}
|
||||
|
||||
{
|
||||
// No argument behavior - throw TypeError
|
||||
throws(() => {
|
||||
assert.throws(() => {
|
||||
new CustomEvent();
|
||||
}, TypeError);
|
||||
|
||||
throws(() => new CustomEvent(Symbol()), TypeError);
|
||||
assert.throws(() => new CustomEvent(Symbol()), TypeError);
|
||||
|
||||
// Too many arguments passed behavior - ignore additional arguments
|
||||
const ev = new CustomEvent('foo', {}, {});
|
||||
strictEqual(ev.type, 'foo');
|
||||
assert.strictEqual(ev.type, 'foo');
|
||||
}
|
||||
|
||||
{
|
||||
const ev = new CustomEvent('$');
|
||||
strictEqual(ev.type, '$');
|
||||
strictEqual(ev.bubbles, false);
|
||||
strictEqual(ev.cancelable, false);
|
||||
strictEqual(ev.detail, null);
|
||||
assert.strictEqual(ev.type, '$');
|
||||
assert.strictEqual(ev.bubbles, false);
|
||||
assert.strictEqual(ev.cancelable, false);
|
||||
assert.strictEqual(ev.detail, null);
|
||||
}
|
||||
|
||||
{
|
||||
// Coercion to string works
|
||||
strictEqual(new CustomEvent(1).type, '1');
|
||||
strictEqual(new CustomEvent(false).type, 'false');
|
||||
strictEqual(new CustomEvent({}).type, String({}));
|
||||
assert.strictEqual(new CustomEvent(1).type, '1');
|
||||
assert.strictEqual(new CustomEvent(false).type, 'false');
|
||||
assert.strictEqual(new CustomEvent({}).type, String({}));
|
||||
}
|
||||
|
||||
{
|
||||
@@ -49,18 +49,18 @@ const { Event, EventTarget, CustomEvent } = require('internal/event_target');
|
||||
sweet: 'x',
|
||||
cancelable: true,
|
||||
});
|
||||
strictEqual(ev.type, '$');
|
||||
strictEqual(ev.bubbles, false);
|
||||
strictEqual(ev.cancelable, true);
|
||||
strictEqual(ev.sweet, undefined);
|
||||
strictEqual(ev.detail, 56);
|
||||
assert.strictEqual(ev.type, '$');
|
||||
assert.strictEqual(ev.bubbles, false);
|
||||
assert.strictEqual(ev.cancelable, true);
|
||||
assert.strictEqual(ev.sweet, undefined);
|
||||
assert.strictEqual(ev.detail, 56);
|
||||
}
|
||||
|
||||
{
|
||||
// Any types of value for `detail` are acceptable.
|
||||
['foo', 1, false, [], {}].forEach((i) => {
|
||||
const ev = new CustomEvent('$', { detail: i });
|
||||
strictEqual(ev.detail, i);
|
||||
assert.strictEqual(ev.detail, i);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -69,21 +69,21 @@ const { Event, EventTarget, CustomEvent } = require('internal/event_target');
|
||||
const ev = new CustomEvent('$', {
|
||||
detail: 56,
|
||||
});
|
||||
strictEqual(ev.detail, 56);
|
||||
assert.strictEqual(ev.detail, 56);
|
||||
try {
|
||||
ev.detail = 96;
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
} catch (error) {
|
||||
common.mustCall()();
|
||||
}
|
||||
strictEqual(ev.detail, 56);
|
||||
assert.strictEqual(ev.detail, 56);
|
||||
}
|
||||
|
||||
{
|
||||
const ev = new Event('$', {
|
||||
detail: 96,
|
||||
});
|
||||
strictEqual(ev.detail, undefined);
|
||||
assert.strictEqual(ev.detail, undefined);
|
||||
}
|
||||
|
||||
// The following tests verify whether CustomEvent works the same as Event
|
||||
@@ -91,31 +91,31 @@ const { Event, EventTarget, CustomEvent } = require('internal/event_target');
|
||||
|
||||
{
|
||||
const ev = new CustomEvent('$');
|
||||
strictEqual(ev.type, '$');
|
||||
strictEqual(ev.bubbles, false);
|
||||
strictEqual(ev.cancelable, false);
|
||||
strictEqual(ev.detail, null);
|
||||
assert.strictEqual(ev.type, '$');
|
||||
assert.strictEqual(ev.bubbles, false);
|
||||
assert.strictEqual(ev.cancelable, false);
|
||||
assert.strictEqual(ev.detail, null);
|
||||
|
||||
strictEqual(ev.defaultPrevented, false);
|
||||
strictEqual(typeof ev.timeStamp, 'number');
|
||||
assert.strictEqual(ev.defaultPrevented, false);
|
||||
assert.strictEqual(typeof ev.timeStamp, 'number');
|
||||
|
||||
// Compatibility properties with the DOM
|
||||
deepStrictEqual(ev.composedPath(), []);
|
||||
strictEqual(ev.returnValue, true);
|
||||
strictEqual(ev.composed, false);
|
||||
strictEqual(ev.isTrusted, false);
|
||||
strictEqual(ev.eventPhase, 0);
|
||||
strictEqual(ev.cancelBubble, false);
|
||||
assert.deepStrictEqual(ev.composedPath(), []);
|
||||
assert.strictEqual(ev.returnValue, true);
|
||||
assert.strictEqual(ev.composed, false);
|
||||
assert.strictEqual(ev.isTrusted, false);
|
||||
assert.strictEqual(ev.eventPhase, 0);
|
||||
assert.strictEqual(ev.cancelBubble, false);
|
||||
|
||||
// Not cancelable
|
||||
ev.preventDefault();
|
||||
strictEqual(ev.defaultPrevented, false);
|
||||
assert.strictEqual(ev.defaultPrevented, false);
|
||||
}
|
||||
|
||||
{
|
||||
// Invalid options
|
||||
['foo', 1, false].forEach((i) =>
|
||||
throws(() => new CustomEvent('foo', i), {
|
||||
assert.throws(() => new CustomEvent('foo', i), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
name: 'TypeError',
|
||||
message:
|
||||
@@ -127,67 +127,67 @@ const { Event, EventTarget, CustomEvent } = require('internal/event_target');
|
||||
|
||||
{
|
||||
const ev = new CustomEvent('$');
|
||||
strictEqual(ev.constructor.name, 'CustomEvent');
|
||||
assert.strictEqual(ev.constructor.name, 'CustomEvent');
|
||||
|
||||
// CustomEvent Statics
|
||||
strictEqual(CustomEvent.NONE, 0);
|
||||
strictEqual(CustomEvent.CAPTURING_PHASE, 1);
|
||||
strictEqual(CustomEvent.AT_TARGET, 2);
|
||||
strictEqual(CustomEvent.BUBBLING_PHASE, 3);
|
||||
strictEqual(new CustomEvent('foo').eventPhase, CustomEvent.NONE);
|
||||
assert.strictEqual(CustomEvent.NONE, 0);
|
||||
assert.strictEqual(CustomEvent.CAPTURING_PHASE, 1);
|
||||
assert.strictEqual(CustomEvent.AT_TARGET, 2);
|
||||
assert.strictEqual(CustomEvent.BUBBLING_PHASE, 3);
|
||||
assert.strictEqual(new CustomEvent('foo').eventPhase, CustomEvent.NONE);
|
||||
|
||||
// CustomEvent is a function
|
||||
strictEqual(CustomEvent.length, 1);
|
||||
assert.strictEqual(CustomEvent.length, 1);
|
||||
}
|
||||
|
||||
{
|
||||
const ev = new CustomEvent('foo');
|
||||
strictEqual(ev.cancelBubble, false);
|
||||
assert.strictEqual(ev.cancelBubble, false);
|
||||
ev.cancelBubble = true;
|
||||
strictEqual(ev.cancelBubble, true);
|
||||
assert.strictEqual(ev.cancelBubble, true);
|
||||
}
|
||||
{
|
||||
const ev = new CustomEvent('foo');
|
||||
strictEqual(ev.cancelBubble, false);
|
||||
assert.strictEqual(ev.cancelBubble, false);
|
||||
ev.stopPropagation();
|
||||
strictEqual(ev.cancelBubble, true);
|
||||
assert.strictEqual(ev.cancelBubble, true);
|
||||
}
|
||||
{
|
||||
const ev = new CustomEvent('foo');
|
||||
strictEqual(ev.cancelBubble, false);
|
||||
assert.strictEqual(ev.cancelBubble, false);
|
||||
ev.cancelBubble = 'some-truthy-value';
|
||||
strictEqual(ev.cancelBubble, true);
|
||||
assert.strictEqual(ev.cancelBubble, true);
|
||||
}
|
||||
{
|
||||
const ev = new CustomEvent('foo');
|
||||
strictEqual(ev.cancelBubble, false);
|
||||
assert.strictEqual(ev.cancelBubble, false);
|
||||
ev.cancelBubble = true;
|
||||
strictEqual(ev.cancelBubble, true);
|
||||
assert.strictEqual(ev.cancelBubble, true);
|
||||
}
|
||||
{
|
||||
const ev = new CustomEvent('foo');
|
||||
strictEqual(ev.cancelBubble, false);
|
||||
assert.strictEqual(ev.cancelBubble, false);
|
||||
ev.stopPropagation();
|
||||
strictEqual(ev.cancelBubble, true);
|
||||
assert.strictEqual(ev.cancelBubble, true);
|
||||
}
|
||||
{
|
||||
const ev = new CustomEvent('foo');
|
||||
strictEqual(ev.cancelBubble, false);
|
||||
assert.strictEqual(ev.cancelBubble, false);
|
||||
ev.cancelBubble = 'some-truthy-value';
|
||||
strictEqual(ev.cancelBubble, true);
|
||||
assert.strictEqual(ev.cancelBubble, true);
|
||||
}
|
||||
{
|
||||
const ev = new CustomEvent('foo', { cancelable: true });
|
||||
strictEqual(ev.type, 'foo');
|
||||
strictEqual(ev.cancelable, true);
|
||||
strictEqual(ev.defaultPrevented, false);
|
||||
assert.strictEqual(ev.type, 'foo');
|
||||
assert.strictEqual(ev.cancelable, true);
|
||||
assert.strictEqual(ev.defaultPrevented, false);
|
||||
|
||||
ev.preventDefault();
|
||||
strictEqual(ev.defaultPrevented, true);
|
||||
assert.strictEqual(ev.defaultPrevented, true);
|
||||
}
|
||||
{
|
||||
const ev = new CustomEvent('foo');
|
||||
strictEqual(ev.isTrusted, false);
|
||||
assert.strictEqual(ev.isTrusted, false);
|
||||
}
|
||||
|
||||
// Works with EventTarget
|
||||
@@ -197,8 +197,8 @@ const { Event, EventTarget, CustomEvent } = require('internal/event_target');
|
||||
const et = new EventTarget();
|
||||
const ev = new CustomEvent('$', { detail: obj });
|
||||
const fn = common.mustCall((event) => {
|
||||
strictEqual(event, ev);
|
||||
deepStrictEqual(event.detail, obj);
|
||||
assert.strictEqual(event, ev);
|
||||
assert.deepStrictEqual(event.detail, obj);
|
||||
});
|
||||
et.addEventListener('$', fn);
|
||||
et.dispatchEvent(ev);
|
||||
@@ -208,7 +208,7 @@ const { Event, EventTarget, CustomEvent } = require('internal/event_target');
|
||||
const eventTarget = new EventTarget();
|
||||
const event = new CustomEvent('$');
|
||||
eventTarget.dispatchEvent(event);
|
||||
strictEqual(event.target, eventTarget);
|
||||
assert.strictEqual(event.target, eventTarget);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -216,23 +216,23 @@ const { Event, EventTarget, CustomEvent } = require('internal/event_target');
|
||||
const eventTarget = new EventTarget();
|
||||
|
||||
const ev1 = common.mustCall(function(event) {
|
||||
strictEqual(event.type, 'foo');
|
||||
strictEqual(event.detail, obj);
|
||||
strictEqual(this, eventTarget);
|
||||
strictEqual(event.eventPhase, 2);
|
||||
assert.strictEqual(event.type, 'foo');
|
||||
assert.strictEqual(event.detail, obj);
|
||||
assert.strictEqual(this, eventTarget);
|
||||
assert.strictEqual(event.eventPhase, 2);
|
||||
}, 2);
|
||||
|
||||
const ev2 = {
|
||||
handleEvent: common.mustCall(function(event) {
|
||||
strictEqual(event.type, 'foo');
|
||||
strictEqual(event.detail, obj);
|
||||
strictEqual(this, ev2);
|
||||
assert.strictEqual(event.type, 'foo');
|
||||
assert.strictEqual(event.detail, obj);
|
||||
assert.strictEqual(this, ev2);
|
||||
}),
|
||||
};
|
||||
|
||||
eventTarget.addEventListener('foo', ev1);
|
||||
eventTarget.addEventListener('foo', ev2, { once: true });
|
||||
ok(eventTarget.dispatchEvent(new CustomEvent('foo', { detail: obj })));
|
||||
assert.ok(eventTarget.dispatchEvent(new CustomEvent('foo', { detail: obj })));
|
||||
eventTarget.dispatchEvent(new CustomEvent('foo', { detail: obj }));
|
||||
|
||||
eventTarget.removeEventListener('foo', ev1);
|
||||
@@ -249,32 +249,32 @@ const { Event, EventTarget, CustomEvent } = require('internal/event_target');
|
||||
eventTarget1.addEventListener(
|
||||
'foo',
|
||||
common.mustCall((event) => {
|
||||
strictEqual(event.eventPhase, CustomEvent.AT_TARGET);
|
||||
strictEqual(event.target, eventTarget1);
|
||||
strictEqual(event.detail, obj);
|
||||
deepStrictEqual(event.composedPath(), [eventTarget1]);
|
||||
assert.strictEqual(event.eventPhase, CustomEvent.AT_TARGET);
|
||||
assert.strictEqual(event.target, eventTarget1);
|
||||
assert.strictEqual(event.detail, obj);
|
||||
assert.deepStrictEqual(event.composedPath(), [eventTarget1]);
|
||||
}),
|
||||
);
|
||||
|
||||
eventTarget2.addEventListener(
|
||||
'foo',
|
||||
common.mustCall((event) => {
|
||||
strictEqual(event.eventPhase, CustomEvent.AT_TARGET);
|
||||
strictEqual(event.target, eventTarget2);
|
||||
strictEqual(event.detail, obj);
|
||||
deepStrictEqual(event.composedPath(), [eventTarget2]);
|
||||
assert.strictEqual(event.eventPhase, CustomEvent.AT_TARGET);
|
||||
assert.strictEqual(event.target, eventTarget2);
|
||||
assert.strictEqual(event.detail, obj);
|
||||
assert.deepStrictEqual(event.composedPath(), [eventTarget2]);
|
||||
}),
|
||||
);
|
||||
|
||||
eventTarget1.dispatchEvent(event);
|
||||
strictEqual(event.eventPhase, CustomEvent.NONE);
|
||||
strictEqual(event.target, eventTarget1);
|
||||
deepStrictEqual(event.composedPath(), []);
|
||||
assert.strictEqual(event.eventPhase, CustomEvent.NONE);
|
||||
assert.strictEqual(event.target, eventTarget1);
|
||||
assert.deepStrictEqual(event.composedPath(), []);
|
||||
|
||||
eventTarget2.dispatchEvent(event);
|
||||
strictEqual(event.eventPhase, CustomEvent.NONE);
|
||||
strictEqual(event.target, eventTarget2);
|
||||
deepStrictEqual(event.composedPath(), []);
|
||||
assert.strictEqual(event.eventPhase, CustomEvent.NONE);
|
||||
assert.strictEqual(event.target, eventTarget2);
|
||||
assert.deepStrictEqual(event.composedPath(), []);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -282,15 +282,15 @@ const { Event, EventTarget, CustomEvent } = require('internal/event_target');
|
||||
const target = new EventTarget();
|
||||
const event = new CustomEvent('foo', { detail: obj });
|
||||
|
||||
strictEqual(event.target, null);
|
||||
assert.strictEqual(event.target, null);
|
||||
|
||||
target.addEventListener(
|
||||
'foo',
|
||||
common.mustCall((event) => {
|
||||
strictEqual(event.target, target);
|
||||
strictEqual(event.currentTarget, target);
|
||||
strictEqual(event.srcElement, target);
|
||||
strictEqual(event.detail, obj);
|
||||
assert.strictEqual(event.target, target);
|
||||
assert.strictEqual(event.currentTarget, target);
|
||||
assert.strictEqual(event.srcElement, target);
|
||||
assert.strictEqual(event.detail, obj);
|
||||
}),
|
||||
);
|
||||
target.dispatchEvent(event);
|
||||
@@ -302,8 +302,8 @@ const { Event, EventTarget, CustomEvent } = require('internal/event_target');
|
||||
const ev = new SubEvent('foo', { detail: 56 });
|
||||
const eventTarget = new EventTarget();
|
||||
const fn = common.mustCall((event) => {
|
||||
strictEqual(event, ev);
|
||||
strictEqual(event.detail, 56);
|
||||
assert.strictEqual(event, ev);
|
||||
assert.strictEqual(event.detail, 56);
|
||||
});
|
||||
eventTarget.addEventListener('foo', fn, { once: true });
|
||||
eventTarget.dispatchEvent(ev);
|
||||
@@ -316,10 +316,10 @@ const { Event, EventTarget, CustomEvent } = require('internal/event_target');
|
||||
const evConstructorName = inspect(ev, {
|
||||
depth: -1,
|
||||
});
|
||||
strictEqual(evConstructorName, 'CustomEvent');
|
||||
assert.strictEqual(evConstructorName, 'CustomEvent');
|
||||
|
||||
const inspectResult = inspect(ev, {
|
||||
depth: 1,
|
||||
});
|
||||
ok(inspectResult.includes('CustomEvent'));
|
||||
assert.ok(inspectResult.includes('CustomEvent'));
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ async function invalidArgType() {
|
||||
|
||||
const ee = new EventEmitter();
|
||||
|
||||
[1, 'hi', null, false, () => {}, Symbol(), 1n].map((options) => {
|
||||
[1, 'hi', null, false, () => {}, Symbol(), 1n].forEach((options) => {
|
||||
return assert.throws(() => on(ee, 'foo', options), common.expectsError({
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
name: 'TypeError',
|
||||
|
||||
@@ -3,12 +3,7 @@
|
||||
|
||||
const common = require('../common');
|
||||
const { once, EventEmitter, getEventListeners } = require('events');
|
||||
const {
|
||||
deepStrictEqual,
|
||||
fail,
|
||||
rejects,
|
||||
strictEqual,
|
||||
} = require('assert');
|
||||
const assert = require('assert');
|
||||
|
||||
async function onceAnEvent() {
|
||||
const ee = new EventEmitter();
|
||||
@@ -18,16 +13,16 @@ async function onceAnEvent() {
|
||||
});
|
||||
|
||||
const [value] = await once(ee, 'myevent');
|
||||
strictEqual(value, 42);
|
||||
strictEqual(ee.listenerCount('error'), 0);
|
||||
strictEqual(ee.listenerCount('myevent'), 0);
|
||||
assert.strictEqual(value, 42);
|
||||
assert.strictEqual(ee.listenerCount('error'), 0);
|
||||
assert.strictEqual(ee.listenerCount('myevent'), 0);
|
||||
}
|
||||
|
||||
async function onceAnEventWithInvalidOptions() {
|
||||
const ee = new EventEmitter();
|
||||
|
||||
await Promise.all([1, 'hi', null, false, () => {}, Symbol(), 1n].map((options) => {
|
||||
return rejects(once(ee, 'myevent', options), {
|
||||
return assert.rejects(once(ee, 'myevent', options), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
});
|
||||
}));
|
||||
@@ -41,7 +36,7 @@ async function onceAnEventWithTwoArgs() {
|
||||
});
|
||||
|
||||
const value = await once(ee, 'myevent');
|
||||
deepStrictEqual(value, [42, 24]);
|
||||
assert.deepStrictEqual(value, [42, 24]);
|
||||
}
|
||||
|
||||
async function catchesErrors() {
|
||||
@@ -58,9 +53,9 @@ async function catchesErrors() {
|
||||
} catch (_e) {
|
||||
err = _e;
|
||||
}
|
||||
strictEqual(err, expected);
|
||||
strictEqual(ee.listenerCount('error'), 0);
|
||||
strictEqual(ee.listenerCount('myevent'), 0);
|
||||
assert.strictEqual(err, expected);
|
||||
assert.strictEqual(ee.listenerCount('error'), 0);
|
||||
assert.strictEqual(ee.listenerCount('myevent'), 0);
|
||||
}
|
||||
|
||||
async function catchesErrorsWithAbortSignal() {
|
||||
@@ -76,17 +71,17 @@ async function catchesErrorsWithAbortSignal() {
|
||||
|
||||
try {
|
||||
const promise = once(ee, 'myevent', { signal });
|
||||
strictEqual(ee.listenerCount('error'), 1);
|
||||
strictEqual(getEventListeners(signal, 'abort').length, 1);
|
||||
assert.strictEqual(ee.listenerCount('error'), 1);
|
||||
assert.strictEqual(getEventListeners(signal, 'abort').length, 1);
|
||||
|
||||
await promise;
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
strictEqual(err, expected);
|
||||
strictEqual(ee.listenerCount('error'), 0);
|
||||
strictEqual(ee.listenerCount('myevent'), 0);
|
||||
strictEqual(getEventListeners(signal, 'abort').length, 0);
|
||||
assert.strictEqual(err, expected);
|
||||
assert.strictEqual(ee.listenerCount('error'), 0);
|
||||
assert.strictEqual(ee.listenerCount('myevent'), 0);
|
||||
assert.strictEqual(getEventListeners(signal, 'abort').length, 0);
|
||||
}
|
||||
|
||||
async function stopListeningAfterCatchingError() {
|
||||
@@ -104,9 +99,9 @@ async function stopListeningAfterCatchingError() {
|
||||
} catch (_e) {
|
||||
err = _e;
|
||||
}
|
||||
strictEqual(err, expected);
|
||||
strictEqual(ee.listenerCount('error'), 0);
|
||||
strictEqual(ee.listenerCount('myevent'), 0);
|
||||
assert.strictEqual(err, expected);
|
||||
assert.strictEqual(ee.listenerCount('error'), 0);
|
||||
assert.strictEqual(ee.listenerCount('myevent'), 0);
|
||||
}
|
||||
|
||||
async function onceError() {
|
||||
@@ -118,11 +113,11 @@ async function onceError() {
|
||||
});
|
||||
|
||||
const promise = once(ee, 'error');
|
||||
strictEqual(ee.listenerCount('error'), 1);
|
||||
assert.strictEqual(ee.listenerCount('error'), 1);
|
||||
const [ err ] = await promise;
|
||||
strictEqual(err, expected);
|
||||
strictEqual(ee.listenerCount('error'), 0);
|
||||
strictEqual(ee.listenerCount('myevent'), 0);
|
||||
assert.strictEqual(err, expected);
|
||||
assert.strictEqual(ee.listenerCount('error'), 0);
|
||||
assert.strictEqual(ee.listenerCount('myevent'), 0);
|
||||
}
|
||||
|
||||
async function onceWithEventTarget() {
|
||||
@@ -132,7 +127,7 @@ async function onceWithEventTarget() {
|
||||
et.dispatchEvent(event);
|
||||
});
|
||||
const [ value ] = await once(et, 'myevent');
|
||||
strictEqual(value, event);
|
||||
assert.strictEqual(value, event);
|
||||
}
|
||||
|
||||
async function onceWithEventTargetError() {
|
||||
@@ -143,20 +138,20 @@ async function onceWithEventTargetError() {
|
||||
});
|
||||
|
||||
const [ err ] = await once(et, 'error');
|
||||
strictEqual(err, error);
|
||||
assert.strictEqual(err, error);
|
||||
}
|
||||
|
||||
async function onceWithInvalidEventEmmiter() {
|
||||
const ac = new AbortController();
|
||||
return rejects(once(ac, 'myevent'), {
|
||||
return assert.rejects(once(ac, 'myevent'), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
});
|
||||
}
|
||||
|
||||
async function prioritizesEventEmitter() {
|
||||
const ee = new EventEmitter();
|
||||
ee.addEventListener = fail;
|
||||
ee.removeAllListeners = fail;
|
||||
ee.addEventListener = assert.fail;
|
||||
ee.removeAllListeners = assert.fail;
|
||||
process.nextTick(() => ee.emit('foo'));
|
||||
await once(ee, 'foo');
|
||||
}
|
||||
@@ -167,12 +162,12 @@ async function abortSignalBefore() {
|
||||
const abortedSignal = AbortSignal.abort();
|
||||
|
||||
await Promise.all([1, {}, 'hi', null, false].map((signal) => {
|
||||
return rejects(once(ee, 'foo', { signal }), {
|
||||
return assert.rejects(once(ee, 'foo', { signal }), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
});
|
||||
}));
|
||||
|
||||
return rejects(once(ee, 'foo', { signal: abortedSignal }), {
|
||||
return assert.rejects(once(ee, 'foo', { signal: abortedSignal }), {
|
||||
name: 'AbortError',
|
||||
});
|
||||
}
|
||||
@@ -181,7 +176,7 @@ async function abortSignalAfter() {
|
||||
const ee = new EventEmitter();
|
||||
const ac = new AbortController();
|
||||
ee.on('error', common.mustNotCall());
|
||||
const r = rejects(once(ee, 'foo', { signal: ac.signal }), {
|
||||
const r = assert.rejects(once(ee, 'foo', { signal: ac.signal }), {
|
||||
name: 'AbortError',
|
||||
});
|
||||
process.nextTick(() => ac.abort());
|
||||
@@ -196,9 +191,9 @@ async function abortSignalAfterEvent() {
|
||||
ac.abort();
|
||||
});
|
||||
const promise = once(ee, 'foo', { signal: ac.signal });
|
||||
strictEqual(getEventListeners(ac.signal, 'abort').length, 1);
|
||||
assert.strictEqual(getEventListeners(ac.signal, 'abort').length, 1);
|
||||
await promise;
|
||||
strictEqual(getEventListeners(ac.signal, 'abort').length, 0);
|
||||
assert.strictEqual(getEventListeners(ac.signal, 'abort').length, 0);
|
||||
}
|
||||
|
||||
async function abortSignalRemoveListener() {
|
||||
@@ -209,8 +204,8 @@ async function abortSignalRemoveListener() {
|
||||
process.nextTick(() => ac.abort());
|
||||
await once(ee, 'test', { signal: ac.signal });
|
||||
} catch {
|
||||
strictEqual(ee.listeners('test').length, 0);
|
||||
strictEqual(ee.listeners('error').length, 0);
|
||||
assert.strictEqual(ee.listeners('test').length, 0);
|
||||
assert.strictEqual(ee.listeners('error').length, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,12 +214,12 @@ async function eventTargetAbortSignalBefore() {
|
||||
const abortedSignal = AbortSignal.abort();
|
||||
|
||||
await Promise.all([1, {}, 'hi', null, false].map((signal) => {
|
||||
return rejects(once(et, 'foo', { signal }), {
|
||||
return assert.rejects(once(et, 'foo', { signal }), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
});
|
||||
}));
|
||||
|
||||
return rejects(once(et, 'foo', { signal: abortedSignal }), {
|
||||
return assert.rejects(once(et, 'foo', { signal: abortedSignal }), {
|
||||
name: 'AbortError',
|
||||
});
|
||||
}
|
||||
@@ -236,7 +231,7 @@ async function eventTargetAbortSignalBeforeEvenWhenSignalPropagationStopped() {
|
||||
signal.addEventListener('abort', (e) => e.stopImmediatePropagation(), { once: true });
|
||||
|
||||
process.nextTick(() => ac.abort());
|
||||
return rejects(once(et, 'foo', { signal }), {
|
||||
return assert.rejects(once(et, 'foo', { signal }), {
|
||||
name: 'AbortError',
|
||||
});
|
||||
}
|
||||
@@ -244,7 +239,7 @@ async function eventTargetAbortSignalBeforeEvenWhenSignalPropagationStopped() {
|
||||
async function eventTargetAbortSignalAfter() {
|
||||
const et = new EventTarget();
|
||||
const ac = new AbortController();
|
||||
const r = rejects(once(et, 'foo', { signal: ac.signal }), {
|
||||
const r = assert.rejects(once(et, 'foo', { signal: ac.signal }), {
|
||||
name: 'AbortError',
|
||||
});
|
||||
process.nextTick(() => ac.abort());
|
||||
|
||||
@@ -3,10 +3,7 @@
|
||||
const common = require('../common');
|
||||
const { kWeakHandler } = require('internal/event_target');
|
||||
|
||||
const {
|
||||
deepStrictEqual,
|
||||
throws,
|
||||
} = require('assert');
|
||||
const assert = require('assert');
|
||||
|
||||
const { getEventListeners, EventEmitter } = require('events');
|
||||
|
||||
@@ -19,9 +16,9 @@ const { getEventListeners, EventEmitter } = require('events');
|
||||
emitter.on('foo', fn2);
|
||||
emitter.on('baz', fn1);
|
||||
emitter.on('baz', fn1);
|
||||
deepStrictEqual(getEventListeners(emitter, 'foo'), [fn1, fn2]);
|
||||
deepStrictEqual(getEventListeners(emitter, 'bar'), []);
|
||||
deepStrictEqual(getEventListeners(emitter, 'baz'), [fn1, fn1]);
|
||||
assert.deepStrictEqual(getEventListeners(emitter, 'foo'), [fn1, fn2]);
|
||||
assert.deepStrictEqual(getEventListeners(emitter, 'bar'), []);
|
||||
assert.deepStrictEqual(getEventListeners(emitter, 'baz'), [fn1, fn1]);
|
||||
}
|
||||
// Test getEventListeners on EventTarget
|
||||
{
|
||||
@@ -32,13 +29,13 @@ const { getEventListeners, EventEmitter } = require('events');
|
||||
target.addEventListener('foo', fn2);
|
||||
target.addEventListener('baz', fn1);
|
||||
target.addEventListener('baz', fn1);
|
||||
deepStrictEqual(getEventListeners(target, 'foo'), [fn1, fn2]);
|
||||
deepStrictEqual(getEventListeners(target, 'bar'), []);
|
||||
deepStrictEqual(getEventListeners(target, 'baz'), [fn1]);
|
||||
assert.deepStrictEqual(getEventListeners(target, 'foo'), [fn1, fn2]);
|
||||
assert.deepStrictEqual(getEventListeners(target, 'bar'), []);
|
||||
assert.deepStrictEqual(getEventListeners(target, 'baz'), [fn1]);
|
||||
}
|
||||
|
||||
{
|
||||
throws(() => {
|
||||
assert.throws(() => {
|
||||
getEventListeners('INVALID_EMITTER');
|
||||
}, /ERR_INVALID_ARG_TYPE/);
|
||||
}
|
||||
@@ -48,5 +45,5 @@ const { getEventListeners, EventEmitter } = require('events');
|
||||
const fn = common.mustNotCall();
|
||||
target.addEventListener('foo', fn, { [kWeakHandler]: {} });
|
||||
const listeners = getEventListeners(target, 'foo');
|
||||
deepStrictEqual(listeners, [fn]);
|
||||
assert.deepStrictEqual(listeners, [fn]);
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ const EventEmitter = require('events');
|
||||
// Tests that the error stack where the exception was thrown is *not* appended.
|
||||
|
||||
process.on('uncaughtException', common.mustCall((err) => {
|
||||
const lines = err.stack.split('\n');
|
||||
assert.strictEqual(lines[0], 'Error');
|
||||
lines.slice(1).forEach((line) => {
|
||||
const [firstLine, ...lines] = err.stack.split('\n');
|
||||
assert.strictEqual(firstLine, 'Error');
|
||||
lines.forEach((line) => {
|
||||
assert.match(line, /^ {4}at/);
|
||||
});
|
||||
}));
|
||||
|
||||
@@ -7,12 +7,7 @@ const {
|
||||
kWeakHandler,
|
||||
} = require('internal/event_target');
|
||||
|
||||
const {
|
||||
ok,
|
||||
deepStrictEqual,
|
||||
strictEqual,
|
||||
throws,
|
||||
} = require('assert');
|
||||
const assert = require('assert');
|
||||
|
||||
const { once } = require('events');
|
||||
|
||||
@@ -20,8 +15,8 @@ const { inspect } = require('util');
|
||||
const { setTimeout: delay } = require('timers/promises');
|
||||
|
||||
// The globals are defined.
|
||||
ok(Event);
|
||||
ok(EventTarget);
|
||||
assert.ok(Event);
|
||||
assert.ok(EventTarget);
|
||||
|
||||
// The warning event has special behavior regarding attaching listeners
|
||||
let lastWarning;
|
||||
@@ -37,23 +32,23 @@ let asyncTest = Promise.resolve();
|
||||
// First, test Event
|
||||
{
|
||||
const ev = new Event('foo');
|
||||
strictEqual(ev.type, 'foo');
|
||||
strictEqual(ev.cancelable, false);
|
||||
strictEqual(ev.defaultPrevented, false);
|
||||
strictEqual(typeof ev.timeStamp, 'number');
|
||||
assert.strictEqual(ev.type, 'foo');
|
||||
assert.strictEqual(ev.cancelable, false);
|
||||
assert.strictEqual(ev.defaultPrevented, false);
|
||||
assert.strictEqual(typeof ev.timeStamp, 'number');
|
||||
|
||||
// Compatibility properties with the DOM
|
||||
deepStrictEqual(ev.composedPath(), []);
|
||||
strictEqual(ev.returnValue, true);
|
||||
strictEqual(ev.bubbles, false);
|
||||
strictEqual(ev.composed, false);
|
||||
strictEqual(ev.isTrusted, false);
|
||||
strictEqual(ev.eventPhase, 0);
|
||||
strictEqual(ev.cancelBubble, false);
|
||||
assert.deepStrictEqual(ev.composedPath(), []);
|
||||
assert.strictEqual(ev.returnValue, true);
|
||||
assert.strictEqual(ev.bubbles, false);
|
||||
assert.strictEqual(ev.composed, false);
|
||||
assert.strictEqual(ev.isTrusted, false);
|
||||
assert.strictEqual(ev.eventPhase, 0);
|
||||
assert.strictEqual(ev.cancelBubble, false);
|
||||
|
||||
// Not cancelable
|
||||
ev.preventDefault();
|
||||
strictEqual(ev.defaultPrevented, false);
|
||||
assert.strictEqual(ev.defaultPrevented, false);
|
||||
}
|
||||
{
|
||||
[
|
||||
@@ -61,7 +56,7 @@ let asyncTest = Promise.resolve();
|
||||
1,
|
||||
false,
|
||||
].forEach((i) => (
|
||||
throws(() => new Event('foo', i), {
|
||||
assert.throws(() => new Event('foo', i), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
name: 'TypeError',
|
||||
message: 'The "options" argument must be of type object.' +
|
||||
@@ -71,82 +66,82 @@ let asyncTest = Promise.resolve();
|
||||
}
|
||||
{
|
||||
const ev = new Event('foo');
|
||||
strictEqual(ev.cancelBubble, false);
|
||||
assert.strictEqual(ev.cancelBubble, false);
|
||||
ev.cancelBubble = true;
|
||||
strictEqual(ev.cancelBubble, true);
|
||||
assert.strictEqual(ev.cancelBubble, true);
|
||||
}
|
||||
{
|
||||
const ev = new Event('foo');
|
||||
strictEqual(ev.cancelBubble, false);
|
||||
assert.strictEqual(ev.cancelBubble, false);
|
||||
ev.stopPropagation();
|
||||
strictEqual(ev.cancelBubble, true);
|
||||
assert.strictEqual(ev.cancelBubble, true);
|
||||
}
|
||||
{
|
||||
const ev = new Event('foo');
|
||||
strictEqual(ev.cancelBubble, false);
|
||||
assert.strictEqual(ev.cancelBubble, false);
|
||||
ev.cancelBubble = 'some-truthy-value';
|
||||
strictEqual(ev.cancelBubble, true);
|
||||
assert.strictEqual(ev.cancelBubble, true);
|
||||
}
|
||||
{
|
||||
// No argument behavior - throw TypeError
|
||||
throws(() => {
|
||||
assert.throws(() => {
|
||||
new Event();
|
||||
}, TypeError);
|
||||
// Too many arguments passed behavior - ignore additional arguments
|
||||
const ev = new Event('foo', {}, {});
|
||||
strictEqual(ev.type, 'foo');
|
||||
assert.strictEqual(ev.type, 'foo');
|
||||
}
|
||||
{
|
||||
const ev = new Event('foo');
|
||||
strictEqual(ev.cancelBubble, false);
|
||||
assert.strictEqual(ev.cancelBubble, false);
|
||||
ev.cancelBubble = true;
|
||||
strictEqual(ev.cancelBubble, true);
|
||||
assert.strictEqual(ev.cancelBubble, true);
|
||||
}
|
||||
{
|
||||
const ev = new Event('foo');
|
||||
strictEqual(ev.cancelBubble, false);
|
||||
assert.strictEqual(ev.cancelBubble, false);
|
||||
ev.stopPropagation();
|
||||
strictEqual(ev.cancelBubble, true);
|
||||
assert.strictEqual(ev.cancelBubble, true);
|
||||
}
|
||||
{
|
||||
const ev = new Event('foo');
|
||||
strictEqual(ev.cancelBubble, false);
|
||||
assert.strictEqual(ev.cancelBubble, false);
|
||||
ev.cancelBubble = 'some-truthy-value';
|
||||
strictEqual(ev.cancelBubble, true);
|
||||
assert.strictEqual(ev.cancelBubble, true);
|
||||
}
|
||||
{
|
||||
const ev = new Event('foo', { cancelable: true });
|
||||
strictEqual(ev.type, 'foo');
|
||||
strictEqual(ev.cancelable, true);
|
||||
strictEqual(ev.defaultPrevented, false);
|
||||
assert.strictEqual(ev.type, 'foo');
|
||||
assert.strictEqual(ev.cancelable, true);
|
||||
assert.strictEqual(ev.defaultPrevented, false);
|
||||
|
||||
ev.preventDefault();
|
||||
strictEqual(ev.defaultPrevented, true);
|
||||
throws(() => new Event(Symbol()), TypeError);
|
||||
assert.strictEqual(ev.defaultPrevented, true);
|
||||
assert.throws(() => new Event(Symbol()), TypeError);
|
||||
}
|
||||
{
|
||||
const ev = new Event('foo');
|
||||
strictEqual(ev.isTrusted, false);
|
||||
assert.strictEqual(ev.isTrusted, false);
|
||||
}
|
||||
{
|
||||
const eventTarget = new EventTarget();
|
||||
|
||||
const ev1 = common.mustCall(function(event) {
|
||||
strictEqual(event.type, 'foo');
|
||||
strictEqual(this, eventTarget);
|
||||
strictEqual(event.eventPhase, 2);
|
||||
assert.strictEqual(event.type, 'foo');
|
||||
assert.strictEqual(this, eventTarget);
|
||||
assert.strictEqual(event.eventPhase, 2);
|
||||
}, 2);
|
||||
|
||||
const ev2 = {
|
||||
handleEvent: common.mustCall(function(event) {
|
||||
strictEqual(event.type, 'foo');
|
||||
strictEqual(this, ev2);
|
||||
assert.strictEqual(event.type, 'foo');
|
||||
assert.strictEqual(this, ev2);
|
||||
}),
|
||||
};
|
||||
|
||||
eventTarget.addEventListener('foo', ev1);
|
||||
eventTarget.addEventListener('foo', ev2, { once: true });
|
||||
ok(eventTarget.dispatchEvent(new Event('foo')));
|
||||
assert.ok(eventTarget.dispatchEvent(new Event('foo')));
|
||||
eventTarget.dispatchEvent(new Event('foo'));
|
||||
|
||||
eventTarget.removeEventListener('foo', ev1);
|
||||
@@ -157,7 +152,7 @@ let asyncTest = Promise.resolve();
|
||||
const SubEvent = class extends Event {};
|
||||
const ev = new SubEvent('foo');
|
||||
const eventTarget = new EventTarget();
|
||||
const fn = common.mustCall((event) => strictEqual(event, ev));
|
||||
const fn = common.mustCall((event) => assert.strictEqual(event, ev));
|
||||
eventTarget.addEventListener('foo', fn, { once: true });
|
||||
eventTarget.dispatchEvent(ev);
|
||||
}
|
||||
@@ -169,27 +164,27 @@ let asyncTest = Promise.resolve();
|
||||
const eventTarget2 = new EventTarget();
|
||||
|
||||
eventTarget1.addEventListener('foo', common.mustCall((event) => {
|
||||
strictEqual(event.eventPhase, Event.AT_TARGET);
|
||||
strictEqual(event.target, eventTarget1);
|
||||
deepStrictEqual(event.composedPath(), [eventTarget1]);
|
||||
assert.strictEqual(event.eventPhase, Event.AT_TARGET);
|
||||
assert.strictEqual(event.target, eventTarget1);
|
||||
assert.deepStrictEqual(event.composedPath(), [eventTarget1]);
|
||||
}));
|
||||
|
||||
eventTarget2.addEventListener('foo', common.mustCall((event) => {
|
||||
strictEqual(event.eventPhase, Event.AT_TARGET);
|
||||
strictEqual(event.target, eventTarget2);
|
||||
deepStrictEqual(event.composedPath(), [eventTarget2]);
|
||||
assert.strictEqual(event.eventPhase, Event.AT_TARGET);
|
||||
assert.strictEqual(event.target, eventTarget2);
|
||||
assert.deepStrictEqual(event.composedPath(), [eventTarget2]);
|
||||
}));
|
||||
|
||||
eventTarget1.dispatchEvent(event);
|
||||
strictEqual(event.eventPhase, Event.NONE);
|
||||
strictEqual(event.target, eventTarget1);
|
||||
deepStrictEqual(event.composedPath(), []);
|
||||
assert.strictEqual(event.eventPhase, Event.NONE);
|
||||
assert.strictEqual(event.target, eventTarget1);
|
||||
assert.deepStrictEqual(event.composedPath(), []);
|
||||
|
||||
|
||||
eventTarget2.dispatchEvent(event);
|
||||
strictEqual(event.eventPhase, Event.NONE);
|
||||
strictEqual(event.target, eventTarget2);
|
||||
deepStrictEqual(event.composedPath(), []);
|
||||
assert.strictEqual(event.eventPhase, Event.NONE);
|
||||
assert.strictEqual(event.target, eventTarget2);
|
||||
assert.deepStrictEqual(event.composedPath(), []);
|
||||
}
|
||||
{
|
||||
// Same event dispatched multiple times, without listeners added.
|
||||
@@ -198,27 +193,27 @@ let asyncTest = Promise.resolve();
|
||||
const eventTarget2 = new EventTarget();
|
||||
|
||||
eventTarget1.dispatchEvent(event);
|
||||
strictEqual(event.eventPhase, Event.NONE);
|
||||
strictEqual(event.target, eventTarget1);
|
||||
deepStrictEqual(event.composedPath(), []);
|
||||
assert.strictEqual(event.eventPhase, Event.NONE);
|
||||
assert.strictEqual(event.target, eventTarget1);
|
||||
assert.deepStrictEqual(event.composedPath(), []);
|
||||
|
||||
eventTarget2.dispatchEvent(event);
|
||||
strictEqual(event.eventPhase, Event.NONE);
|
||||
strictEqual(event.target, eventTarget2);
|
||||
deepStrictEqual(event.composedPath(), []);
|
||||
assert.strictEqual(event.eventPhase, Event.NONE);
|
||||
assert.strictEqual(event.target, eventTarget2);
|
||||
assert.deepStrictEqual(event.composedPath(), []);
|
||||
}
|
||||
|
||||
{
|
||||
const eventTarget = new EventTarget();
|
||||
const event = new Event('foo', { cancelable: true });
|
||||
eventTarget.addEventListener('foo', (event) => event.preventDefault());
|
||||
ok(!eventTarget.dispatchEvent(event));
|
||||
assert.ok(!eventTarget.dispatchEvent(event));
|
||||
}
|
||||
{
|
||||
// Adding event listeners with a boolean useCapture
|
||||
const eventTarget = new EventTarget();
|
||||
const event = new Event('foo');
|
||||
const fn = common.mustCall((event) => strictEqual(event.type, 'foo'));
|
||||
const fn = common.mustCall((event) => assert.strictEqual(event.type, 'foo'));
|
||||
eventTarget.addEventListener('foo', fn, false);
|
||||
eventTarget.dispatchEvent(event);
|
||||
}
|
||||
@@ -227,7 +222,7 @@ let asyncTest = Promise.resolve();
|
||||
// The `options` argument can be `null`.
|
||||
const eventTarget = new EventTarget();
|
||||
const event = new Event('foo');
|
||||
const fn = common.mustCall((event) => strictEqual(event.type, 'foo'));
|
||||
const fn = common.mustCall((event) => assert.strictEqual(event.type, 'foo'));
|
||||
eventTarget.addEventListener('foo', fn, null);
|
||||
eventTarget.dispatchEvent(event);
|
||||
}
|
||||
@@ -239,8 +234,8 @@ let asyncTest = Promise.resolve();
|
||||
// defined on an EventListener.
|
||||
target.addEventListener('foo', listener);
|
||||
listener.handleEvent = common.mustCall(function(event) {
|
||||
strictEqual(event.type, 'foo');
|
||||
strictEqual(this, listener);
|
||||
assert.strictEqual(event.type, 'foo');
|
||||
assert.strictEqual(this, listener);
|
||||
});
|
||||
target.dispatchEvent(new Event('foo'));
|
||||
}
|
||||
@@ -258,8 +253,8 @@ let asyncTest = Promise.resolve();
|
||||
|
||||
{
|
||||
const uncaughtException = common.mustCall((err, origin) => {
|
||||
strictEqual(err.message, 'boom');
|
||||
strictEqual(origin, 'uncaughtException');
|
||||
assert.strictEqual(err.message, 'boom');
|
||||
assert.strictEqual(origin, 'uncaughtException');
|
||||
}, 4);
|
||||
|
||||
// Make sure that we no longer call 'error' on error.
|
||||
@@ -301,9 +296,9 @@ let asyncTest = Promise.resolve();
|
||||
|
||||
{
|
||||
// Coercion to string works
|
||||
strictEqual((new Event(1)).type, '1');
|
||||
strictEqual((new Event(false)).type, 'false');
|
||||
strictEqual((new Event({})).type, String({}));
|
||||
assert.strictEqual((new Event(1)).type, '1');
|
||||
assert.strictEqual((new Event(false)).type, 'false');
|
||||
assert.strictEqual((new Event({})).type, String({}));
|
||||
|
||||
const target = new EventTarget();
|
||||
|
||||
@@ -314,7 +309,7 @@ let asyncTest = Promise.resolve();
|
||||
1,
|
||||
false,
|
||||
].forEach((i) => {
|
||||
throws(() => target.dispatchEvent(i), {
|
||||
assert.throws(() => target.dispatchEvent(i), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
name: 'TypeError',
|
||||
message: 'The "event" argument must be an instance of Event.' +
|
||||
@@ -333,7 +328,7 @@ let asyncTest = Promise.resolve();
|
||||
'foo',
|
||||
1,
|
||||
false,
|
||||
].forEach((i) => throws(() => target.addEventListener('foo', i), err(i)));
|
||||
].forEach((i) => assert.throws(() => target.addEventListener('foo', i), err(i)));
|
||||
}
|
||||
|
||||
{
|
||||
@@ -345,9 +340,9 @@ let asyncTest = Promise.resolve();
|
||||
{
|
||||
const target = new EventTarget();
|
||||
const event = new Event('foo');
|
||||
strictEqual(event.cancelBubble, false);
|
||||
assert.strictEqual(event.cancelBubble, false);
|
||||
event.stopImmediatePropagation();
|
||||
strictEqual(event.cancelBubble, true);
|
||||
assert.strictEqual(event.cancelBubble, true);
|
||||
target.addEventListener('foo', common.mustNotCall());
|
||||
target.dispatchEvent(event);
|
||||
}
|
||||
@@ -375,11 +370,11 @@ let asyncTest = Promise.resolve();
|
||||
{
|
||||
const target = new EventTarget();
|
||||
const event = new Event('foo');
|
||||
strictEqual(event.target, null);
|
||||
assert.strictEqual(event.target, null);
|
||||
target.addEventListener('foo', common.mustCall((event) => {
|
||||
strictEqual(event.target, target);
|
||||
strictEqual(event.currentTarget, target);
|
||||
strictEqual(event.srcElement, target);
|
||||
assert.strictEqual(event.target, target);
|
||||
assert.strictEqual(event.currentTarget, target);
|
||||
assert.strictEqual(event.srcElement, target);
|
||||
}));
|
||||
target.dispatchEvent(event);
|
||||
}
|
||||
@@ -389,7 +384,7 @@ let asyncTest = Promise.resolve();
|
||||
const target2 = new EventTarget();
|
||||
const event = new Event('foo');
|
||||
target1.addEventListener('foo', common.mustCall((event) => {
|
||||
throws(() => target2.dispatchEvent(event), {
|
||||
assert.throws(() => target2.dispatchEvent(event), {
|
||||
code: 'ERR_EVENT_RECURSION',
|
||||
});
|
||||
}));
|
||||
@@ -423,9 +418,9 @@ let asyncTest = Promise.resolve();
|
||||
}
|
||||
{
|
||||
const target = new EventTarget();
|
||||
strictEqual(target.toString(), '[object EventTarget]');
|
||||
assert.strictEqual(target.toString(), '[object EventTarget]');
|
||||
const event = new Event('');
|
||||
strictEqual(event.toString(), '[object Event]');
|
||||
assert.strictEqual(event.toString(), '[object Event]');
|
||||
}
|
||||
{
|
||||
const target = new EventTarget();
|
||||
@@ -437,7 +432,7 @@ let asyncTest = Promise.resolve();
|
||||
{
|
||||
const target = new EventTarget();
|
||||
defineEventHandler(target, 'foo');
|
||||
strictEqual(target.onfoo, null);
|
||||
assert.strictEqual(target.onfoo, null);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -447,7 +442,7 @@ let asyncTest = Promise.resolve();
|
||||
target.onfoo = () => count++;
|
||||
target.onfoo = common.mustCall(() => count++);
|
||||
target.dispatchEvent(new Event('foo'));
|
||||
strictEqual(count, 1);
|
||||
assert.strictEqual(count, 1);
|
||||
}
|
||||
{
|
||||
const target = new EventTarget();
|
||||
@@ -456,14 +451,14 @@ let asyncTest = Promise.resolve();
|
||||
target.addEventListener('foo', () => count++);
|
||||
target.onfoo = common.mustCall(() => count++);
|
||||
target.dispatchEvent(new Event('foo'));
|
||||
strictEqual(count, 2);
|
||||
assert.strictEqual(count, 2);
|
||||
}
|
||||
{
|
||||
const target = new EventTarget();
|
||||
defineEventHandler(target, 'foo');
|
||||
const fn = common.mustNotCall();
|
||||
target.onfoo = fn;
|
||||
strictEqual(target.onfoo, fn);
|
||||
assert.strictEqual(target.onfoo, fn);
|
||||
target.onfoo = null;
|
||||
target.dispatchEvent(new Event('foo'));
|
||||
}
|
||||
@@ -474,7 +469,7 @@ let asyncTest = Promise.resolve();
|
||||
const target2 = new EventTarget();
|
||||
const event = new Event('foo');
|
||||
|
||||
ok(target.dispatchEvent.call(target2, event));
|
||||
assert.ok(target.dispatchEvent.call(target2, event));
|
||||
|
||||
[
|
||||
'foo',
|
||||
@@ -487,7 +482,7 @@ let asyncTest = Promise.resolve();
|
||||
Symbol(),
|
||||
/a/,
|
||||
].forEach((i) => {
|
||||
throws(() => target.dispatchEvent.call(i, event), {
|
||||
assert.throws(() => target.dispatchEvent.call(i, event), {
|
||||
code: 'ERR_INVALID_THIS',
|
||||
});
|
||||
});
|
||||
@@ -495,31 +490,31 @@ let asyncTest = Promise.resolve();
|
||||
|
||||
{
|
||||
// Event Statics
|
||||
strictEqual(Event.NONE, 0);
|
||||
strictEqual(Event.CAPTURING_PHASE, 1);
|
||||
strictEqual(Event.AT_TARGET, 2);
|
||||
strictEqual(Event.BUBBLING_PHASE, 3);
|
||||
strictEqual(new Event('foo').eventPhase, Event.NONE);
|
||||
assert.strictEqual(Event.NONE, 0);
|
||||
assert.strictEqual(Event.CAPTURING_PHASE, 1);
|
||||
assert.strictEqual(Event.AT_TARGET, 2);
|
||||
assert.strictEqual(Event.BUBBLING_PHASE, 3);
|
||||
assert.strictEqual(new Event('foo').eventPhase, Event.NONE);
|
||||
const target = new EventTarget();
|
||||
target.addEventListener('foo', common.mustCall((e) => {
|
||||
strictEqual(e.eventPhase, Event.AT_TARGET);
|
||||
assert.strictEqual(e.eventPhase, Event.AT_TARGET);
|
||||
}), { once: true });
|
||||
target.dispatchEvent(new Event('foo'));
|
||||
// Event is a function
|
||||
strictEqual(Event.length, 1);
|
||||
assert.strictEqual(Event.length, 1);
|
||||
}
|
||||
|
||||
{
|
||||
const target = new EventTarget();
|
||||
const ev = new Event('toString');
|
||||
const fn = common.mustCall((event) => strictEqual(event.type, 'toString'));
|
||||
const fn = common.mustCall((event) => assert.strictEqual(event.type, 'toString'));
|
||||
target.addEventListener('toString', fn);
|
||||
target.dispatchEvent(ev);
|
||||
}
|
||||
{
|
||||
const target = new EventTarget();
|
||||
const ev = new Event('__proto__');
|
||||
const fn = common.mustCall((event) => strictEqual(event.type, '__proto__'));
|
||||
const fn = common.mustCall((event) => assert.strictEqual(event.type, '__proto__'));
|
||||
target.addEventListener('__proto__', fn);
|
||||
target.dispatchEvent(ev);
|
||||
}
|
||||
@@ -527,20 +522,20 @@ let asyncTest = Promise.resolve();
|
||||
{
|
||||
const eventTarget = new EventTarget();
|
||||
// Single argument throws
|
||||
throws(() => eventTarget.addEventListener('foo'), TypeError);
|
||||
assert.throws(() => eventTarget.addEventListener('foo'), TypeError);
|
||||
// Null events - does not throw
|
||||
eventTarget.addEventListener('foo', null);
|
||||
eventTarget.removeEventListener('foo', null);
|
||||
eventTarget.addEventListener('foo', undefined);
|
||||
eventTarget.removeEventListener('foo', undefined);
|
||||
// Strings, booleans
|
||||
throws(() => eventTarget.addEventListener('foo', 'hello'), TypeError);
|
||||
throws(() => eventTarget.addEventListener('foo', false), TypeError);
|
||||
throws(() => eventTarget.addEventListener('foo', Symbol()), TypeError);
|
||||
assert.throws(() => eventTarget.addEventListener('foo', 'hello'), TypeError);
|
||||
assert.throws(() => eventTarget.addEventListener('foo', false), TypeError);
|
||||
assert.throws(() => eventTarget.addEventListener('foo', Symbol()), TypeError);
|
||||
asyncTest = asyncTest.then(async () => {
|
||||
const eventTarget = new EventTarget();
|
||||
// Single argument throws
|
||||
throws(() => eventTarget.addEventListener('foo'), TypeError);
|
||||
assert.throws(() => eventTarget.addEventListener('foo'), TypeError);
|
||||
// Null events - does not throw
|
||||
|
||||
eventTarget.addEventListener('foo', null);
|
||||
@@ -548,34 +543,34 @@ let asyncTest = Promise.resolve();
|
||||
|
||||
// Warnings always happen after nextTick, so wait for a timer of 0
|
||||
await delay(0);
|
||||
strictEqual(lastWarning.name, 'AddEventListenerArgumentTypeWarning');
|
||||
strictEqual(lastWarning.target, eventTarget);
|
||||
assert.strictEqual(lastWarning.name, 'AddEventListenerArgumentTypeWarning');
|
||||
assert.strictEqual(lastWarning.target, eventTarget);
|
||||
lastWarning = null;
|
||||
eventTarget.addEventListener('foo', undefined);
|
||||
await delay(0);
|
||||
strictEqual(lastWarning.name, 'AddEventListenerArgumentTypeWarning');
|
||||
strictEqual(lastWarning.target, eventTarget);
|
||||
assert.strictEqual(lastWarning.name, 'AddEventListenerArgumentTypeWarning');
|
||||
assert.strictEqual(lastWarning.target, eventTarget);
|
||||
eventTarget.removeEventListener('foo', undefined);
|
||||
// Strings, booleans
|
||||
throws(() => eventTarget.addEventListener('foo', 'hello'), TypeError);
|
||||
throws(() => eventTarget.addEventListener('foo', false), TypeError);
|
||||
throws(() => eventTarget.addEventListener('foo', Symbol()), TypeError);
|
||||
assert.throws(() => eventTarget.addEventListener('foo', 'hello'), TypeError);
|
||||
assert.throws(() => eventTarget.addEventListener('foo', false), TypeError);
|
||||
assert.throws(() => eventTarget.addEventListener('foo', Symbol()), TypeError);
|
||||
});
|
||||
}
|
||||
{
|
||||
const eventTarget = new EventTarget();
|
||||
const event = new Event('foo');
|
||||
eventTarget.dispatchEvent(event);
|
||||
strictEqual(event.target, eventTarget);
|
||||
assert.strictEqual(event.target, eventTarget);
|
||||
}
|
||||
{
|
||||
// Event target exported keys
|
||||
const eventTarget = new EventTarget();
|
||||
deepStrictEqual(Object.keys(eventTarget), []);
|
||||
deepStrictEqual(Object.getOwnPropertyNames(eventTarget), []);
|
||||
assert.deepStrictEqual(Object.keys(eventTarget), []);
|
||||
assert.deepStrictEqual(Object.getOwnPropertyNames(eventTarget), []);
|
||||
const parentKeys = Object.keys(Object.getPrototypeOf(eventTarget)).sort();
|
||||
const keys = ['addEventListener', 'dispatchEvent', 'removeEventListener'];
|
||||
deepStrictEqual(parentKeys, keys);
|
||||
assert.deepStrictEqual(parentKeys, keys);
|
||||
}
|
||||
{
|
||||
// Subclassing
|
||||
@@ -589,11 +584,11 @@ let asyncTest = Promise.resolve();
|
||||
const target = new EventTarget();
|
||||
let state = 0;
|
||||
target.addEventListener('foo', common.mustCall(() => {
|
||||
strictEqual(state, 0);
|
||||
assert.strictEqual(state, 0);
|
||||
state++;
|
||||
}));
|
||||
target.addEventListener('foo', common.mustCall(() => {
|
||||
strictEqual(state, 1);
|
||||
assert.strictEqual(state, 1);
|
||||
}));
|
||||
target.dispatchEvent(new Event('foo'));
|
||||
}
|
||||
@@ -601,8 +596,8 @@ let asyncTest = Promise.resolve();
|
||||
const target = new EventTarget();
|
||||
defineEventHandler(target, 'foo');
|
||||
const descriptor = Object.getOwnPropertyDescriptor(target, 'onfoo');
|
||||
strictEqual(descriptor.configurable, true);
|
||||
strictEqual(descriptor.enumerable, true);
|
||||
assert.strictEqual(descriptor.configurable, true);
|
||||
assert.strictEqual(descriptor.enumerable, true);
|
||||
}
|
||||
{
|
||||
const target = new EventTarget();
|
||||
@@ -614,7 +609,7 @@ let asyncTest = Promise.resolve();
|
||||
target.onfoo = () => output.push(2);
|
||||
target.addEventListener('foo', () => output.push(4));
|
||||
target.dispatchEvent(new Event('foo'));
|
||||
deepStrictEqual(output, [1, 2, 3, 4]);
|
||||
assert.deepStrictEqual(output, [1, 2, 3, 4]);
|
||||
}
|
||||
{
|
||||
const target = new EventTarget();
|
||||
@@ -623,7 +618,7 @@ let asyncTest = Promise.resolve();
|
||||
target.addEventListener('bar', () => output.push(1));
|
||||
target.onfoo = () => output.push(2);
|
||||
target.dispatchEvent(new Event('bar'));
|
||||
deepStrictEqual(output, [1, 2]);
|
||||
assert.deepStrictEqual(output, [1, 2]);
|
||||
}
|
||||
{
|
||||
const et = new EventTarget();
|
||||
@@ -640,12 +635,12 @@ let asyncTest = Promise.resolve();
|
||||
const evConstructorName = inspect(ev, {
|
||||
depth: -1,
|
||||
});
|
||||
strictEqual(evConstructorName, 'Event');
|
||||
assert.strictEqual(evConstructorName, 'Event');
|
||||
|
||||
const inspectResult = inspect(ev, {
|
||||
depth: 1,
|
||||
});
|
||||
ok(inspectResult.includes('Event'));
|
||||
assert.ok(inspectResult.includes('Event'));
|
||||
}
|
||||
|
||||
{
|
||||
@@ -653,15 +648,15 @@ let asyncTest = Promise.resolve();
|
||||
const inspectResult = inspect(et, {
|
||||
depth: 1,
|
||||
});
|
||||
ok(inspectResult.includes('EventTarget'));
|
||||
assert.ok(inspectResult.includes('EventTarget'));
|
||||
}
|
||||
|
||||
{
|
||||
const ev = new Event('test');
|
||||
strictEqual(ev.constructor.name, 'Event');
|
||||
assert.strictEqual(ev.constructor.name, 'Event');
|
||||
|
||||
const et = new EventTarget();
|
||||
strictEqual(et.constructor.name, 'EventTarget');
|
||||
assert.strictEqual(et.constructor.name, 'EventTarget');
|
||||
}
|
||||
{
|
||||
// Weak event listeners work
|
||||
@@ -691,27 +686,27 @@ let asyncTest = Promise.resolve();
|
||||
{
|
||||
const et = new EventTarget();
|
||||
|
||||
throws(() => et.addEventListener(), {
|
||||
assert.throws(() => et.addEventListener(), {
|
||||
code: 'ERR_MISSING_ARGS',
|
||||
name: 'TypeError',
|
||||
});
|
||||
|
||||
throws(() => et.addEventListener('foo'), {
|
||||
assert.throws(() => et.addEventListener('foo'), {
|
||||
code: 'ERR_MISSING_ARGS',
|
||||
name: 'TypeError',
|
||||
});
|
||||
|
||||
throws(() => et.removeEventListener(), {
|
||||
assert.throws(() => et.removeEventListener(), {
|
||||
code: 'ERR_MISSING_ARGS',
|
||||
name: 'TypeError',
|
||||
});
|
||||
|
||||
throws(() => et.removeEventListener('foo'), {
|
||||
assert.throws(() => et.removeEventListener('foo'), {
|
||||
code: 'ERR_MISSING_ARGS',
|
||||
name: 'TypeError',
|
||||
});
|
||||
|
||||
throws(() => et.dispatchEvent(), {
|
||||
assert.throws(() => et.dispatchEvent(), {
|
||||
code: 'ERR_MISSING_ARGS',
|
||||
name: 'TypeError',
|
||||
});
|
||||
@@ -720,11 +715,11 @@ let asyncTest = Promise.resolve();
|
||||
{
|
||||
const et = new EventTarget();
|
||||
|
||||
throws(() => {
|
||||
assert.throws(() => {
|
||||
et.addEventListener(Symbol('symbol'), () => {});
|
||||
}, TypeError);
|
||||
|
||||
throws(() => {
|
||||
assert.throws(() => {
|
||||
et.removeEventListener(Symbol('symbol'), () => {});
|
||||
}, TypeError);
|
||||
}
|
||||
@@ -743,9 +738,9 @@ let asyncTest = Promise.resolve();
|
||||
|
||||
{
|
||||
const event = new Event('foo');
|
||||
strictEqual(event.cancelBubble, false);
|
||||
assert.strictEqual(event.cancelBubble, false);
|
||||
event.cancelBubble = true;
|
||||
strictEqual(event.cancelBubble, true);
|
||||
assert.strictEqual(event.cancelBubble, true);
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -2,11 +2,7 @@
|
||||
|
||||
const common = require('../common');
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
const {
|
||||
ok,
|
||||
strictEqual,
|
||||
throws,
|
||||
} = require('node:assert');
|
||||
const assert = require('node:assert');
|
||||
const {
|
||||
openSync,
|
||||
readFile,
|
||||
@@ -33,13 +29,13 @@ function getTempFile() {
|
||||
const stream = new Utf8Stream({ fd, sync: false });
|
||||
|
||||
// Test successful write
|
||||
ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
stream.destroy();
|
||||
|
||||
throws(() => stream.write('hello world\n'), Error);
|
||||
assert.throws(() => stream.write('hello world\n'), Error);
|
||||
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\n');
|
||||
assert.strictEqual(data, 'hello world\n');
|
||||
}));
|
||||
|
||||
stream.on('finish', common.mustNotCall());
|
||||
@@ -51,12 +47,12 @@ function getTempFile() {
|
||||
const fd = openSync(dest, 'w');
|
||||
const stream = new Utf8Stream({ fd, sync: true });
|
||||
|
||||
ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
stream.destroy();
|
||||
throws(() => stream.write('hello world\n'), Error);
|
||||
assert.throws(() => stream.write('hello world\n'), Error);
|
||||
|
||||
const data = readFileSync(dest, 'utf8');
|
||||
strictEqual(data, 'hello world\n');
|
||||
assert.strictEqual(data, 'hello world\n');
|
||||
};
|
||||
|
||||
{
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
|
||||
const common = require('../common');
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
const {
|
||||
strictEqual,
|
||||
} = require('node:assert');
|
||||
const assert = require('node:assert');
|
||||
const fs = require('node:fs');
|
||||
const { Utf8Stream } = require('node:fs');
|
||||
const { join } = require('node:path');
|
||||
@@ -35,7 +33,7 @@ function runTests(sync) {
|
||||
stream.write('after reopen\n');
|
||||
stream.on('finish', common.mustCall(() => {
|
||||
fs.readFile(after, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'after reopen\n');
|
||||
assert.strictEqual(data, 'after reopen\n');
|
||||
}));
|
||||
}));
|
||||
stream.end();
|
||||
@@ -53,7 +51,7 @@ function runTests(sync) {
|
||||
stream.write('after reopen\n');
|
||||
stream.on('finish', common.mustCall(() => {
|
||||
fs.readFile(after, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'after reopen\n');
|
||||
assert.strictEqual(data, 'after reopen\n');
|
||||
}));
|
||||
}));
|
||||
stream.end();
|
||||
@@ -69,7 +67,7 @@ function runTests(sync) {
|
||||
stream.write('after reopen\n');
|
||||
stream.on('finish', common.mustCall(() => {
|
||||
fs.readFile(after, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'after reopen\n');
|
||||
assert.strictEqual(data, 'after reopen\n');
|
||||
}));
|
||||
}));
|
||||
|
||||
@@ -102,8 +100,8 @@ function runTests(sync) {
|
||||
|
||||
stream.on('finish', common.mustCall(() => {
|
||||
fs.readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data.length, 10000);
|
||||
strictEqual(data, str);
|
||||
assert.strictEqual(data.length, 10000);
|
||||
assert.strictEqual(data, str);
|
||||
}));
|
||||
}));
|
||||
|
||||
|
||||
@@ -2,10 +2,7 @@
|
||||
|
||||
const common = require('../common');
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
const {
|
||||
ok,
|
||||
strictEqual,
|
||||
} = require('node:assert');
|
||||
const assert = require('node:assert');
|
||||
const {
|
||||
openSync,
|
||||
fsyncSync,
|
||||
@@ -57,7 +54,7 @@ function runTests(sync) {
|
||||
});
|
||||
|
||||
stream.on('ready', common.mustCall(() => {
|
||||
ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
|
||||
stream.flush(common.mustSucceed(() => stream.end()));
|
||||
}));
|
||||
@@ -94,10 +91,10 @@ function runTests(sync) {
|
||||
});
|
||||
|
||||
stream.on('ready', common.mustCall(() => {
|
||||
ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
stream.flush(common.mustCall((err) => {
|
||||
ok(err, 'flush should return an error');
|
||||
strictEqual(err.code, 'ETEST');
|
||||
assert.ok(err, 'flush should return an error');
|
||||
assert.strictEqual(err.code, 'ETEST');
|
||||
stream.end();
|
||||
}));
|
||||
}));
|
||||
|
||||
@@ -2,11 +2,7 @@
|
||||
|
||||
const common = require('../common');
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
const {
|
||||
ok,
|
||||
strictEqual,
|
||||
throws,
|
||||
} = require('node:assert');
|
||||
const assert = require('node:assert');
|
||||
const {
|
||||
openSync,
|
||||
readFile,
|
||||
@@ -37,15 +33,15 @@ function runTests(sync) {
|
||||
const fd = openSync(dest, 'w');
|
||||
const stream = new Utf8Stream({ fd, minLength: 4096, sync });
|
||||
|
||||
ok(stream.write('hello world\n'));
|
||||
ok(stream.write('something else\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('something else\n'));
|
||||
|
||||
stream.flushSync();
|
||||
|
||||
setImmediate(common.mustCall(() => {
|
||||
stream.end();
|
||||
const data = readFileSync(dest, 'utf8');
|
||||
strictEqual(data, 'hello world\nsomething else\n');
|
||||
assert.strictEqual(data, 'hello world\nsomething else\n');
|
||||
stream.on('close', common.mustCall());
|
||||
}));
|
||||
}
|
||||
@@ -76,14 +72,14 @@ function runTests(sync) {
|
||||
});
|
||||
|
||||
stream.on('ready', common.mustCall(() => {
|
||||
ok(stream.write('hello world\n'));
|
||||
ok(stream.write('something else\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('something else\n'));
|
||||
stream.flushSync();
|
||||
stream.end();
|
||||
|
||||
stream.on('finish', common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\nsomething else\n');
|
||||
assert.strictEqual(data, 'hello world\nsomething else\n');
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
@@ -112,27 +108,27 @@ function runTests(sync) {
|
||||
fd,
|
||||
sync: false,
|
||||
minLength: 1000,
|
||||
retryEAGAIN: (err, writeBufferLen, remainingBufferLen) => {
|
||||
retryEAGAIN: common.mustCall((err, writeBufferLen, remainingBufferLen) => {
|
||||
retryCallCount++;
|
||||
strictEqual(err.code, 'EAGAIN');
|
||||
strictEqual(writeBufferLen, 12);
|
||||
strictEqual(remainingBufferLen, 0);
|
||||
assert.strictEqual(err.code, 'EAGAIN');
|
||||
assert.strictEqual(writeBufferLen, 12);
|
||||
assert.strictEqual(remainingBufferLen, 0);
|
||||
return false; // Don't retry
|
||||
},
|
||||
}),
|
||||
fs: fsOverride,
|
||||
});
|
||||
|
||||
stream.on('ready', common.mustCall(() => {
|
||||
ok(stream.write('hello world\n'));
|
||||
throws(() => stream.flushSync(), err);
|
||||
ok(stream.write('something else\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
assert.throws(() => stream.flushSync(), err);
|
||||
assert.ok(stream.write('something else\n'));
|
||||
stream.flushSync();
|
||||
stream.end();
|
||||
|
||||
stream.on('finish', common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\nsomething else\n');
|
||||
strictEqual(retryCallCount, 1);
|
||||
assert.strictEqual(data, 'hello world\nsomething else\n');
|
||||
assert.strictEqual(retryCallCount, 1);
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
|
||||
@@ -2,10 +2,7 @@
|
||||
|
||||
const common = require('../common');
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
const {
|
||||
ok,
|
||||
strictEqual,
|
||||
} = require('node:assert');
|
||||
const assert = require('node:assert');
|
||||
const {
|
||||
openSync,
|
||||
readFile,
|
||||
@@ -34,17 +31,17 @@ function runTests(sync) {
|
||||
writeFileSync(dest, 'hello world\n');
|
||||
const stream = new Utf8Stream({ dest, append: false, sync });
|
||||
|
||||
stream.on('ready', () => {
|
||||
ok(stream.write('something else\n'));
|
||||
stream.on('ready', common.mustCall(() => {
|
||||
assert.ok(stream.write('something else\n'));
|
||||
stream.flush();
|
||||
|
||||
stream.on('drain', common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'something else\n');
|
||||
assert.strictEqual(data, 'something else\n');
|
||||
stream.end();
|
||||
}));
|
||||
}));
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
@@ -52,12 +49,12 @@ function runTests(sync) {
|
||||
const stream = new Utf8Stream({ dest, mkdir: true, sync });
|
||||
|
||||
stream.on('ready', common.mustCall(() => {
|
||||
ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
stream.flush();
|
||||
|
||||
stream.on('drain', common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\n');
|
||||
assert.strictEqual(data, 'hello world\n');
|
||||
stream.end();
|
||||
}));
|
||||
}));
|
||||
@@ -70,13 +67,13 @@ function runTests(sync) {
|
||||
const stream = new Utf8Stream({ fd, minLength: 4096, sync });
|
||||
|
||||
stream.on('ready', common.mustCall(() => {
|
||||
ok(stream.write('hello world\n'));
|
||||
ok(stream.write('something else\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('something else\n'));
|
||||
stream.flush();
|
||||
|
||||
stream.on('drain', common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\nsomething else\n');
|
||||
assert.strictEqual(data, 'hello world\nsomething else\n');
|
||||
stream.end();
|
||||
}));
|
||||
}));
|
||||
@@ -102,8 +99,8 @@ function runTests(sync) {
|
||||
const stream = new Utf8Stream({ fd, minLength: 4096, sync });
|
||||
|
||||
stream.on('ready', common.mustCall(() => {
|
||||
ok(stream.write('hello world\n'));
|
||||
ok(stream.write('something else\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('something else\n'));
|
||||
|
||||
stream.flush(common.mustSucceed(() => {
|
||||
stream.end();
|
||||
@@ -137,6 +134,6 @@ function runTests(sync) {
|
||||
const fd = openSync(dest, 'w');
|
||||
const stream = new Utf8Stream({ fd, minLength: 4096, sync });
|
||||
stream.destroy();
|
||||
stream.flush(common.mustCall(ok));
|
||||
stream.flush(common.mustCall(assert.ok));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,7 @@
|
||||
|
||||
const common = require('../common');
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
const {
|
||||
ok,
|
||||
strictEqual,
|
||||
} = require('node:assert');
|
||||
const assert = require('node:assert');
|
||||
const {
|
||||
fsyncSync,
|
||||
openSync,
|
||||
@@ -40,12 +37,12 @@ function getTempFile() {
|
||||
},
|
||||
});
|
||||
|
||||
ok(stream.write('hello world\n'));
|
||||
ok(stream.write('something else\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('something else\n'));
|
||||
stream.end();
|
||||
|
||||
const data = readFileSync(dest, 'utf8');
|
||||
strictEqual(data, 'hello world\nsomething else\n');
|
||||
assert.strictEqual(data, 'hello world\nsomething else\n');
|
||||
}
|
||||
|
||||
{
|
||||
@@ -60,13 +57,13 @@ function getTempFile() {
|
||||
}
|
||||
});
|
||||
|
||||
ok(stream.write('hello world\n'));
|
||||
ok(stream.write('something else\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('something else\n'));
|
||||
stream.end();
|
||||
|
||||
stream.on('finish', common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\nsomething else\n');
|
||||
assert.strictEqual(data, 'hello world\nsomething else\n');
|
||||
}));
|
||||
}));
|
||||
|
||||
|
||||
@@ -2,10 +2,7 @@
|
||||
|
||||
const common = require('../common');
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
const {
|
||||
ok,
|
||||
throws,
|
||||
} = require('node:assert');
|
||||
const assert = require('node:assert');
|
||||
const {
|
||||
closeSync,
|
||||
openSync,
|
||||
@@ -26,9 +23,9 @@ const MAX_WRITE = 16 * 1024;
|
||||
const dest = getTempFile();
|
||||
const stream = new Utf8Stream({ dest, sync: false, minLength: 9999 });
|
||||
|
||||
ok(stream.write(Buffer.alloc(1500).fill('x').toString()));
|
||||
ok(stream.write(Buffer.alloc(1500).fill('x').toString()));
|
||||
ok(!stream.write(Buffer.alloc(MAX_WRITE).fill('x').toString()));
|
||||
assert.ok(stream.write(Buffer.alloc(1500).fill('x').toString()));
|
||||
assert.ok(stream.write(Buffer.alloc(1500).fill('x').toString()));
|
||||
assert.ok(!stream.write(Buffer.alloc(MAX_WRITE).fill('x').toString()));
|
||||
|
||||
stream.on('drain', common.mustCall(() => stream.end()));
|
||||
|
||||
@@ -38,7 +35,7 @@ const MAX_WRITE = 16 * 1024;
|
||||
const dest = getTempFile();
|
||||
const fd = openSync(dest, 'w');
|
||||
|
||||
throws(() => {
|
||||
assert.throws(() => {
|
||||
new Utf8Stream({
|
||||
fd,
|
||||
minLength: MAX_WRITE
|
||||
|
||||
@@ -2,10 +2,7 @@
|
||||
|
||||
const common = require('../common');
|
||||
const tmpdir = require('../common/tmpdir'); ;
|
||||
const {
|
||||
ok,
|
||||
strictEqual,
|
||||
} = require('node:assert');
|
||||
const assert = require('node:assert');
|
||||
const {
|
||||
readFile,
|
||||
statSync,
|
||||
@@ -39,17 +36,17 @@ function runTests(sync) {
|
||||
const stream = new Utf8Stream({ dest, sync, mode });
|
||||
|
||||
stream.on('ready', common.mustCall(() => {
|
||||
ok(stream.write('hello world\n'));
|
||||
ok(stream.write('something else\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('something else\n'));
|
||||
|
||||
stream.end();
|
||||
|
||||
stream.on('finish', common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\nsomething else\n');
|
||||
assert.strictEqual(data, 'hello world\nsomething else\n');
|
||||
// The actual mode may vary depending on the platform,
|
||||
// so we check only the first bit.
|
||||
strictEqual(statSync(dest).mode & 0o700, 0o600);
|
||||
assert.strictEqual(statSync(dest).mode & 0o700, 0o600);
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
@@ -60,15 +57,15 @@ function runTests(sync) {
|
||||
const defaultMode = 0o600;
|
||||
const stream = new Utf8Stream({ dest, sync });
|
||||
stream.on('ready', common.mustCall(() => {
|
||||
ok(stream.write('hello world\n'));
|
||||
ok(stream.write('something else\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('something else\n'));
|
||||
|
||||
stream.end();
|
||||
|
||||
stream.on('finish', common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\nsomething else\n');
|
||||
strictEqual(statSync(dest).mode & 0o700, defaultMode);
|
||||
assert.strictEqual(data, 'hello world\nsomething else\n');
|
||||
assert.strictEqual(statSync(dest).mode & 0o700, defaultMode);
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
@@ -80,11 +77,11 @@ function runTests(sync) {
|
||||
const stream = new Utf8Stream({ dest, mkdir: true, mode, sync });
|
||||
|
||||
stream.on('ready', common.mustCall(() => {
|
||||
ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
stream.flush();
|
||||
stream.on('drain', common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\n');
|
||||
assert.strictEqual(data, 'hello world\n');
|
||||
stream.end();
|
||||
}));
|
||||
}));
|
||||
@@ -98,11 +95,11 @@ function runTests(sync) {
|
||||
const mode = isWindows ? 0o444 : 0o666;
|
||||
const stream = new Utf8Stream({ dest, append: false, mode, sync });
|
||||
stream.on('ready', common.mustCall(() => {
|
||||
ok(stream.write('something else\n'));
|
||||
assert.ok(stream.write('something else\n'));
|
||||
stream.flush();
|
||||
stream.on('drain', common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'something else\n');
|
||||
assert.strictEqual(data, 'something else\n');
|
||||
stream.end();
|
||||
}));
|
||||
}));
|
||||
|
||||
@@ -2,10 +2,7 @@
|
||||
|
||||
const common = require('../common');
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
const {
|
||||
ok,
|
||||
strictEqual,
|
||||
} = require('node:assert');
|
||||
const assert = require('node:assert');
|
||||
const {
|
||||
openSync,
|
||||
readFile,
|
||||
@@ -34,11 +31,11 @@ function runTests(sync) {
|
||||
const fd = openSync(dest, 'w');
|
||||
const stream = new Utf8Stream({ fd, sync, minLength: 5000 });
|
||||
|
||||
ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
|
||||
setTimeout(common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, '');
|
||||
assert.strictEqual(data, '');
|
||||
}));
|
||||
}), 1500);
|
||||
|
||||
@@ -51,12 +48,12 @@ function runTests(sync) {
|
||||
|
||||
// Test that periodicFlush property is set correctly
|
||||
const stream1 = new Utf8Stream({ fd, sync, minLength: 5000 });
|
||||
strictEqual(stream1.periodicFlush, 0);
|
||||
assert.strictEqual(stream1.periodicFlush, 0);
|
||||
stream1.destroy();
|
||||
|
||||
const fd2 = openSync(dest, 'w');
|
||||
const stream2 = new Utf8Stream({ fd: fd2, sync, minLength: 5000, periodicFlush: 1000 });
|
||||
strictEqual(stream2.periodicFlush, 1000);
|
||||
assert.strictEqual(stream2.periodicFlush, 1000);
|
||||
stream2.destroy();
|
||||
}
|
||||
|
||||
@@ -65,14 +62,14 @@ function runTests(sync) {
|
||||
const fd = openSync(dest, 'w');
|
||||
const stream = new Utf8Stream({ fd, sync, minLength: 5000 });
|
||||
|
||||
ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
|
||||
// Manually flush to test that data can be written
|
||||
stream.flush(common.mustSucceed());
|
||||
|
||||
setTimeout(common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\n');
|
||||
assert.strictEqual(data, 'hello world\n');
|
||||
}));
|
||||
}), 500);
|
||||
|
||||
|
||||
@@ -2,11 +2,7 @@
|
||||
|
||||
const common = require('../common');
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
const {
|
||||
ok,
|
||||
strictEqual,
|
||||
throws,
|
||||
} = require('node:assert');
|
||||
const assert = require('node:assert');
|
||||
const {
|
||||
open,
|
||||
openSync,
|
||||
@@ -37,8 +33,8 @@ function runTests(sync) {
|
||||
const dest = getTempFile();
|
||||
const stream = new Utf8Stream({ dest, sync });
|
||||
|
||||
ok(stream.write('hello world\n'));
|
||||
ok(stream.write('something else\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('something else\n'));
|
||||
|
||||
const after = dest + '-moved';
|
||||
|
||||
@@ -47,13 +43,13 @@ function runTests(sync) {
|
||||
stream.reopen();
|
||||
|
||||
stream.once('ready', common.mustCall(() => {
|
||||
ok(stream.write('after reopen\n'));
|
||||
assert.ok(stream.write('after reopen\n'));
|
||||
|
||||
stream.once('drain', common.mustCall(() => {
|
||||
readFile(after, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\nsomething else\n');
|
||||
assert.strictEqual(data, 'hello world\nsomething else\n');
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'after reopen\n');
|
||||
assert.strictEqual(data, 'after reopen\n');
|
||||
stream.end();
|
||||
}));
|
||||
}));
|
||||
@@ -66,8 +62,8 @@ function runTests(sync) {
|
||||
const dest = getTempFile();
|
||||
const stream = new Utf8Stream({ dest, sync });
|
||||
|
||||
ok(stream.write('hello world\n'));
|
||||
ok(stream.write('something else\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('something else\n'));
|
||||
|
||||
stream.reopen();
|
||||
stream.end();
|
||||
@@ -79,23 +75,23 @@ function runTests(sync) {
|
||||
const dest = getTempFile();
|
||||
const stream = new Utf8Stream({ dest, minLength: 0, sync });
|
||||
|
||||
ok(stream.write('hello world\n'));
|
||||
ok(stream.write('something else\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('something else\n'));
|
||||
|
||||
const after = dest + '-new';
|
||||
|
||||
stream.once('drain', common.mustCall(() => {
|
||||
stream.reopen(after);
|
||||
strictEqual(stream.file, after);
|
||||
assert.strictEqual(stream.file, after);
|
||||
|
||||
stream.once('ready', common.mustCall(() => {
|
||||
ok(stream.write('after reopen\n'));
|
||||
assert.ok(stream.write('after reopen\n'));
|
||||
|
||||
stream.once('drain', common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\nsomething else\n');
|
||||
assert.strictEqual(data, 'hello world\nsomething else\n');
|
||||
readFile(after, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'after reopen\n');
|
||||
assert.strictEqual(data, 'after reopen\n');
|
||||
stream.end();
|
||||
}));
|
||||
}));
|
||||
@@ -134,8 +130,8 @@ function runTests(sync) {
|
||||
fs: fsOverride,
|
||||
});
|
||||
|
||||
ok(stream.write('hello world\n'));
|
||||
ok(stream.write('something else\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('something else\n'));
|
||||
|
||||
const after = dest + '-moved';
|
||||
stream.on('error', common.mustCall());
|
||||
@@ -144,18 +140,18 @@ function runTests(sync) {
|
||||
renameSync(dest, after);
|
||||
throwOnNextOpen = true;
|
||||
if (sync) {
|
||||
throws(() => stream.reopen(), err);
|
||||
assert.throws(() => stream.reopen(), err);
|
||||
} else {
|
||||
stream.reopen();
|
||||
}
|
||||
|
||||
setTimeout(common.mustCall(() => {
|
||||
ok(stream.write('after reopen\n'));
|
||||
assert.ok(stream.write('after reopen\n'));
|
||||
|
||||
stream.end();
|
||||
stream.on('finish', common.mustCall(() => {
|
||||
readFile(after, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\nsomething else\nafter reopen\n');
|
||||
assert.strictEqual(data, 'hello world\nsomething else\nafter reopen\n');
|
||||
}));
|
||||
}));
|
||||
}), 10);
|
||||
@@ -166,8 +162,8 @@ function runTests(sync) {
|
||||
const dest = getTempFile();
|
||||
const stream = new Utf8Stream({ dest, sync });
|
||||
|
||||
ok(stream.write('hello world\n'));
|
||||
ok(stream.write('something else\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('something else\n'));
|
||||
|
||||
const after = dest + '-moved';
|
||||
stream.once('drain', common.mustCall(() => {
|
||||
@@ -175,13 +171,13 @@ function runTests(sync) {
|
||||
stream.reopen();
|
||||
|
||||
stream.once('drain', common.mustCall(() => {
|
||||
ok(stream.write('after reopen\n'));
|
||||
assert.ok(stream.write('after reopen\n'));
|
||||
|
||||
stream.once('drain', common.mustCall(() => {
|
||||
readFile(after, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\nsomething else\n');
|
||||
assert.strictEqual(data, 'hello world\nsomething else\n');
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'after reopen\n');
|
||||
assert.strictEqual(data, 'after reopen\n');
|
||||
stream.end();
|
||||
}));
|
||||
}));
|
||||
|
||||
@@ -2,10 +2,7 @@
|
||||
|
||||
const common = require('../common');
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
const {
|
||||
ok,
|
||||
strictEqual,
|
||||
} = require('node:assert');
|
||||
const assert = require('node:assert');
|
||||
const {
|
||||
openSync,
|
||||
writeSync,
|
||||
@@ -67,12 +64,12 @@ function runTests(sync) {
|
||||
});
|
||||
|
||||
stream.on('ready', common.mustCall(() => {
|
||||
ok(stream.write('hello world\n'));
|
||||
ok(stream.write('something else\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('something else\n'));
|
||||
stream.end();
|
||||
stream.on('finish', common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\nsomething else\n');
|
||||
assert.strictEqual(data, 'hello world\nsomething else\n');
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
@@ -91,12 +88,12 @@ function runTests(sync) {
|
||||
fd,
|
||||
sync: false,
|
||||
minLength: 12,
|
||||
retryEAGAIN: (err, writeBufferLen, remainingBufferLen) => {
|
||||
strictEqual(err.code, 'EAGAIN');
|
||||
strictEqual(writeBufferLen, 12);
|
||||
strictEqual(remainingBufferLen, 0);
|
||||
retryEAGAIN: common.mustCall((err, writeBufferLen, remainingBufferLen) => {
|
||||
assert.strictEqual(err.code, 'EAGAIN');
|
||||
assert.strictEqual(writeBufferLen, 12);
|
||||
assert.strictEqual(remainingBufferLen, 0);
|
||||
return false; // Don't retry
|
||||
},
|
||||
}),
|
||||
fs: {
|
||||
write: common.mustCall((...args) => {
|
||||
if (errorOnNext) {
|
||||
@@ -112,16 +109,16 @@ function runTests(sync) {
|
||||
|
||||
stream.on('ready', common.mustCall(() => {
|
||||
stream.once('error', common.mustCall((err) => {
|
||||
strictEqual(err.code, 'EAGAIN');
|
||||
ok(stream.write('something else\n'));
|
||||
assert.strictEqual(err.code, 'EAGAIN');
|
||||
assert.ok(stream.write('something else\n'));
|
||||
}));
|
||||
|
||||
ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
stream.end();
|
||||
|
||||
stream.on('finish', common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\nsomething else\n');
|
||||
assert.strictEqual(data, 'hello world\nsomething else\n');
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
@@ -153,14 +150,14 @@ function runTests(sync) {
|
||||
});
|
||||
|
||||
stream.on('ready', common.mustCall(() => {
|
||||
ok(stream.write('hello world\n'));
|
||||
ok(stream.write('something else\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('something else\n'));
|
||||
|
||||
stream.end();
|
||||
|
||||
stream.on('finish', common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\nsomething else\n');
|
||||
assert.strictEqual(data, 'hello world\nsomething else\n');
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
@@ -178,12 +175,12 @@ function runTests(sync) {
|
||||
fd,
|
||||
sync: false,
|
||||
minLength: 12,
|
||||
retryEAGAIN: (err, writeBufferLen, remainingBufferLen) => {
|
||||
strictEqual(err.code, 'EBUSY');
|
||||
strictEqual(writeBufferLen, 12);
|
||||
strictEqual(remainingBufferLen, 0);
|
||||
retryEAGAIN: common.mustCall((err, writeBufferLen, remainingBufferLen) => {
|
||||
assert.strictEqual(err.code, 'EBUSY');
|
||||
assert.strictEqual(writeBufferLen, 12);
|
||||
assert.strictEqual(remainingBufferLen, 0);
|
||||
return false; // Don't retry
|
||||
},
|
||||
}),
|
||||
fs: {
|
||||
write: common.mustCall((...args) => {
|
||||
if (errorOnNext) {
|
||||
@@ -199,17 +196,17 @@ function runTests(sync) {
|
||||
|
||||
stream.on('ready', common.mustCall(() => {
|
||||
stream.once('error', common.mustCall((err) => {
|
||||
strictEqual(err.code, 'EBUSY');
|
||||
ok(stream.write('something else\n'));
|
||||
assert.strictEqual(err.code, 'EBUSY');
|
||||
assert.ok(stream.write('something else\n'));
|
||||
}));
|
||||
|
||||
ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
|
||||
stream.end();
|
||||
|
||||
stream.on('finish', common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\nsomething else\n');
|
||||
assert.strictEqual(data, 'hello world\nsomething else\n');
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
|
||||
@@ -2,11 +2,7 @@
|
||||
|
||||
const common = require('../common');
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
const {
|
||||
ok,
|
||||
strictEqual,
|
||||
throws,
|
||||
} = require('node:assert');
|
||||
const assert = require('node:assert');
|
||||
const {
|
||||
openSync,
|
||||
closeSync,
|
||||
@@ -48,14 +44,14 @@ function getTempFile() {
|
||||
});
|
||||
|
||||
stream.on('ready', common.mustCall(() => {
|
||||
ok(stream.write('hello world\n'));
|
||||
ok(stream.write('something else\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('something else\n'));
|
||||
|
||||
stream.end();
|
||||
|
||||
stream.on('finish', common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\nsomething else\n');
|
||||
assert.strictEqual(data, 'hello world\nsomething else\n');
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
@@ -79,14 +75,14 @@ function getTempFile() {
|
||||
});
|
||||
|
||||
stream.on('ready', common.mustCall(() => {
|
||||
ok(stream.write('hello world\n'));
|
||||
ok(stream.write('something else\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('something else\n'));
|
||||
stream.flushSync();
|
||||
stream.on('write', common.mustNotCall());
|
||||
stream.end();
|
||||
stream.on('finish', common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\nsomething else\n');
|
||||
assert.strictEqual(data, 'hello world\nsomething else\n');
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
@@ -105,12 +101,12 @@ function getTempFile() {
|
||||
}
|
||||
});
|
||||
|
||||
ok(stream.write('hello world\n'));
|
||||
ok(stream.write('something else\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('something else\n'));
|
||||
|
||||
stream.on('drain', common.mustCall(() => {
|
||||
const data = readFileSync(dest, 'utf8');
|
||||
strictEqual(data, 'hello world\nsomething else\n');
|
||||
assert.strictEqual(data, 'hello world\nsomething else\n');
|
||||
}));
|
||||
|
||||
}
|
||||
@@ -133,7 +129,7 @@ function getTempFile() {
|
||||
|
||||
stream.on('finish', common.mustCall(() => {
|
||||
stat(dest, common.mustSucceed((stat) => {
|
||||
strictEqual(stat.size, length);
|
||||
assert.strictEqual(stat.size, length);
|
||||
}));
|
||||
}));
|
||||
}
|
||||
@@ -152,12 +148,12 @@ function getTempFile() {
|
||||
|
||||
stream.on('finish', common.mustCall(() => {
|
||||
stat(dest, common.mustSucceed((stat) => {
|
||||
strictEqual(stat.size, length);
|
||||
assert.strictEqual(stat.size, length);
|
||||
const char = Buffer.alloc(4);
|
||||
const readFd = openSync(dest, 'r');
|
||||
readSync(readFd, char, 0, 4, length - 4);
|
||||
closeSync(readFd);
|
||||
strictEqual(char.toString(), '🌲');
|
||||
assert.strictEqual(char.toString(), '🌲');
|
||||
}));
|
||||
}));
|
||||
}
|
||||
@@ -166,13 +162,13 @@ function getTempFile() {
|
||||
const dest = getTempFile();
|
||||
|
||||
const stream = new Utf8Stream({ dest, sync: true });
|
||||
ok(stream.write('hello world\n'));
|
||||
ok(stream.write('something else\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('something else\n'));
|
||||
stream.flushSync();
|
||||
// If we get here without error, the test passes
|
||||
stream.end();
|
||||
}
|
||||
throws(() => {
|
||||
assert.throws(() => {
|
||||
new Utf8Stream({ dest: '/path/to/nowhere', sync: true });
|
||||
}, /ENOENT|EACCES/);
|
||||
|
||||
@@ -182,12 +178,12 @@ throws(() => {
|
||||
const fd = openSync(dest, 'w');
|
||||
const stream = new Utf8Stream({ fd, sync: true });
|
||||
|
||||
ok(stream.write('hello world 👀\n'));
|
||||
ok(stream.write('another line 👀\n'));
|
||||
assert.ok(stream.write('hello world 👀\n'));
|
||||
assert.ok(stream.write('another line 👀\n'));
|
||||
|
||||
// Check internal buffer length (may not be available in Utf8Stream)
|
||||
// This is implementation-specific, so we just verify writes succeeded
|
||||
ok(true, 'writes completed successfully');
|
||||
assert.ok(true, 'writes completed successfully');
|
||||
|
||||
stream.end();
|
||||
}
|
||||
@@ -199,13 +195,13 @@ throws(() => {
|
||||
|
||||
let str = '';
|
||||
for (let i = 0; i < 20; i++) {
|
||||
ok(stream.write('👀'));
|
||||
assert.ok(stream.write('👀'));
|
||||
str += '👀';
|
||||
}
|
||||
|
||||
// Check internal buffer length (implementation-specific)
|
||||
ok(true, 'writes completed successfully');
|
||||
assert.ok(true, 'writes completed successfully');
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, str);
|
||||
assert.strictEqual(data, str);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -2,10 +2,7 @@
|
||||
|
||||
const common = require('../common');
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
const {
|
||||
ok,
|
||||
strictEqual,
|
||||
} = require('node:assert');
|
||||
const assert = require('node:assert');
|
||||
const {
|
||||
openSync,
|
||||
readFile,
|
||||
@@ -37,14 +34,14 @@ function runTests(sync) {
|
||||
const fd = openSync(dest, 'w');
|
||||
const stream = new Utf8Stream({ fd, sync });
|
||||
stream.on('ready', common.mustCall(() => {
|
||||
ok(stream.write('hello world\n'));
|
||||
ok(stream.write('something else\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('something else\n'));
|
||||
|
||||
stream.end();
|
||||
|
||||
stream.on('finish', common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\nsomething else\n');
|
||||
assert.strictEqual(data, 'hello world\nsomething else\n');
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
@@ -57,19 +54,19 @@ function runTests(sync) {
|
||||
|
||||
stream.once('drain', common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\n');
|
||||
ok(stream.write('something else\n'));
|
||||
assert.strictEqual(data, 'hello world\n');
|
||||
assert.ok(stream.write('something else\n'));
|
||||
|
||||
stream.once('drain', common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\nsomething else\n');
|
||||
assert.strictEqual(data, 'hello world\nsomething else\n');
|
||||
stream.end();
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
|
||||
ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
};
|
||||
|
||||
{
|
||||
@@ -83,7 +80,7 @@ function runTests(sync) {
|
||||
stream.on('finish', common.mustCall(() => {
|
||||
readFile(__filename, 'utf8', common.mustSucceed((expected) => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, expected);
|
||||
assert.strictEqual(data, expected);
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
@@ -94,14 +91,14 @@ function runTests(sync) {
|
||||
const stream = new Utf8Stream({ dest, sync });
|
||||
|
||||
stream.on('ready', common.mustCall(() => {
|
||||
ok(stream.write('hello world\n'));
|
||||
ok(stream.write('something else\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('something else\n'));
|
||||
|
||||
stream.end();
|
||||
|
||||
stream.on('finish', common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\nsomething else\n');
|
||||
assert.strictEqual(data, 'hello world\nsomething else\n');
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
@@ -112,20 +109,20 @@ function runTests(sync) {
|
||||
const stream = new Utf8Stream({ dest, minLength: 4096, sync });
|
||||
|
||||
stream.on('ready', common.mustCall(() => {
|
||||
ok(stream.write('hello world\n'));
|
||||
ok(stream.write('something else\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('something else\n'));
|
||||
|
||||
stream.on('drain', common.mustNotCall());
|
||||
|
||||
setTimeout(common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, ''); // Should be empty due to minLength
|
||||
assert.strictEqual(data, ''); // Should be empty due to minLength
|
||||
|
||||
stream.end();
|
||||
|
||||
stream.on('finish', common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\nsomething else\n');
|
||||
assert.strictEqual(data, 'hello world\nsomething else\n');
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
@@ -167,15 +164,15 @@ function runTests(sync) {
|
||||
|
||||
stream.on('ready', common.mustCall(() => {
|
||||
stream.on('error', common.mustCall());
|
||||
ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
|
||||
setTimeout(common.mustCall(() => {
|
||||
throwOnNext = false;
|
||||
ok(stream.write('something else\n'));
|
||||
assert.ok(stream.write('something else\n'));
|
||||
stream.end();
|
||||
stream.on('finish', common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\nsomething else\n');
|
||||
assert.strictEqual(data, 'hello world\nsomething else\n');
|
||||
}));
|
||||
}));
|
||||
}), 10);
|
||||
@@ -192,15 +189,15 @@ function runTests(sync) {
|
||||
length += bytes;
|
||||
});
|
||||
|
||||
ok(stream.write('hello world\n'));
|
||||
ok(stream.write('something else\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('something else\n'));
|
||||
|
||||
stream.end();
|
||||
|
||||
stream.on('finish', common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\nsomething else\n');
|
||||
strictEqual(length, 27);
|
||||
assert.strictEqual(data, 'hello world\nsomething else\n');
|
||||
assert.strictEqual(length, 27);
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
@@ -229,14 +226,14 @@ function runTests(sync) {
|
||||
}
|
||||
});
|
||||
stream.on('ready', common.mustCall(() => {
|
||||
ok(stream.write('hello world\n'));
|
||||
ok(stream.write('something else\n'));
|
||||
assert.ok(stream.write('hello world\n'));
|
||||
assert.ok(stream.write('something else\n'));
|
||||
|
||||
stream.end();
|
||||
|
||||
stream.on('finish', common.mustCall(() => {
|
||||
readFile(dest, 'utf8', common.mustSucceed((data) => {
|
||||
strictEqual(data, 'hello world\nsomething else\n');
|
||||
assert.strictEqual(data, 'hello world\nsomething else\n');
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
@@ -260,7 +257,7 @@ function runTests(sync) {
|
||||
|
||||
stream.on('finish', common.mustCall(() => {
|
||||
stat(dest, common.mustSucceed((stat) => {
|
||||
strictEqual(stat.size, length);
|
||||
assert.strictEqual(stat.size, length);
|
||||
}));
|
||||
}));
|
||||
}
|
||||
@@ -268,6 +265,6 @@ function runTests(sync) {
|
||||
{
|
||||
const dest = getTempFile();
|
||||
const stream = new Utf8Stream({ dest, maxLength: 65536 });
|
||||
strictEqual(stream.maxLength, 65536);
|
||||
assert.strictEqual(stream.maxLength, 65536);
|
||||
stream.end();
|
||||
}
|
||||
|
||||
@@ -40,12 +40,12 @@ const callbacks = {
|
||||
};
|
||||
|
||||
file
|
||||
.on('open', function(fd) {
|
||||
.on('open', common.mustCall((fd) => {
|
||||
console.error('open!');
|
||||
callbacks.open++;
|
||||
assert.strictEqual(typeof fd, 'number');
|
||||
})
|
||||
.on('drain', function() {
|
||||
}))
|
||||
.on('drain', common.mustCallAtLeast(() => {
|
||||
console.error('drain!', callbacks.drain);
|
||||
callbacks.drain++;
|
||||
if (callbacks.drain === -1) {
|
||||
@@ -55,8 +55,8 @@ file
|
||||
assert.strictEqual(fs.readFileSync(fn, 'utf8'), EXPECTED + EXPECTED);
|
||||
file.end();
|
||||
}
|
||||
})
|
||||
.on('close', function() {
|
||||
}))
|
||||
.on('close', common.mustCall(() => {
|
||||
console.error('close!');
|
||||
assert.strictEqual(file.bytesWritten, EXPECTED.length * 2);
|
||||
|
||||
@@ -69,7 +69,7 @@ file
|
||||
file.on('error', common.mustNotCall());
|
||||
|
||||
fs.unlinkSync(fn);
|
||||
});
|
||||
}));
|
||||
|
||||
for (let i = 0; i < 11; i++) {
|
||||
file.write(`${i}`);
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
'use strict';
|
||||
require('../common');
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const fs = require('fs');
|
||||
@@ -68,13 +68,13 @@ const file = fs.createWriteStream(filepath, {
|
||||
highWaterMark: 11
|
||||
});
|
||||
|
||||
file.on('open', function(fd) {
|
||||
file.on('open', common.mustCall((fd) => {
|
||||
console.error('open');
|
||||
cb_occurred += 'open ';
|
||||
assert.strictEqual(typeof fd, 'number');
|
||||
});
|
||||
}));
|
||||
|
||||
file.on('drain', function() {
|
||||
file.on('drain', common.mustCallAtLeast(() => {
|
||||
console.error('drain');
|
||||
cb_occurred += 'drain ';
|
||||
++countDrains;
|
||||
@@ -88,15 +88,15 @@ file.on('drain', function() {
|
||||
assert.strictEqual(fs.readFileSync(filepath, 'utf8'), EXPECTED + EXPECTED);
|
||||
file.end();
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
file.on('close', function() {
|
||||
file.on('close', common.mustCall(() => {
|
||||
cb_occurred += 'close ';
|
||||
assert.strictEqual(file.bytesWritten, EXPECTED.length * 2);
|
||||
file.write('should not work anymore', (err) => {
|
||||
file.write('should not work anymore', common.mustCall((err) => {
|
||||
assert.ok(err.message.includes('write after end'));
|
||||
});
|
||||
});
|
||||
}));
|
||||
}));
|
||||
|
||||
for (let i = 0; i < 11; i++) {
|
||||
const ret = file.write(String(i));
|
||||
|
||||
@@ -65,7 +65,7 @@ function run_test_1() {
|
||||
cb_occurred += 'open ';
|
||||
});
|
||||
|
||||
file.on('close', function() {
|
||||
file.on('close', common.mustCall(() => {
|
||||
cb_occurred += 'close ';
|
||||
console.log(' (debug: bytesWritten ', file.bytesWritten);
|
||||
console.log(' (debug: start ', file.start);
|
||||
@@ -77,7 +77,7 @@ function run_test_1() {
|
||||
assert.strictEqual(fileData, fileDataExpected_1);
|
||||
|
||||
run_test_2();
|
||||
});
|
||||
}));
|
||||
|
||||
file.on('error', function(err) {
|
||||
cb_occurred += 'error ';
|
||||
@@ -107,7 +107,7 @@ function run_test_2() {
|
||||
cb_occurred += 'open ';
|
||||
});
|
||||
|
||||
file.on('close', function() {
|
||||
file.on('close', common.mustCall(() => {
|
||||
cb_occurred += 'close ';
|
||||
console.log(' (debug: bytesWritten ', file.bytesWritten);
|
||||
console.log(' (debug: start ', file.start);
|
||||
@@ -119,7 +119,7 @@ function run_test_2() {
|
||||
assert.strictEqual(fileData, fileDataExpected_2);
|
||||
|
||||
run_test_3();
|
||||
});
|
||||
}));
|
||||
|
||||
file.on('error', function(err) {
|
||||
cb_occurred += 'error ';
|
||||
@@ -148,7 +148,7 @@ function run_test_3() {
|
||||
cb_occurred += 'open ';
|
||||
});
|
||||
|
||||
file.on('close', function() {
|
||||
file.on('close', common.mustCall(() => {
|
||||
cb_occurred += 'close ';
|
||||
console.log(' (debug: bytesWritten ', file.bytesWritten);
|
||||
console.log(' (debug: start ', file.start);
|
||||
@@ -161,7 +161,7 @@ function run_test_3() {
|
||||
|
||||
run_test_4();
|
||||
run_test_5();
|
||||
});
|
||||
}));
|
||||
|
||||
file.on('error', function(err) {
|
||||
cb_occurred += 'error ';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import '../common/index.mjs';
|
||||
import { open } from 'node:fs/promises';
|
||||
import { rejects } from 'node:assert';
|
||||
import assert from 'node:assert';
|
||||
|
||||
{
|
||||
const fh = await open(new URL(import.meta.url));
|
||||
@@ -13,7 +13,7 @@ import { rejects } from 'node:assert';
|
||||
|
||||
// If reading the FileHandle after the stream is consumed fails,
|
||||
// then we assume the autoClose option worked as expected.
|
||||
await rejects(fh.read(), { code: 'EBADF' });
|
||||
await assert.rejects(fh.read(), { code: 'EBADF' });
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -23,10 +23,7 @@ const {
|
||||
writeFileSync,
|
||||
} = require('node:fs');
|
||||
|
||||
const {
|
||||
ok,
|
||||
throws,
|
||||
} = require('node:assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const {
|
||||
sep,
|
||||
@@ -46,7 +43,7 @@ const kShiftJisBuffer = Buffer.from([0x82, 0xA0, 0x82, 0xA2, 0x82, 0xA4]);
|
||||
const tmpdirUrl = pathToFileURL(tmpdir.path + sep);
|
||||
const testPath = new URL(kShiftJisName, tmpdirUrl);
|
||||
|
||||
ok(testPath.pathname.endsWith(`/${kShiftJisName}`));
|
||||
assert.ok(testPath.pathname.endsWith(`/${kShiftJisName}`));
|
||||
|
||||
const tmpdirBuffer = Buffer.from(tmpdir.path + sep, 'utf8');
|
||||
const testPathBuffer = Buffer.concat([tmpdirBuffer, kShiftJisBuffer]);
|
||||
@@ -54,19 +51,19 @@ const testPathBuffer = Buffer.concat([tmpdirBuffer, kShiftJisBuffer]);
|
||||
// We can use the Buffer version of the path to create a file and check
|
||||
// its existence. But we cannot use the URL version because it contains
|
||||
// non-Unicode percent-encoded characters.
|
||||
throws(() => writeFileSync(testPath, 'test'), {
|
||||
assert.throws(() => writeFileSync(testPath, 'test'), {
|
||||
name: 'URIError',
|
||||
});
|
||||
|
||||
writeFileSync(testPathBuffer, 'test');
|
||||
ok(existsSync(testPathBuffer));
|
||||
assert.ok(existsSync(testPathBuffer));
|
||||
|
||||
// Using fileURLToPath fails because the URL contains non-Unicode
|
||||
// percent-encoded characters.
|
||||
throws(() => existsSync(fileURLToPath(testPath)), {
|
||||
assert.throws(() => existsSync(fileURLToPath(testPath)), {
|
||||
name: 'URIError',
|
||||
});
|
||||
|
||||
// This variation succeeds because the URL is converted to a buffer
|
||||
// without trying to interpret the percent-encoded characters.
|
||||
ok(existsSync(fileURLToPathBuffer(testPath)));
|
||||
assert.ok(existsSync(fileURLToPathBuffer(testPath)));
|
||||
|
||||
@@ -90,19 +90,17 @@ fs.promises.access(readOnlyFile, fs.constants.R_OK)
|
||||
.catch(throwNextTick);
|
||||
|
||||
{
|
||||
const expectedError = (err) => {
|
||||
const expectedError = common.mustCall((err) => {
|
||||
assert.notStrictEqual(err, null);
|
||||
assert.strictEqual(err.code, 'ENOENT');
|
||||
assert.strictEqual(err.path, doesNotExist);
|
||||
};
|
||||
const expectedErrorPromise = (err) => {
|
||||
}, 2);
|
||||
fs.access(doesNotExist, expectedError);
|
||||
assert.rejects(fs.promises.access(doesNotExist), (err) => {
|
||||
expectedError(err);
|
||||
assert.match(err.stack, /at async Object\.access/);
|
||||
};
|
||||
fs.access(doesNotExist, common.mustCall(expectedError));
|
||||
fs.promises.access(doesNotExist)
|
||||
.then(common.mustNotCall(), common.mustCall(expectedErrorPromise))
|
||||
.catch(throwNextTick);
|
||||
return true;
|
||||
}).then(common.mustCall());
|
||||
}
|
||||
|
||||
{
|
||||
@@ -122,19 +120,18 @@ fs.promises.access(readOnlyFile, fs.constants.R_OK)
|
||||
}
|
||||
|
||||
{
|
||||
const expectedError = (err) => {
|
||||
const expectedError = common.mustCall((err) => {
|
||||
assert.strictEqual(err.code, 'ERR_INVALID_ARG_TYPE');
|
||||
assert.ok(err instanceof TypeError);
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
assert.throws(
|
||||
() => { fs.access(100, fs.constants.F_OK, common.mustNotCall()); },
|
||||
expectedError
|
||||
);
|
||||
|
||||
fs.promises.access(100, fs.constants.F_OK)
|
||||
.then(common.mustNotCall(), common.mustCall(expectedError))
|
||||
.catch(throwNextTick);
|
||||
assert.rejects(fs.promises.access(100, fs.constants.F_OK), expectedError)
|
||||
.then(common.mustCall());
|
||||
}
|
||||
|
||||
assert.throws(
|
||||
|
||||
@@ -27,12 +27,12 @@ function beforeEach() {
|
||||
fs.writeFileSync(dest, 'dest');
|
||||
fs.chmodSync(dest, '444');
|
||||
|
||||
const check = (err) => {
|
||||
const check = common.mustCall((err) => {
|
||||
const expected = ['EACCES', 'EPERM'];
|
||||
assert(expected.includes(err.code), `${err.code} not in ${expected}`);
|
||||
assert.strictEqual(fs.readFileSync(dest, 'utf8'), 'dest');
|
||||
return true;
|
||||
};
|
||||
});
|
||||
|
||||
return { source, dest, check };
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ function re(literals, ...values) {
|
||||
|
||||
// stat
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(nonexistentFile, err.path);
|
||||
assert.strictEqual(
|
||||
err.message,
|
||||
@@ -76,7 +76,7 @@ function re(literals, ...values) {
|
||||
assert.strictEqual(err.code, 'ENOENT');
|
||||
assert.strictEqual(err.syscall, 'stat');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
fs.stat(nonexistentFile, common.mustCall(validateError));
|
||||
|
||||
@@ -88,7 +88,7 @@ function re(literals, ...values) {
|
||||
|
||||
// lstat
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(nonexistentFile, err.path);
|
||||
assert.strictEqual(
|
||||
err.message,
|
||||
@@ -97,7 +97,7 @@ function re(literals, ...values) {
|
||||
assert.strictEqual(err.code, 'ENOENT');
|
||||
assert.strictEqual(err.syscall, 'lstat');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
fs.lstat(nonexistentFile, common.mustCall(validateError));
|
||||
assert.throws(
|
||||
@@ -108,27 +108,27 @@ function re(literals, ...values) {
|
||||
|
||||
// fstat
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(err.message, 'EBADF: bad file descriptor, fstat');
|
||||
assert.strictEqual(err.errno, UV_EBADF);
|
||||
assert.strictEqual(err.code, 'EBADF');
|
||||
assert.strictEqual(err.syscall, 'fstat');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
common.runWithInvalidFD((fd) => {
|
||||
common.runWithInvalidFD(common.mustCall((fd) => {
|
||||
fs.fstat(fd, common.mustCall(validateError));
|
||||
|
||||
assert.throws(
|
||||
() => fs.fstatSync(fd),
|
||||
validateError
|
||||
);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
// realpath
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(nonexistentFile, err.path);
|
||||
assert.strictEqual(
|
||||
err.message,
|
||||
@@ -137,7 +137,7 @@ function re(literals, ...values) {
|
||||
assert.strictEqual(err.code, 'ENOENT');
|
||||
assert.strictEqual(err.syscall, 'lstat');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
fs.realpath(nonexistentFile, common.mustCall(validateError));
|
||||
|
||||
@@ -149,7 +149,7 @@ function re(literals, ...values) {
|
||||
|
||||
// native realpath
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(nonexistentFile, err.path);
|
||||
assert.strictEqual(
|
||||
err.message,
|
||||
@@ -158,7 +158,7 @@ function re(literals, ...values) {
|
||||
assert.strictEqual(err.code, 'ENOENT');
|
||||
assert.strictEqual(err.syscall, 'realpath');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
fs.realpath.native(nonexistentFile, common.mustCall(validateError));
|
||||
|
||||
@@ -170,7 +170,7 @@ function re(literals, ...values) {
|
||||
|
||||
// readlink
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(nonexistentFile, err.path);
|
||||
assert.strictEqual(
|
||||
err.message,
|
||||
@@ -179,7 +179,7 @@ function re(literals, ...values) {
|
||||
assert.strictEqual(err.code, 'ENOENT');
|
||||
assert.strictEqual(err.syscall, 'readlink');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
fs.readlink(nonexistentFile, common.mustCall(validateError));
|
||||
|
||||
@@ -191,7 +191,7 @@ function re(literals, ...values) {
|
||||
|
||||
// Link nonexistent file
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(nonexistentFile, err.path);
|
||||
// Could be resolved to an absolute path
|
||||
assert.ok(err.dest.endsWith('foo'),
|
||||
@@ -203,7 +203,7 @@ function re(literals, ...values) {
|
||||
assert.strictEqual(err.code, 'ENOENT');
|
||||
assert.strictEqual(err.syscall, 'link');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
fs.link(nonexistentFile, 'foo', common.mustCall(validateError));
|
||||
|
||||
@@ -215,7 +215,7 @@ function re(literals, ...values) {
|
||||
|
||||
// link existing file
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(existingFile, err.path);
|
||||
assert.strictEqual(existingFile2, err.dest);
|
||||
assert.strictEqual(
|
||||
@@ -226,7 +226,7 @@ function re(literals, ...values) {
|
||||
assert.strictEqual(err.code, 'EEXIST');
|
||||
assert.strictEqual(err.syscall, 'link');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
fs.link(existingFile, existingFile2, common.mustCall(validateError));
|
||||
|
||||
@@ -238,7 +238,7 @@ function re(literals, ...values) {
|
||||
|
||||
// symlink
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(existingFile, err.path);
|
||||
assert.strictEqual(existingFile2, err.dest);
|
||||
assert.strictEqual(
|
||||
@@ -249,7 +249,7 @@ function re(literals, ...values) {
|
||||
assert.strictEqual(err.code, 'EEXIST');
|
||||
assert.strictEqual(err.syscall, 'symlink');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
fs.symlink(existingFile, existingFile2, common.mustCall(validateError));
|
||||
|
||||
@@ -261,7 +261,7 @@ function re(literals, ...values) {
|
||||
|
||||
// unlink
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(nonexistentFile, err.path);
|
||||
assert.strictEqual(
|
||||
err.message,
|
||||
@@ -270,7 +270,7 @@ function re(literals, ...values) {
|
||||
assert.strictEqual(err.code, 'ENOENT');
|
||||
assert.strictEqual(err.syscall, 'unlink');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
fs.unlink(nonexistentFile, common.mustCall(validateError));
|
||||
|
||||
@@ -282,7 +282,7 @@ function re(literals, ...values) {
|
||||
|
||||
// rename
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(nonexistentFile, err.path);
|
||||
// Could be resolved to an absolute path
|
||||
assert.ok(err.dest.endsWith('foo'),
|
||||
@@ -294,7 +294,7 @@ function re(literals, ...values) {
|
||||
assert.strictEqual(err.code, 'ENOENT');
|
||||
assert.strictEqual(err.syscall, 'rename');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
const destFile = tmpdir.resolve('foo');
|
||||
fs.rename(nonexistentFile, destFile, common.mustCall(validateError));
|
||||
@@ -307,7 +307,7 @@ function re(literals, ...values) {
|
||||
|
||||
// Rename non-empty directory
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(existingDir, err.path);
|
||||
assert.strictEqual(existingDir2, err.dest);
|
||||
assert.strictEqual(err.syscall, 'rename');
|
||||
@@ -338,7 +338,7 @@ function re(literals, ...values) {
|
||||
assert.strictEqual(err.code, 'EPERM');
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
fs.rename(existingDir, existingDir2, common.mustCall(validateError));
|
||||
|
||||
@@ -350,7 +350,7 @@ function re(literals, ...values) {
|
||||
|
||||
// rmdir
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(nonexistentFile, err.path);
|
||||
assert.strictEqual(
|
||||
err.message,
|
||||
@@ -359,7 +359,7 @@ function re(literals, ...values) {
|
||||
assert.strictEqual(err.code, 'ENOENT');
|
||||
assert.strictEqual(err.syscall, 'rmdir');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
fs.rmdir(nonexistentFile, common.mustCall(validateError));
|
||||
|
||||
@@ -371,7 +371,7 @@ function re(literals, ...values) {
|
||||
|
||||
// rmdir a file
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(existingFile, err.path);
|
||||
assert.strictEqual(err.syscall, 'rmdir');
|
||||
if (err.code === 'ENOTDIR') {
|
||||
@@ -387,7 +387,7 @@ function re(literals, ...values) {
|
||||
assert.strictEqual(err.code, 'ENOENT');
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
fs.rmdir(existingFile, common.mustCall(validateError));
|
||||
|
||||
@@ -399,7 +399,7 @@ function re(literals, ...values) {
|
||||
|
||||
// mkdir
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(existingFile, err.path);
|
||||
assert.strictEqual(
|
||||
err.message,
|
||||
@@ -408,7 +408,7 @@ function re(literals, ...values) {
|
||||
assert.strictEqual(err.code, 'EEXIST');
|
||||
assert.strictEqual(err.syscall, 'mkdir');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
fs.mkdir(existingFile, 0o666, common.mustCall(validateError));
|
||||
|
||||
@@ -420,7 +420,7 @@ function re(literals, ...values) {
|
||||
|
||||
// chmod
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(nonexistentFile, err.path);
|
||||
assert.strictEqual(
|
||||
err.message,
|
||||
@@ -429,7 +429,7 @@ function re(literals, ...values) {
|
||||
assert.strictEqual(err.code, 'ENOENT');
|
||||
assert.strictEqual(err.syscall, 'chmod');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
fs.chmod(nonexistentFile, 0o666, common.mustCall(validateError));
|
||||
|
||||
@@ -441,7 +441,7 @@ function re(literals, ...values) {
|
||||
|
||||
// open
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(nonexistentFile, err.path);
|
||||
assert.strictEqual(
|
||||
err.message,
|
||||
@@ -450,7 +450,7 @@ function re(literals, ...values) {
|
||||
assert.strictEqual(err.code, 'ENOENT');
|
||||
assert.strictEqual(err.syscall, 'open');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
fs.open(nonexistentFile, 'r', 0o666, common.mustCall(validateError));
|
||||
|
||||
@@ -463,27 +463,27 @@ function re(literals, ...values) {
|
||||
|
||||
// close
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(err.message, 'EBADF: bad file descriptor, close');
|
||||
assert.strictEqual(err.errno, UV_EBADF);
|
||||
assert.strictEqual(err.code, 'EBADF');
|
||||
assert.strictEqual(err.syscall, 'close');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
common.runWithInvalidFD((fd) => {
|
||||
common.runWithInvalidFD(common.mustCall((fd) => {
|
||||
fs.close(fd, common.mustCall(validateError));
|
||||
|
||||
assert.throws(
|
||||
() => fs.closeSync(fd),
|
||||
validateError
|
||||
);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
// readFile
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(nonexistentFile, err.path);
|
||||
assert.strictEqual(
|
||||
err.message,
|
||||
@@ -492,7 +492,7 @@ function re(literals, ...values) {
|
||||
assert.strictEqual(err.code, 'ENOENT');
|
||||
assert.strictEqual(err.syscall, 'open');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
fs.readFile(nonexistentFile, common.mustCall(validateError));
|
||||
|
||||
@@ -504,7 +504,7 @@ function re(literals, ...values) {
|
||||
|
||||
// readdir
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(nonexistentFile, err.path);
|
||||
assert.strictEqual(
|
||||
err.message,
|
||||
@@ -513,7 +513,7 @@ function re(literals, ...values) {
|
||||
assert.strictEqual(err.code, 'ENOENT');
|
||||
assert.strictEqual(err.syscall, 'scandir');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
fs.readdir(nonexistentFile, common.mustCall(validateError));
|
||||
|
||||
@@ -525,7 +525,7 @@ function re(literals, ...values) {
|
||||
|
||||
// ftruncate
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(err.syscall, 'ftruncate');
|
||||
// Could be EBADF or EINVAL, depending on the platform
|
||||
if (err.code === 'EBADF') {
|
||||
@@ -537,61 +537,61 @@ function re(literals, ...values) {
|
||||
assert.strictEqual(err.code, 'EINVAL');
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
common.runWithInvalidFD((fd) => {
|
||||
common.runWithInvalidFD(common.mustCall((fd) => {
|
||||
fs.ftruncate(fd, 4, common.mustCall(validateError));
|
||||
|
||||
assert.throws(
|
||||
() => fs.ftruncateSync(fd, 4),
|
||||
validateError
|
||||
);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
// fdatasync
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(err.message, 'EBADF: bad file descriptor, fdatasync');
|
||||
assert.strictEqual(err.errno, UV_EBADF);
|
||||
assert.strictEqual(err.code, 'EBADF');
|
||||
assert.strictEqual(err.syscall, 'fdatasync');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
common.runWithInvalidFD((fd) => {
|
||||
common.runWithInvalidFD(common.mustCall((fd) => {
|
||||
fs.fdatasync(fd, common.mustCall(validateError));
|
||||
|
||||
assert.throws(
|
||||
() => fs.fdatasyncSync(fd),
|
||||
validateError
|
||||
);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
// fsync
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(err.message, 'EBADF: bad file descriptor, fsync');
|
||||
assert.strictEqual(err.errno, UV_EBADF);
|
||||
assert.strictEqual(err.code, 'EBADF');
|
||||
assert.strictEqual(err.syscall, 'fsync');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
common.runWithInvalidFD((fd) => {
|
||||
common.runWithInvalidFD(common.mustCall((fd) => {
|
||||
fs.fsync(fd, common.mustCall(validateError));
|
||||
|
||||
assert.throws(
|
||||
() => fs.fsyncSync(fd),
|
||||
validateError
|
||||
);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
// chown
|
||||
if (!common.isWindows) {
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(nonexistentFile, err.path);
|
||||
assert.strictEqual(
|
||||
err.message,
|
||||
@@ -600,7 +600,7 @@ if (!common.isWindows) {
|
||||
assert.strictEqual(err.code, 'ENOENT');
|
||||
assert.strictEqual(err.syscall, 'chown');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
fs.chown(nonexistentFile, process.getuid(), process.getgid(),
|
||||
common.mustCall(validateError));
|
||||
@@ -614,7 +614,7 @@ if (!common.isWindows) {
|
||||
|
||||
// utimes
|
||||
if (!common.isAIX) {
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(nonexistentFile, err.path);
|
||||
assert.strictEqual(
|
||||
err.message,
|
||||
@@ -623,7 +623,7 @@ if (!common.isAIX) {
|
||||
assert.strictEqual(err.code, 'ENOENT');
|
||||
assert.strictEqual(err.syscall, 'utime');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
fs.utimes(nonexistentFile, new Date(), new Date(),
|
||||
common.mustCall(validateError));
|
||||
@@ -636,7 +636,7 @@ if (!common.isAIX) {
|
||||
|
||||
// mkdtemp
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
const pathPrefix = new RegExp('^' + re`${nonexistentDir}`);
|
||||
assert.match(err.path, pathPrefix);
|
||||
|
||||
@@ -648,7 +648,7 @@ if (!common.isAIX) {
|
||||
assert.strictEqual(err.code, 'ENOENT');
|
||||
assert.strictEqual(err.syscall, 'mkdtemp');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
fs.mkdtemp(nonexistentDir, common.mustCall(validateError));
|
||||
|
||||
@@ -676,7 +676,7 @@ if (!common.isAIX) {
|
||||
|
||||
// copyFile: destination exists but the COPYFILE_EXCL flag is provided.
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
if (err.code === 'ENOENT') { // Could be ENOENT or EEXIST
|
||||
assert.strictEqual(err.message,
|
||||
'ENOENT: no such file or directory, copyfile ' +
|
||||
@@ -693,7 +693,7 @@ if (!common.isAIX) {
|
||||
assert.strictEqual(err.syscall, 'copyfile');
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
fs.copyFile(existingFile, existingFile2, COPYFILE_EXCL,
|
||||
common.mustCall(validateError));
|
||||
@@ -706,7 +706,7 @@ if (!common.isAIX) {
|
||||
|
||||
// copyFile: the source does not exist.
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(err.message,
|
||||
'ENOENT: no such file or directory, copyfile ' +
|
||||
`'${nonexistentFile}' -> '${existingFile2}'`);
|
||||
@@ -714,7 +714,7 @@ if (!common.isAIX) {
|
||||
assert.strictEqual(err.code, 'ENOENT');
|
||||
assert.strictEqual(err.syscall, 'copyfile');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
fs.copyFile(nonexistentFile, existingFile2, COPYFILE_EXCL,
|
||||
common.mustCall(validateError));
|
||||
@@ -727,15 +727,15 @@ if (!common.isAIX) {
|
||||
|
||||
// read
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(err.message, 'EBADF: bad file descriptor, read');
|
||||
assert.strictEqual(err.errno, UV_EBADF);
|
||||
assert.strictEqual(err.code, 'EBADF');
|
||||
assert.strictEqual(err.syscall, 'read');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
common.runWithInvalidFD((fd) => {
|
||||
common.runWithInvalidFD(common.mustCall((fd) => {
|
||||
const buf = Buffer.alloc(5);
|
||||
fs.read(fd, buf, 0, 1, 1, common.mustCall(validateError));
|
||||
|
||||
@@ -743,108 +743,108 @@ if (!common.isAIX) {
|
||||
() => fs.readSync(fd, buf, 0, 1, 1),
|
||||
validateError
|
||||
);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
// fchmod
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(err.message, 'EBADF: bad file descriptor, fchmod');
|
||||
assert.strictEqual(err.errno, UV_EBADF);
|
||||
assert.strictEqual(err.code, 'EBADF');
|
||||
assert.strictEqual(err.syscall, 'fchmod');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
common.runWithInvalidFD((fd) => {
|
||||
common.runWithInvalidFD(common.mustCall((fd) => {
|
||||
fs.fchmod(fd, 0o666, common.mustCall(validateError));
|
||||
|
||||
assert.throws(
|
||||
() => fs.fchmodSync(fd, 0o666),
|
||||
validateError
|
||||
);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
// fchown
|
||||
if (!common.isWindows) {
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(err.message, 'EBADF: bad file descriptor, fchown');
|
||||
assert.strictEqual(err.errno, UV_EBADF);
|
||||
assert.strictEqual(err.code, 'EBADF');
|
||||
assert.strictEqual(err.syscall, 'fchown');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
common.runWithInvalidFD((fd) => {
|
||||
common.runWithInvalidFD(common.mustCall((fd) => {
|
||||
fs.fchown(fd, process.getuid(), process.getgid(),
|
||||
common.mustCall(validateError));
|
||||
validateError);
|
||||
|
||||
assert.throws(
|
||||
() => fs.fchownSync(fd, process.getuid(), process.getgid()),
|
||||
validateError
|
||||
);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
// write buffer
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(err.message, 'EBADF: bad file descriptor, write');
|
||||
assert.strictEqual(err.errno, UV_EBADF);
|
||||
assert.strictEqual(err.code, 'EBADF');
|
||||
assert.strictEqual(err.syscall, 'write');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
common.runWithInvalidFD((fd) => {
|
||||
common.runWithInvalidFD(common.mustCall((fd) => {
|
||||
const buf = Buffer.alloc(5);
|
||||
fs.write(fd, buf, 0, 1, 1, common.mustCall(validateError));
|
||||
fs.write(fd, buf, 0, 1, 1, validateError);
|
||||
|
||||
assert.throws(
|
||||
() => fs.writeSync(fd, buf, 0, 1, 1),
|
||||
validateError
|
||||
);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
// write string
|
||||
{
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(err.message, 'EBADF: bad file descriptor, write');
|
||||
assert.strictEqual(err.errno, UV_EBADF);
|
||||
assert.strictEqual(err.code, 'EBADF');
|
||||
assert.strictEqual(err.syscall, 'write');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
common.runWithInvalidFD((fd) => {
|
||||
fs.write(fd, 'test', 1, common.mustCall(validateError));
|
||||
common.runWithInvalidFD(common.mustCall((fd) => {
|
||||
fs.write(fd, 'test', 1, validateError);
|
||||
|
||||
assert.throws(
|
||||
() => fs.writeSync(fd, 'test', 1),
|
||||
validateError
|
||||
);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
// futimes
|
||||
if (!common.isAIX) {
|
||||
const validateError = (err) => {
|
||||
const validateError = common.mustCall((err) => {
|
||||
assert.strictEqual(err.message, 'EBADF: bad file descriptor, futime');
|
||||
assert.strictEqual(err.errno, UV_EBADF);
|
||||
assert.strictEqual(err.code, 'EBADF');
|
||||
assert.strictEqual(err.syscall, 'futime');
|
||||
return true;
|
||||
};
|
||||
}, 2);
|
||||
|
||||
common.runWithInvalidFD((fd) => {
|
||||
fs.futimes(fd, new Date(), new Date(), common.mustCall(validateError));
|
||||
common.runWithInvalidFD(common.mustCall((fd) => {
|
||||
fs.futimes(fd, new Date(), new Date(), validateError);
|
||||
|
||||
assert.throws(
|
||||
() => fs.futimesSync(fd, new Date(), new Date()),
|
||||
validateError
|
||||
);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { mustCall } from '../common/index.mjs';
|
||||
import { glob } from 'node:fs';
|
||||
import process from 'node:process';
|
||||
import { strictEqual } from 'node:assert';
|
||||
import assert from 'node:assert';
|
||||
|
||||
// One uncaught error is expected
|
||||
process.on('uncaughtException', mustCall((err) => {
|
||||
strictEqual(err.message, 'blep');
|
||||
assert.strictEqual(err.message, 'blep');
|
||||
}));
|
||||
|
||||
{
|
||||
|
||||
@@ -384,7 +384,7 @@ describe('glob - withFileTypes', function() {
|
||||
const actual = await promisified(pattern, {
|
||||
cwd: fixtureDir,
|
||||
withFileTypes: true,
|
||||
exclude: (dirent) => assert.ok(dirent instanceof Dirent),
|
||||
exclude: common.mustCallAtLeast((dirent) => assert.ok(dirent instanceof Dirent), 0),
|
||||
});
|
||||
assertDirents(actual);
|
||||
assert.deepStrictEqual(actual.map(normalizeDirent).sort(), expected.filter(Boolean).map(normalizePath).sort());
|
||||
@@ -398,7 +398,7 @@ describe('globSync - withFileTypes', function() {
|
||||
const actual = globSync(pattern, {
|
||||
cwd: fixtureDir,
|
||||
withFileTypes: true,
|
||||
exclude: (dirent) => assert.ok(dirent instanceof Dirent),
|
||||
exclude: common.mustCallAtLeast((dirent) => assert.ok(dirent instanceof Dirent), 0),
|
||||
});
|
||||
assertDirents(actual);
|
||||
assert.deepStrictEqual(actual.map(normalizeDirent).sort(), expected.filter(Boolean).map(normalizePath).sort());
|
||||
@@ -413,7 +413,7 @@ describe('fsPromises glob - withFileTypes', function() {
|
||||
for await (const item of asyncGlob(pattern, {
|
||||
cwd: fixtureDir,
|
||||
withFileTypes: true,
|
||||
exclude: (dirent) => assert.ok(dirent instanceof Dirent),
|
||||
exclude: common.mustCallAtLeast((dirent) => assert.ok(dirent instanceof Dirent), 0),
|
||||
})) actual.push(item);
|
||||
assertDirents(actual);
|
||||
assert.deepStrictEqual(actual.map(normalizeDirent).sort(), expected.filter(Boolean).map(normalizePath).sort());
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
|
||||
require('../common');
|
||||
const { opendirSync } = require('node:fs');
|
||||
const { throws } = require('node:assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
throws(() => opendirSync('.', { encoding: 'no' }), {
|
||||
assert.throws(() => opendirSync('.', { encoding: 'no' }), {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
message: 'The argument \'encoding\' is invalid encoding. Received \'no\'',
|
||||
});
|
||||
|
||||
@@ -61,10 +61,10 @@ function makeDirectoryWritable(dir) {
|
||||
const dir = tmpdir.resolve(`mkdirp_${n++}`);
|
||||
fs.mkdirSync(dir);
|
||||
const codeExpected = makeDirectoryReadOnly(dir);
|
||||
fs.mkdir(path.join(dir, '/bar'), { recursive: true }, (err) => {
|
||||
fs.mkdir(path.join(dir, '/bar'), { recursive: true }, common.mustCall((err) => {
|
||||
makeDirectoryWritable(dir);
|
||||
assert(err);
|
||||
assert.strictEqual(err.code, codeExpected);
|
||||
assert(err.path);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -232,10 +232,10 @@ if (isMainThread && (common.isLinux || common.isMacOS)) {
|
||||
syscall: 'mkdir',
|
||||
}
|
||||
);
|
||||
fs.mkdir('X', common.mustNotMutateObjectDeep({ recursive: true }), (err) => {
|
||||
fs.mkdir('X', common.mustNotMutateObjectDeep({ recursive: true }), common.mustCall((err) => {
|
||||
assert.strictEqual(err.code, 'ENOENT');
|
||||
assert.strictEqual(err.syscall, 'mkdir');
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
// mkdirSync and mkdir require options.recursive to be a boolean.
|
||||
|
||||
@@ -63,8 +63,8 @@ assert.strictEqual(stringToFlags('xa+'), O_APPEND | O_CREAT | O_RDWR | O_EXCL);
|
||||
assert.strictEqual(stringToFlags('as+'), O_APPEND | O_CREAT | O_RDWR | O_SYNC);
|
||||
assert.strictEqual(stringToFlags('sa+'), O_APPEND | O_CREAT | O_RDWR | O_SYNC);
|
||||
|
||||
('+ +a +r +w rw wa war raw r++ a++ w++ x +x x+ rx rx+ wxx wax xwx xxx')
|
||||
.split(' ')
|
||||
['+', '+a', '+r', '+w', 'rw', 'wa', 'war', 'raw', 'r++', 'a++', 'w++', 'x', '+x',
|
||||
'x+', 'rx', 'rx+', 'wxx', 'wax', 'xwx', 'xxx']
|
||||
.forEach(function(flags) {
|
||||
assert.throws(
|
||||
() => stringToFlags(flags),
|
||||
|
||||
@@ -31,13 +31,13 @@ async function checkOperationError(op) {
|
||||
try {
|
||||
const filePath = await createFile();
|
||||
Object.defineProperty(FileHandle.prototype, 'fd', {
|
||||
get: function() {
|
||||
get: common.mustCall(function() {
|
||||
// Verify that close is called when an error is thrown
|
||||
this.close = common.mustCall(this.close);
|
||||
const opError = new Error('INTERNAL_ERROR');
|
||||
opError.code = 123;
|
||||
throw opError;
|
||||
}
|
||||
}),
|
||||
});
|
||||
|
||||
await assert.rejects(op(filePath), {
|
||||
|
||||
@@ -21,6 +21,7 @@ class WatchTestCase {
|
||||
|
||||
async run() {
|
||||
await Promise.all([this.watchFiles(), this.writeFiles()]);
|
||||
// eslint-disable-next-line node-core/must-call-assert
|
||||
assert(!this.files.length);
|
||||
}
|
||||
async watchFiles() {
|
||||
|
||||
@@ -123,14 +123,14 @@ async function executeOnHandle(dest, func) {
|
||||
|
||||
// handle is object
|
||||
{
|
||||
await executeOnHandle(dest, async (handle) => {
|
||||
await executeOnHandle(dest, common.mustCall(async (handle) => {
|
||||
assert.strictEqual(typeof handle, 'object');
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
// file stats
|
||||
{
|
||||
await executeOnHandle(dest, async (handle) => {
|
||||
await executeOnHandle(dest, common.mustCall(async (handle) => {
|
||||
let stats = await handle.stat();
|
||||
verifyStatObject(stats);
|
||||
assert.strictEqual(stats.size, 35);
|
||||
@@ -149,7 +149,7 @@ async function executeOnHandle(dest, func) {
|
||||
|
||||
await handle.datasync();
|
||||
await handle.sync();
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
// File system stats
|
||||
@@ -167,7 +167,7 @@ async function executeOnHandle(dest, func) {
|
||||
// Test fs.read promises when length to read is zero bytes
|
||||
{
|
||||
const dest = path.resolve(tmpDir, 'test1.js');
|
||||
await executeOnHandle(dest, async (handle) => {
|
||||
await executeOnHandle(dest, common.mustCall(async (handle) => {
|
||||
const buf = Buffer.from('DAWGS WIN');
|
||||
const bufLen = buf.length;
|
||||
await handle.write(buf);
|
||||
@@ -175,42 +175,42 @@ async function executeOnHandle(dest, func) {
|
||||
assert.strictEqual(ret.bytesRead, 0);
|
||||
|
||||
await unlink(dest);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
// Use fallback buffer allocation when first argument is null
|
||||
{
|
||||
await executeOnHandle(dest, async (handle) => {
|
||||
await executeOnHandle(dest, common.mustCall(async (handle) => {
|
||||
const ret = await handle.read(null, 0, 0, 0);
|
||||
assert.strictEqual(ret.buffer.length, 16384);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
// TypeError if buffer is not ArrayBufferView or nullable object
|
||||
{
|
||||
await executeOnHandle(dest, async (handle) => {
|
||||
await executeOnHandle(dest, common.mustCall(async (handle) => {
|
||||
await assert.rejects(
|
||||
async () => handle.read(0, 0, 0, 0),
|
||||
{ code: 'ERR_INVALID_ARG_TYPE' }
|
||||
);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
// Bytes written to file match buffer
|
||||
{
|
||||
await executeOnHandle(dest, async (handle) => {
|
||||
await executeOnHandle(dest, common.mustCall(async (handle) => {
|
||||
const buf = Buffer.from('hello fsPromises');
|
||||
const bufLen = buf.length;
|
||||
await handle.write(buf);
|
||||
const ret = await handle.read(Buffer.alloc(bufLen), 0, bufLen, 0);
|
||||
assert.strictEqual(ret.bytesRead, bufLen);
|
||||
assert.deepStrictEqual(ret.buffer, buf);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
// Truncate file to specified length
|
||||
{
|
||||
await executeOnHandle(dest, async (handle) => {
|
||||
await executeOnHandle(dest, common.mustCall(async (handle) => {
|
||||
const buf = Buffer.from('hello FileHandle');
|
||||
const bufLen = buf.length;
|
||||
await handle.write(buf, 0, bufLen, 0);
|
||||
@@ -219,12 +219,12 @@ async function executeOnHandle(dest, func) {
|
||||
assert.deepStrictEqual(ret.buffer, buf);
|
||||
await truncate(dest, 5);
|
||||
assert.strictEqual((await readFile(dest)).toString(), 'hello');
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
// Invalid change of ownership
|
||||
{
|
||||
await executeOnHandle(dest, async (handle) => {
|
||||
await executeOnHandle(dest, common.mustCall(async (handle) => {
|
||||
await chmod(dest, 0o666);
|
||||
await handle.chmod(0o666);
|
||||
|
||||
@@ -257,7 +257,7 @@ async function executeOnHandle(dest, func) {
|
||||
message: 'The value of "gid" is out of range. ' +
|
||||
'It must be >= -1 && <= 4294967295. Received -2'
|
||||
});
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
// Set modification times
|
||||
@@ -483,7 +483,7 @@ async function executeOnHandle(dest, func) {
|
||||
|
||||
// Regression test for https://github.com/nodejs/node/issues/38168
|
||||
{
|
||||
await executeOnHandle(dest, async (handle) => {
|
||||
await executeOnHandle(dest, common.mustCall(async (handle) => {
|
||||
await assert.rejects(
|
||||
async () => handle.write('abc', 0, 'hex'),
|
||||
{
|
||||
@@ -494,17 +494,17 @@ async function executeOnHandle(dest, func) {
|
||||
|
||||
const ret = await handle.write('abcd', 0, 'hex');
|
||||
assert.strictEqual(ret.bytesWritten, 2);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
// Test prototype methods calling with contexts other than FileHandle
|
||||
{
|
||||
await executeOnHandle(dest, async (handle) => {
|
||||
await executeOnHandle(dest, common.mustCall(async (handle) => {
|
||||
await assert.rejects(() => handle.stat.call({}), {
|
||||
code: 'ERR_INTERNAL_ASSERTION',
|
||||
message: /handle must be an instance of FileHandle/
|
||||
});
|
||||
});
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
require('../common');
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const stream = require('stream');
|
||||
@@ -8,10 +8,10 @@ const encoding = 'base64';
|
||||
|
||||
const example = fixtures.path('x.txt');
|
||||
const assertStream = new stream.Writable({
|
||||
write: function(chunk, enc, next) {
|
||||
write: common.mustCall((chunk, enc, next) => {
|
||||
const expected = Buffer.from('xyz');
|
||||
assert(chunk.equals(expected));
|
||||
}
|
||||
}),
|
||||
});
|
||||
assertStream.setDefaultEncoding(encoding);
|
||||
fs.createReadStream(example, encoding).pipe(assertStream);
|
||||
|
||||
@@ -42,7 +42,7 @@ fs.close = common.mustCall((fd_, cb) => {
|
||||
});
|
||||
|
||||
const read = fs.read;
|
||||
fs.read = function() {
|
||||
fs.read = common.mustCall(function() {
|
||||
// First time is ok.
|
||||
read.apply(fs, arguments);
|
||||
// Then it breaks.
|
||||
@@ -56,7 +56,7 @@ fs.read = function() {
|
||||
throw new Error('BOOM!');
|
||||
};
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
stream.on('data', (buf) => {
|
||||
stream.on('data', common.mustNotCall("no more 'data' events should follow"));
|
||||
|
||||
@@ -52,7 +52,7 @@ const rangeFile = fixtures.path('x.txt');
|
||||
{
|
||||
const file = fs.createReadStream(fn, { __proto__: { encoding: 'utf8' } });
|
||||
file.length = 0;
|
||||
file.on('data', function(data) {
|
||||
file.on('data', common.mustCallAtLeast((data) => {
|
||||
assert.strictEqual(typeof data, 'string');
|
||||
file.length += data.length;
|
||||
|
||||
@@ -60,7 +60,7 @@ const rangeFile = fixtures.path('x.txt');
|
||||
// http://www.fileformat.info/info/unicode/char/2026/index.htm
|
||||
assert.strictEqual(data[i], '\u2026');
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
file.on('close', common.mustCall(function() {
|
||||
assert.strictEqual(file.length, 10000);
|
||||
|
||||
@@ -27,7 +27,7 @@ let isLow = false;
|
||||
let cur = 0;
|
||||
let stream;
|
||||
|
||||
const readInterval = setInterval(() => {
|
||||
const readInterval = setInterval(common.mustCallAtLeast(() => {
|
||||
if (stream) return;
|
||||
|
||||
stream = fs.createReadStream(file, {
|
||||
@@ -60,7 +60,7 @@ const readInterval = setInterval(() => {
|
||||
isLow = false;
|
||||
bufs = [];
|
||||
});
|
||||
}, 10);
|
||||
}), 10);
|
||||
|
||||
// Time longer than 90 seconds to exit safely
|
||||
const endTimer = setTimeout(() => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
require('../common');
|
||||
const common = require('../common');
|
||||
const fixtures = require('../common/fixtures');
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
@@ -14,11 +14,11 @@ fs.createReadStream(example, null);
|
||||
fs.createReadStream(example, 'utf8');
|
||||
fs.createReadStream(example, { encoding: 'utf8' });
|
||||
|
||||
const createReadStreamErr = (path, opt, error) => {
|
||||
const createReadStreamErr = common.mustCallAtLeast((path, opt, error) => {
|
||||
assert.throws(() => {
|
||||
fs.createReadStream(path, opt);
|
||||
}, error);
|
||||
};
|
||||
});
|
||||
|
||||
const typeError = {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
|
||||
@@ -53,7 +53,7 @@ function test1(options) {
|
||||
file.resume();
|
||||
}));
|
||||
|
||||
file.on('data', function(data) {
|
||||
file.on('data', common.mustCallAtLeast((data) => {
|
||||
assert.ok(data instanceof Buffer);
|
||||
assert.ok(data.byteOffset % 8 === 0);
|
||||
assert.ok(!paused);
|
||||
@@ -69,7 +69,7 @@ function test1(options) {
|
||||
paused = false;
|
||||
file.resume();
|
||||
}, 10);
|
||||
});
|
||||
}));
|
||||
|
||||
|
||||
file.on('end', common.mustCall(function(chunk) {
|
||||
@@ -100,7 +100,7 @@ test1({
|
||||
{
|
||||
const file = fs.createReadStream(fn, common.mustNotMutateObjectDeep({ encoding: 'utf8' }));
|
||||
file.length = 0;
|
||||
file.on('data', function(data) {
|
||||
file.on('data', common.mustCallAtLeast((data) => {
|
||||
assert.strictEqual(typeof data, 'string');
|
||||
file.length += data.length;
|
||||
|
||||
@@ -108,7 +108,7 @@ test1({
|
||||
// http://www.fileformat.info/info/unicode/char/2026/index.htm
|
||||
assert.strictEqual(data[i], '\u2026');
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
file.on('close', common.mustCall());
|
||||
|
||||
|
||||
@@ -36,12 +36,12 @@ const fixtures = require('../common/fixtures');
|
||||
|
||||
function test(env, cb) {
|
||||
const filename = fixtures.path('test-fs-readfile-error.js');
|
||||
exec(...common.escapePOSIXShell`"${process.execPath}" "${filename}"`, (err, stdout, stderr) => {
|
||||
exec(...common.escapePOSIXShell`"${process.execPath}" "${filename}"`, common.mustCall((err, stdout, stderr) => {
|
||||
assert(err);
|
||||
assert.strictEqual(stdout, '');
|
||||
assert.notStrictEqual(stderr, '');
|
||||
cb(String(stderr));
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
test({ NODE_DEBUG: '' }, common.mustCall((data) => {
|
||||
|
||||
@@ -10,37 +10,34 @@ const fn = fixtures.path('empty.txt');
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
tmpdir.refresh();
|
||||
|
||||
tempFd(function(fd, close) {
|
||||
fs.readFile(fd, function(err, data) {
|
||||
tempFd(common.mustCall((fd, close) => {
|
||||
fs.readFile(fd, common.mustSucceed((data) => {
|
||||
assert.ok(data);
|
||||
close();
|
||||
});
|
||||
});
|
||||
}));
|
||||
}));
|
||||
|
||||
tempFd(function(fd, close) {
|
||||
fs.readFile(fd, 'utf8', function(err, data) {
|
||||
tempFd(common.mustCall((fd, close) => {
|
||||
fs.readFile(fd, 'utf8', common.mustSucceed((data) => {
|
||||
assert.strictEqual(data, '');
|
||||
close();
|
||||
});
|
||||
});
|
||||
}));
|
||||
}));
|
||||
|
||||
tempFdSync(function(fd) {
|
||||
tempFdSync(common.mustCall((fd) => {
|
||||
assert.ok(fs.readFileSync(fd));
|
||||
});
|
||||
}));
|
||||
|
||||
tempFdSync(function(fd) {
|
||||
tempFdSync(common.mustCall((fd) => {
|
||||
assert.strictEqual(fs.readFileSync(fd, 'utf8'), '');
|
||||
});
|
||||
}));
|
||||
|
||||
function tempFd(callback) {
|
||||
fs.open(fn, 'r', function(err, fd) {
|
||||
assert.ifError(err);
|
||||
callback(fd, function() {
|
||||
fs.close(fd, function(err) {
|
||||
assert.ifError(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
fs.open(fn, 'r', common.mustSucceed((fd) => {
|
||||
callback(fd, common.mustCall(() => {
|
||||
fs.close(fd, common.mustSucceed());
|
||||
}));
|
||||
}));
|
||||
}
|
||||
|
||||
function tempFdSync(callback) {
|
||||
|
||||
@@ -10,10 +10,9 @@ const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
|
||||
if (process.argv[2] === 'child') {
|
||||
fs.readFile('/dev/stdin', function(er, data) {
|
||||
assert.ifError(er);
|
||||
fs.readFile('/dev/stdin', common.mustSucceed((data) => {
|
||||
process.stdout.write(data);
|
||||
});
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ if (common.isWindows) {
|
||||
// Something like "C:\\"
|
||||
root = process.cwd().slice(0, 3);
|
||||
assertEqualPath = function(path_left, path_right, message) {
|
||||
// eslint-disable-next-line node-core/must-call-assert
|
||||
assert
|
||||
.strictEqual(path_left.toLowerCase(), path_right.toLowerCase(), message);
|
||||
};
|
||||
@@ -429,15 +430,13 @@ function test_up_multiple(realpath, realpathSync, cb) {
|
||||
assertEqualPath(realpathSync(abedabeda), abedabeda_real);
|
||||
assertEqualPath(realpathSync(abedabed), abedabed_real);
|
||||
|
||||
realpath(abedabeda, function(er, real) {
|
||||
assert.ifError(er);
|
||||
realpath(abedabeda, common.mustSucceed((real) => {
|
||||
assertEqualPath(abedabeda_real, real);
|
||||
realpath(abedabed, function(er, real) {
|
||||
assert.ifError(er);
|
||||
realpath(abedabed, common.mustSucceed((real) => {
|
||||
assertEqualPath(abedabed_real, real);
|
||||
cb();
|
||||
});
|
||||
});
|
||||
}));
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -472,15 +471,13 @@ function test_up_multiple_with_null_options(realpath, realpathSync, cb) {
|
||||
assertEqualPath(realpathSync(abedabeda), abedabeda_real);
|
||||
assertEqualPath(realpathSync(abedabed), abedabed_real);
|
||||
|
||||
realpath(abedabeda, null, function(er, real) {
|
||||
assert.ifError(er);
|
||||
realpath(abedabeda, null, common.mustSucceed((real) => {
|
||||
assertEqualPath(abedabeda_real, real);
|
||||
realpath(abedabed, null, function(er, real) {
|
||||
assert.ifError(er);
|
||||
realpath(abedabed, null, common.mustSucceed((real) => {
|
||||
assertEqualPath(abedabed_real, real);
|
||||
cb();
|
||||
});
|
||||
});
|
||||
}));
|
||||
}));
|
||||
}
|
||||
|
||||
// Absolute symlinks with children.
|
||||
@@ -548,19 +545,17 @@ function test_abs_with_kids(realpath, realpathSync, cb) {
|
||||
|
||||
function test_root(realpath, realpathSync, cb) {
|
||||
assertEqualPath(root, realpathSync('/'));
|
||||
realpath('/', function(err, result) {
|
||||
assert.ifError(err);
|
||||
realpath('/', common.mustSucceed((result) => {
|
||||
assertEqualPath(root, result);
|
||||
cb();
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
function test_root_with_null_options(realpath, realpathSync, cb) {
|
||||
realpath('/', null, function(err, result) {
|
||||
assert.ifError(err);
|
||||
realpath('/', null, common.mustSucceed((result) => {
|
||||
assertEqualPath(root, result);
|
||||
cb();
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -148,7 +148,7 @@ if (!common.isWindows) {
|
||||
{ code: 'EBADF' });
|
||||
}
|
||||
|
||||
const runCallbackTest = (func, arg, done) => {
|
||||
const runCallbackTest = common.mustCall((func, arg, done) => {
|
||||
const startTime = process.hrtime.bigint();
|
||||
func(arg, common.mustNotMutateObjectDeep({ bigint: true }), common.mustCall((err, bigintStats) => {
|
||||
func(arg, common.mustCall((err, numStats) => {
|
||||
@@ -160,7 +160,7 @@ const runCallbackTest = (func, arg, done) => {
|
||||
}
|
||||
}));
|
||||
}));
|
||||
};
|
||||
}, common.isWindows ? 2 : 3);
|
||||
|
||||
{
|
||||
const filename = getFilename();
|
||||
|
||||
@@ -20,11 +20,10 @@ fs.statfs(__filename, common.mustSucceed(function(stats) {
|
||||
assert.strictEqual(this, undefined);
|
||||
}));
|
||||
|
||||
fs.statfs(__filename, { bigint: true }, function(err, stats) {
|
||||
assert.ifError(err);
|
||||
fs.statfs(__filename, { bigint: true }, common.mustSucceed(function(stats) {
|
||||
verifyStatFsObject(stats, true);
|
||||
assert.strictEqual(this, undefined);
|
||||
});
|
||||
}));
|
||||
|
||||
// Synchronous
|
||||
{
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
'use strict';
|
||||
require('../common');
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const { internalBinding } = require('internal/test/binding');
|
||||
@@ -30,10 +30,9 @@ const { internalBinding } = require('internal/test/binding');
|
||||
fs.openSync = function() {
|
||||
return 42;
|
||||
};
|
||||
fs.closeSync = function(fd) {
|
||||
fs.closeSync = common.mustCall((fd) => {
|
||||
assert.strictEqual(fd, 42);
|
||||
close_called++;
|
||||
};
|
||||
}, 2);
|
||||
fs.readSync = function() {
|
||||
throw new Error('BAM');
|
||||
};
|
||||
@@ -42,45 +41,28 @@ fs.writeSync = function() {
|
||||
};
|
||||
|
||||
// Internal fast paths are pure C++, can't error inside write
|
||||
internalBinding('fs').writeFileUtf8 = function() {
|
||||
internalBinding('fs').writeFileUtf8 = common.mustCall(function() {
|
||||
// Fake close
|
||||
close_called++;
|
||||
throw new Error('BAM');
|
||||
};
|
||||
}, 2);
|
||||
|
||||
internalBinding('fs').fstat = function() {
|
||||
throw new Error('EBADF: bad file descriptor, fstat');
|
||||
};
|
||||
|
||||
let close_called = 0;
|
||||
ensureThrows(function() {
|
||||
assert.throws(function() {
|
||||
// Fast path: writeFileSync utf8
|
||||
fs.writeFileSync('dummy', 'xxx');
|
||||
}, 'BAM');
|
||||
ensureThrows(function() {
|
||||
}, { message: 'BAM' });
|
||||
assert.throws(function() {
|
||||
// Non-fast path
|
||||
fs.writeFileSync('dummy', 'xxx', { encoding: 'base64' });
|
||||
}, 'BAM');
|
||||
ensureThrows(function() {
|
||||
}, { message: 'BAM' });
|
||||
assert.throws(function() {
|
||||
// Fast path: writeFileSync utf8
|
||||
fs.appendFileSync('dummy', 'xxx');
|
||||
}, 'BAM');
|
||||
ensureThrows(function() {
|
||||
}, { message: 'BAM' });
|
||||
assert.throws(function() {
|
||||
// Non-fast path
|
||||
fs.appendFileSync('dummy', 'xxx', { encoding: 'base64' });
|
||||
}, 'BAM');
|
||||
|
||||
function ensureThrows(cb, message) {
|
||||
let got_exception = false;
|
||||
|
||||
close_called = 0;
|
||||
try {
|
||||
cb();
|
||||
} catch (e) {
|
||||
assert.strictEqual(e.message, message);
|
||||
got_exception = true;
|
||||
}
|
||||
|
||||
assert.strictEqual(close_called, 1);
|
||||
assert.strictEqual(got_exception, true);
|
||||
}
|
||||
}, { message: 'BAM' });
|
||||
|
||||
@@ -68,6 +68,7 @@ testTruncate(common.mustSucceed(() => {
|
||||
testFtruncate(common.mustSucceed());
|
||||
}));
|
||||
|
||||
/* eslint-disable node-core/must-call-assert */
|
||||
function testTruncate(cb) {
|
||||
fs.writeFile(filename, data, function(er) {
|
||||
if (er) return cb(er);
|
||||
@@ -124,6 +125,7 @@ function testFtruncate(cb) {
|
||||
});
|
||||
});
|
||||
}
|
||||
/* eslint-enable node-core/must-call-assert */
|
||||
|
||||
// Make sure if the size of the file is smaller than the length then it is
|
||||
// filled with zeroes.
|
||||
@@ -236,7 +238,7 @@ function testFtruncate(cb) {
|
||||
|
||||
{
|
||||
const file8 = path.resolve(tmp, 'non-existent-truncate-file.txt');
|
||||
const validateError = (err) => {
|
||||
fs.truncate(file8, 0, common.mustCall((err) => {
|
||||
assert.strictEqual(file8, err.path);
|
||||
assert.strictEqual(
|
||||
err.message,
|
||||
@@ -244,8 +246,7 @@ function testFtruncate(cb) {
|
||||
assert.strictEqual(err.code, 'ENOENT');
|
||||
assert.strictEqual(err.syscall, 'open');
|
||||
return true;
|
||||
};
|
||||
fs.truncate(file8, 0, common.mustCall(validateError));
|
||||
}));
|
||||
}
|
||||
|
||||
['', false, null, {}, []].forEach((input) => {
|
||||
|
||||
@@ -21,27 +21,25 @@ const {
|
||||
tmpdir.refresh();
|
||||
|
||||
{
|
||||
const validateError = (err) => {
|
||||
assert.strictEqual(err.path, nonexistentFile);
|
||||
assert.strictEqual(err.filename, nonexistentFile);
|
||||
assert.ok(err.syscall === 'watch' || err.syscall === 'stat');
|
||||
if (err.code === 'ENOENT') {
|
||||
assert.ok(err.message.startsWith('ENOENT: no such file or directory'));
|
||||
assert.strictEqual(err.errno, UV_ENOENT);
|
||||
assert.strictEqual(err.code, 'ENOENT');
|
||||
} else { // AIX
|
||||
assert.strictEqual(
|
||||
err.message,
|
||||
`ENODEV: no such device, watch '${nonexistentFile}'`);
|
||||
assert.strictEqual(err.errno, UV_ENODEV);
|
||||
assert.strictEqual(err.code, 'ENODEV');
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
assert.throws(
|
||||
() => fs.watch(nonexistentFile, common.mustNotCall()),
|
||||
validateError
|
||||
(err) => {
|
||||
assert.strictEqual(err.path, nonexistentFile);
|
||||
assert.strictEqual(err.filename, nonexistentFile);
|
||||
assert.ok(err.syscall === 'watch' || err.syscall === 'stat');
|
||||
if (err.code === 'ENOENT') {
|
||||
assert.ok(err.message.startsWith('ENOENT: no such file or directory'));
|
||||
assert.strictEqual(err.errno, UV_ENOENT);
|
||||
assert.strictEqual(err.code, 'ENOENT');
|
||||
} else { // AIX
|
||||
assert.strictEqual(
|
||||
err.message,
|
||||
`ENODEV: no such device, watch '${nonexistentFile}'`);
|
||||
assert.strictEqual(err.errno, UV_ENODEV);
|
||||
assert.strictEqual(err.code, 'ENODEV');
|
||||
}
|
||||
return true;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -51,7 +49,7 @@ tmpdir.refresh();
|
||||
fs.writeFileSync(file, 'test');
|
||||
const watcher = fs.watch(file, common.mustNotCall());
|
||||
|
||||
const validateError = (err) => {
|
||||
watcher.on('error', common.mustCall((err) => {
|
||||
assert.strictEqual(err.path, nonexistentFile);
|
||||
assert.strictEqual(err.filename, nonexistentFile);
|
||||
assert.strictEqual(
|
||||
@@ -62,9 +60,7 @@ tmpdir.refresh();
|
||||
assert.strictEqual(err.syscall, 'watch');
|
||||
fs.unlinkSync(file);
|
||||
return true;
|
||||
};
|
||||
|
||||
watcher.on('error', common.mustCall(validateError));
|
||||
}));
|
||||
|
||||
// Simulate the invocation from the binding
|
||||
watcher._handle.onchange(UV_ENOENT, 'ENOENT', nonexistentFile);
|
||||
|
||||
@@ -39,13 +39,13 @@ const relativePath = path.join(file, path.basename(subfolderPath), childrenFile)
|
||||
|
||||
const watcher = fs.watch(testDirectory, { recursive: true });
|
||||
let watcherClosed = false;
|
||||
watcher.on('change', function(event, filename) {
|
||||
watcher.on('change', common.mustCallAtLeast((event, filename) => {
|
||||
if (filename === relativePath) {
|
||||
assert.strictEqual(event, 'rename');
|
||||
watcher.close();
|
||||
watcherClosed = true;
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
// Do the write with a delay to ensure that the OS is ready to notify us.
|
||||
setTimeout(() => {
|
||||
|
||||
@@ -34,13 +34,13 @@ const childrenRelativePath = path.join(path.basename(filePath), childrenFile);
|
||||
let watcherClosed = false;
|
||||
|
||||
const watcher = fs.watch(testDirectory, { recursive: true });
|
||||
watcher.on('change', function(event, filename) {
|
||||
watcher.on('change', common.mustCallAtLeast((event, filename) => {
|
||||
if (filename === childrenRelativePath) {
|
||||
assert.strictEqual(event, 'rename');
|
||||
watcher.close();
|
||||
watcherClosed = true;
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
// Do the write with a delay to ensure that the OS is ready to notify us.
|
||||
setTimeout(() => {
|
||||
|
||||
@@ -34,13 +34,13 @@ tmpdir.refresh();
|
||||
|
||||
const watcher = fs.watch(url, { recursive: true });
|
||||
let watcherClosed = false;
|
||||
watcher.on('change', function(event, filename) {
|
||||
watcher.on('change', common.mustCallAtLeast((event, filename) => {
|
||||
if (filename === path.basename(filePath)) {
|
||||
assert.strictEqual(event, 'rename');
|
||||
watcher.close();
|
||||
watcherClosed = true;
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
await setTimeout(common.platformTimeout(100));
|
||||
fs.writeFileSync(filePath, 'world');
|
||||
|
||||
@@ -30,13 +30,13 @@ const testFile = path.join(testDirectory, 'file-1.txt');
|
||||
|
||||
const watcher = fs.watch(testDirectory, { recursive: true });
|
||||
let watcherClosed = false;
|
||||
watcher.on('change', function(event, filename) {
|
||||
watcher.on('change', common.mustCallAtLeast((event, filename) => {
|
||||
if (filename === path.basename(testFile)) {
|
||||
assert.strictEqual(event, 'rename');
|
||||
watcher.close();
|
||||
watcherClosed = true;
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
// Do the write with a delay to ensure that the OS is ready to notify us.
|
||||
setTimeout(() => {
|
||||
|
||||
@@ -32,13 +32,13 @@ tmpdir.refresh();
|
||||
|
||||
const watcher = fs.watch(testDirectory, { recursive: true });
|
||||
let watcherClosed = false;
|
||||
watcher.on('change', function(event, filename) {
|
||||
watcher.on('change', common.mustCallAtLeast((event, filename) => {
|
||||
if (filename === path.basename(testFile)) {
|
||||
assert.strictEqual(event, 'rename');
|
||||
watcher.close();
|
||||
watcherClosed = true;
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
await setTimeout(common.platformTimeout(100));
|
||||
fs.mkdirSync(testFile);
|
||||
|
||||
@@ -28,6 +28,6 @@ const onFileUpdate = common.mustCallAtLeast((eventType, filename) => {
|
||||
const watcher = fs.watch(toWatch, { recursive: true }, onFileUpdate);
|
||||
|
||||
// We must wait a bit `fs.rm()` to let the watcher be set up properly
|
||||
setTimeout(() => {
|
||||
setTimeout(common.mustCall(() => {
|
||||
fs.rm(tmpdir.resolve('./parent/child'), { recursive: true }, common.mustCall());
|
||||
}, common.platformTimeout(500));
|
||||
}), common.platformTimeout(500));
|
||||
|
||||
@@ -43,7 +43,7 @@ tmpdir.refresh();
|
||||
|
||||
const watcher = fs.watch(rootDirectory, { recursive: true });
|
||||
let watcherClosed = false;
|
||||
watcher.on('change', function(event, filename) {
|
||||
watcher.on('change', common.mustCallAtLeast((event, filename) => {
|
||||
assert.ok(event === 'rename', `Received ${event}`);
|
||||
assert.ok(filename === path.basename(symlinkFolder) || filename === path.basename(filePath), `Received ${filename}`);
|
||||
|
||||
@@ -51,7 +51,7 @@ tmpdir.refresh();
|
||||
watcher.close();
|
||||
watcherClosed = true;
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
await setTimeout(common.platformTimeout(100));
|
||||
fs.writeFileSync(filePath, 'world');
|
||||
@@ -87,7 +87,7 @@ tmpdir.refresh();
|
||||
|
||||
const watcher = fs.watch(trackingSubDirectory, { recursive: true });
|
||||
let watcherClosed = false;
|
||||
watcher.on('change', function(event, filename) {
|
||||
watcher.on('change', common.mustCallAtLeast((event, filename) => {
|
||||
// macOS will only change the following events:
|
||||
// { event: 'rename', filename: 'symlink-folder' }
|
||||
// { event: 'rename', filename: 'acceptable.txt' }
|
||||
@@ -98,7 +98,7 @@ tmpdir.refresh();
|
||||
watcher.close();
|
||||
watcherClosed = true;
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
await setTimeout(common.platformTimeout(100));
|
||||
fs.writeFileSync(forbiddenFile, 'world');
|
||||
|
||||
@@ -33,7 +33,7 @@ tmpdir.refresh();
|
||||
const watcher = fs.watch(filePath, { recursive: true });
|
||||
let watcherClosed = false;
|
||||
let interval;
|
||||
watcher.on('change', function(event, filename) {
|
||||
watcher.on('change', common.mustCall((event, filename) => {
|
||||
assert.strictEqual(event, 'change');
|
||||
|
||||
if (filename === path.basename(filePath)) {
|
||||
@@ -42,7 +42,7 @@ tmpdir.refresh();
|
||||
watcher.close();
|
||||
watcherClosed = true;
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
interval = setInterval(() => {
|
||||
fs.writeFileSync(filePath, 'world');
|
||||
|
||||
@@ -14,7 +14,7 @@ triggered = false;
|
||||
watch.once('stop', listener); // Should trigger.
|
||||
watch.stop();
|
||||
assert.strictEqual(triggered, false);
|
||||
setImmediate(() => {
|
||||
setImmediate(common.mustCall(() => {
|
||||
assert.strictEqual(triggered, true);
|
||||
watch.removeListener('stop', listener);
|
||||
});
|
||||
}));
|
||||
|
||||
@@ -36,11 +36,10 @@ function next() {
|
||||
|
||||
function next2() {
|
||||
// This will test if after reusing the fd data is written properly
|
||||
fs.readFile(file, function(err, data) {
|
||||
assert.ifError(err);
|
||||
fs.readFile(file, common.mustSucceed((data) => {
|
||||
assert.strictEqual(data.toString(), 'Test2');
|
||||
process.nextTick(common.mustCall(next3));
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
function next3() {
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
'use strict';
|
||||
require('../common');
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
|
||||
@@ -41,12 +41,12 @@ fs.open = function() {
|
||||
return _fs_open.apply(fs, arguments);
|
||||
};
|
||||
|
||||
fs.close = function(fd) {
|
||||
fs.close = common.mustCall(function(fd) {
|
||||
assert.ok(fd, 'fs.close must not be called with an undefined fd.');
|
||||
fs.close = _fs_close;
|
||||
fs.open = _fs_open;
|
||||
fs.closeSync(fd);
|
||||
};
|
||||
});
|
||||
|
||||
stream.write('foo');
|
||||
stream.end();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
require('../common');
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const fixtures = require('../common/fixtures');
|
||||
const fs = require('fs');
|
||||
@@ -21,15 +21,15 @@ const dummyWriteStream = fs.createWriteStream(dummyPath, {
|
||||
encoding: firstEncoding
|
||||
});
|
||||
|
||||
exampleReadStream.pipe(dummyWriteStream).on('finish', function() {
|
||||
exampleReadStream.pipe(dummyWriteStream).on('finish', common.mustCall(() => {
|
||||
const assertWriteStream = new stream.Writable({
|
||||
write: function(chunk, enc, next) {
|
||||
write: common.mustCall((chunk, enc, next) => {
|
||||
const expected = Buffer.from('xyz\n');
|
||||
assert(chunk.equals(expected));
|
||||
}
|
||||
}),
|
||||
});
|
||||
assertWriteStream.setDefaultEncoding(secondEncoding);
|
||||
fs.createReadStream(dummyPath, {
|
||||
encoding: secondEncoding
|
||||
}).pipe(assertWriteStream);
|
||||
});
|
||||
}));
|
||||
|
||||
@@ -68,10 +68,10 @@ stream.on('error', common.mustCall(function(err_) {
|
||||
}));
|
||||
|
||||
|
||||
stream.write(Buffer.allocUnsafe(256), function() {
|
||||
stream.write(Buffer.allocUnsafe(256), common.mustCall(() => {
|
||||
console.error('first cb');
|
||||
stream.write(Buffer.allocUnsafe(256), common.mustCall(function(err_) {
|
||||
console.error('second cb');
|
||||
assert.strictEqual(err_, err);
|
||||
}));
|
||||
});
|
||||
}));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
require('../common');
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
|
||||
@@ -14,7 +14,7 @@ fs.createWriteStream(example, null).end();
|
||||
fs.createWriteStream(example, 'utf8').end();
|
||||
fs.createWriteStream(example, { encoding: 'utf8' }).end();
|
||||
|
||||
const createWriteStreamErr = (path, opt) => {
|
||||
const createWriteStreamErr = common.mustCall((path, opt) => {
|
||||
assert.throws(
|
||||
() => {
|
||||
fs.createWriteStream(path, opt);
|
||||
@@ -23,7 +23,7 @@ const createWriteStreamErr = (path, opt) => {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
name: 'TypeError'
|
||||
});
|
||||
};
|
||||
}, 4);
|
||||
|
||||
createWriteStreamErr(example, 123);
|
||||
createWriteStreamErr(example, 0);
|
||||
|
||||
@@ -34,11 +34,11 @@ tmpdir.refresh();
|
||||
const stream = fs.WriteStream(file);
|
||||
const _fs_close = fs.close;
|
||||
|
||||
fs.close = function(fd) {
|
||||
fs.close = common.mustCall(function(fd) {
|
||||
assert.ok(fd, 'fs.close must not be called without an undefined fd.');
|
||||
fs.close = _fs_close;
|
||||
fs.closeSync(fd);
|
||||
};
|
||||
});
|
||||
stream.destroy();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
const common = require('../common');
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
const { strictEqual } = require('assert');
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
|
||||
// Regression test for https://github.com/nodejs/node/issues/51993
|
||||
@@ -23,6 +23,6 @@ w.on('open', common.mustCall(() => {
|
||||
}));
|
||||
|
||||
w.on('close', common.mustCall(() => {
|
||||
strictEqual(fs.readFileSync(file, 'utf8'), 'helloworld');
|
||||
assert.strictEqual(fs.readFileSync(file, 'utf8'), 'helloworld');
|
||||
fs.unlinkSync(file);
|
||||
}));
|
||||
|
||||
@@ -9,9 +9,7 @@ const {
|
||||
openSync,
|
||||
} = require('node:fs');
|
||||
|
||||
const {
|
||||
throws,
|
||||
} = require('node:assert');
|
||||
const assert = require('node:assert');
|
||||
|
||||
// If a file's mode change after it is opened but before it is written to,
|
||||
// and the Object.prototype is manipulated to throw an error when the errno
|
||||
@@ -39,4 +37,4 @@ Object.defineProperty(Object.prototype, 'errno', {
|
||||
const fd = openSync(path);
|
||||
chmodSync(path, 0o600);
|
||||
|
||||
throws(() => writeSync(fd, 'test'), error);
|
||||
assert.throws(() => writeSync(fd, 'test'), error);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// just like test-gc-http-client-timeout.js,
|
||||
// but using a net server/client instead
|
||||
|
||||
require('../common');
|
||||
const common = require('../common');
|
||||
const { onGC } = require('../common/gc');
|
||||
const assert = require('assert');
|
||||
const net = require('net');
|
||||
@@ -18,9 +18,9 @@ function serverHandler(sock) {
|
||||
sock.on('end', function() {
|
||||
clearTimeout(timer);
|
||||
});
|
||||
sock.on('error', function(err) {
|
||||
sock.on('error', common.mustCallAtLeast((err) => {
|
||||
assert.strictEqual(err.code, 'ECONNRESET');
|
||||
});
|
||||
}, 0));
|
||||
const timer = setTimeout(function() {
|
||||
sock.end('hello\n');
|
||||
}, 100);
|
||||
|
||||
@@ -17,6 +17,7 @@ process.on('warning', () => {
|
||||
// process warning writes to the console, which will
|
||||
// invoke the monkeypatched process.stderr.write
|
||||
// below.
|
||||
// eslint-disable-next-line node-core/must-call-assert
|
||||
assert.strictEqual(writeTimes, 1);
|
||||
EventEmitter.defaultMaxListeners = oldDefault;
|
||||
warningTimes++;
|
||||
@@ -28,6 +29,7 @@ process.on('exit', () => {
|
||||
|
||||
process.stderr.write = (data) => {
|
||||
if (writeTimes === 0)
|
||||
// eslint-disable-next-line node-core/must-call-assert
|
||||
assert.match(data, leakWarning);
|
||||
else
|
||||
assert.fail('stderr.write should be called only once');
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const { strictEqual, ok } = require('node:assert');
|
||||
const assert = require('node:assert');
|
||||
const { CustomEvent: internalCustomEvent } = require('internal/event_target');
|
||||
|
||||
// Global
|
||||
ok(CustomEvent);
|
||||
assert.ok(CustomEvent);
|
||||
|
||||
strictEqual(CustomEvent, internalCustomEvent);
|
||||
assert.strictEqual(CustomEvent, internalCustomEvent);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const { strictEqual } = require('assert');
|
||||
const assert = require('assert');
|
||||
const util = require('util');
|
||||
|
||||
strictEqual(TextDecoder, util.TextDecoder);
|
||||
strictEqual(TextEncoder, util.TextEncoder);
|
||||
assert.strictEqual(TextDecoder, util.TextDecoder);
|
||||
assert.strictEqual(TextEncoder, util.TextEncoder);
|
||||
|
||||
Reference in New Issue
Block a user