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

Function runTests

test/parallel/test-fastutf8stream-write-buffer.js:26–72  ·  view source on GitHub ↗
(sync)

Source from the content-addressed store, hash-verified

24runTests(true);
25
26function runTests(sync) {
27 {
28 // A single buffer write must end up in the file.
29 const dest = getTempFile();
30 const stream = new Utf8Stream({ dest, sync, contentMode: 'buffer' });
31
32 stream.on('ready', common.mustCall(() => {
33 assert.ok(stream.write(Buffer.from('hello world\n')));
34 stream.end();
35
36 stream.on('finish', common.mustCall(() => {
37 readFile(dest, 'utf8', common.mustSucceed((data) => {
38 assert.strictEqual(data, 'hello world\n');
39 }));
40 }));
41 }));
42 }
43
44 {
45 // Writes that exceed maxWrite start a new batch; data must survive
46 // the batch boundary and be written in order.
47 const dest = getTempFile();
48 const stream = new Utf8Stream({
49 dest,
50 sync,
51 contentMode: 'buffer',
52 minLength: 60,
53 maxWrite: 64,
54 });
55
56 stream.on('ready', common.mustCall(() => {
57 stream.write(Buffer.from('a'.repeat(40)));
58 stream.write(Buffer.from('b'.repeat(40)));
59 stream.write(Buffer.from('c'.repeat(40)));
60 stream.end();
61
62 stream.on('finish', common.mustCall(() => {
63 readFile(dest, 'utf8', common.mustSucceed((data) => {
64 assert.strictEqual(
65 data,
66 'a'.repeat(40) + 'b'.repeat(40) + 'c'.repeat(40),
67 );
68 }));
69 }));
70 }));
71 }
72}

Calls 7

writeMethod · 0.95
endMethod · 0.95
getTempFileFunction · 0.70
readFileFunction · 0.70
onMethod · 0.45
okMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…