Skip to content

Commit ee095f3

Browse files
committed
squash: adjust tests
1 parent cb03d99 commit ee095f3

File tree

2 files changed

+20
-35
lines changed

2 files changed

+20
-35
lines changed

test/parallel/test-fs-write-file-sync.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,20 @@ tmpdir.refresh();
102102
assert.strictEqual(content, 'hello world!');
103103
}
104104

105-
// Test writeFileSync with an object with an own toString function
105+
// Test writeFileSync with an invalid input
106106
{
107-
// Runtime deprecated by DEP0162
108-
common.expectWarning('DeprecationWarning',
109-
'Implicit coercion of objects with own toString property is deprecated.',
110-
'DEP0162');
111-
const file = path.join(tmpdir.path, 'testWriteFileSyncStringify.txt');
112-
const data = {
113-
toString() {
114-
return 'hello world!';
115-
}
116-
};
117-
118-
fs.writeFileSync(file, data, { encoding: 'utf8', flag: 'a' });
119-
const content = fs.readFileSync(file, { encoding: 'utf8' });
120-
assert.strictEqual(content, String(data));
107+
const file = path.join(tmpdir.path, 'testWriteFileSyncInvalid.txt');
108+
for (const data of [
109+
false, 5, {}, [], null, undefined, true, 5n, () => {}, Symbol(), new Map(),
110+
new String('notPrimitive'),
111+
{ [Symbol.toPrimitive]: (hint) => 'amObject' },
112+
{ toString() { return 'amObject'; } },
113+
Promise.resolve('amPromise'),
114+
common.mustNotCall(),
115+
]) {
116+
assert.throws(
117+
() => fs.writeFileSync(file, data, { encoding: 'utf8', flag: 'a' }),
118+
{ code: 'ERR_INVALID_ARG_TYPE' }
119+
);
120+
}
121121
}

test/parallel/test-fs-write.js

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const fn = path.join(tmpdir.path, 'write.txt');
3333
const fn2 = path.join(tmpdir.path, 'write2.txt');
3434
const fn3 = path.join(tmpdir.path, 'write3.txt');
3535
const fn4 = path.join(tmpdir.path, 'write4.txt');
36-
const fn5 = path.join(tmpdir.path, 'write5.txt');
3736
const expected = 'ümlaut.';
3837
const constants = fs.constants;
3938

@@ -127,23 +126,6 @@ fs.open(fn3, 'w', 0o644, common.mustSucceed((fd) => {
127126
}));
128127

129128

130-
// Test write with an object with an own toString function
131-
// Runtime deprecated by DEP0162
132-
common.expectWarning('DeprecationWarning',
133-
'Implicit coercion of objects with own toString property is deprecated.',
134-
'DEP0162');
135-
fs.open(fn4, 'w', 0o644, common.mustSucceed((fd) => {
136-
const done = common.mustSucceed((written) => {
137-
assert.strictEqual(written, Buffer.byteLength(expected));
138-
fs.closeSync(fd);
139-
});
140-
141-
const data = {
142-
toString() { return expected; }
143-
};
144-
fs.write(fd, data, done);
145-
}));
146-
147129
[false, 'test', {}, [], null, undefined].forEach((i) => {
148130
assert.throws(
149131
() => fs.write(i, common.mustNotCall()),
@@ -162,9 +144,12 @@ fs.open(fn4, 'w', 0o644, common.mustSucceed((fd) => {
162144
});
163145

164146
[
165-
false, 5, {}, [], null, undefined,
147+
false, 5, {}, [], null, undefined, true, 5n, () => {}, Symbol(), new Map(),
166148
new String('notPrimitive'),
167149
{ [Symbol.toPrimitive]: (hint) => 'amObject' },
150+
{ toString() { return 'amObject'; } },
151+
Promise.resolve('amPromise'),
152+
common.mustNotCall(),
168153
].forEach((data) => {
169154
assert.throws(
170155
() => fs.write(1, data, common.mustNotCall()),
@@ -184,7 +169,7 @@ fs.open(fn4, 'w', 0o644, common.mustSucceed((fd) => {
184169

185170
{
186171
// Regression test for https://github.com/nodejs/node/issues/38168
187-
const fd = fs.openSync(fn5, 'w');
172+
const fd = fs.openSync(fn4, 'w');
188173

189174
assert.throws(
190175
() => fs.writeSync(fd, 'abc', 0, 'hex'),

0 commit comments

Comments
 (0)