MCPcopy Index your code
hub / github.com/nodejs/node / runTests

Function runTests

test/parallel/test-fs-write-optional-params.js:60–108  ·  view source on GitHub ↗
(fd)

Source from the content-addressed store, hash-verified

58const testValid = util.promisify(testValidCb);
59
60async function runTests(fd) {
61 // Test if first argument is not wrongly interpreted as ArrayBufferView|string
62 for (const badBuffer of [
63 undefined, null, true, 42, 42n, Symbol('42'), NaN, [], () => {},
64 Promise.resolve(new Uint8Array(1)),
65 common.mustNotCall(),
66 common.mustNotMutateObjectDeep({}),
67 {},
68 { buffer: 'amNotParam' },
69 { string: 'amNotParam' },
70 { buffer: new Uint8Array(1).buffer },
71 new Date(),
72 new String('notPrimitive'),
73 { [Symbol.toPrimitive]: (hint) => 'amObject' },
74 { toString() { return 'amObject'; } },
75 ]) {
76 await testInvalid(fd, 'ERR_INVALID_ARG_TYPE', badBuffer, {});
77 }
78
79 // First argument (buffer or string) is mandatory
80 await testInvalid(fd, 'ERR_INVALID_ARG_TYPE', undefined, undefined);
81
82 // Various invalid options
83 await testInvalid(fd, 'ERR_OUT_OF_RANGE', buffer, { length: 5 });
84 await testInvalid(fd, 'ERR_OUT_OF_RANGE', buffer, { offset: 5 });
85 await testInvalid(fd, 'ERR_OUT_OF_RANGE', buffer, { length: 1, offset: 3 });
86 await testInvalid(fd, 'ERR_OUT_OF_RANGE', buffer, { length: -1 });
87 await testInvalid(fd, 'ERR_OUT_OF_RANGE', buffer, { offset: -1 });
88 await testInvalid(fd, 'ERR_INVALID_ARG_TYPE', buffer, { offset: false });
89 await testInvalid(fd, 'ERR_INVALID_ARG_TYPE', buffer, { offset: true });
90 await testInvalid(fd, 'ERR_INVALID_ARG_TYPE', buffer, true);
91 await testInvalid(fd, 'ERR_INVALID_ARG_TYPE', buffer, '42');
92 await testInvalid(fd, 'ERR_INVALID_ARG_TYPE', buffer, Symbol('42'));
93
94 // Test compatibility with fs.read counterpart
95 for (const [ index, options ] of [
96 null,
97 {},
98 { length: 1 },
99 { position: 5 },
100 { length: 1, position: 5 },
101 { length: 1, position: -1, offset: 2 },
102 { length: null },
103 { position: null },
104 { offset: 1 },
105 ].entries()) {
106 await testValid(buffer, options, index);
107 }
108}
109
110fs.open(destInvalid, 'w+', common.mustSucceed(async (fd) => {
111 runTests(fd).then(common.mustCall(() => { fs.close(fd, common.mustSucceed()); }));

Calls 5

testInvalidFunction · 0.70
testValidFunction · 0.70
SymbolFunction · 0.50
resolveMethod · 0.45
entriesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…