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

Function runTests

test/parallel/test-fastutf8stream-mode.js:32–108  ·  view source on GitHub ↗
(sync)

Source from the content-addressed store, hash-verified

30runTests(true);
31
32function runTests(sync) {
33 {
34 const dest = getTempFile();
35 const mode = 0o666;
36 const stream = new Utf8Stream({ dest, sync, mode });
37
38 stream.on('ready', common.mustCall(() => {
39 assert.ok(stream.write('hello world\n'));
40 assert.ok(stream.write('something else\n'));
41
42 stream.end();
43
44 stream.on('finish', common.mustCall(() => {
45 readFile(dest, 'utf8', common.mustSucceed((data) => {
46 assert.strictEqual(data, 'hello world\nsomething else\n');
47 // The actual mode may vary depending on the platform,
48 // so we check only the first bit.
49 assert.strictEqual(statSync(dest).mode & 0o700, 0o600);
50 }));
51 }));
52 }));
53 }
54
55 {
56 const dest = getTempFile();
57 const defaultMode = 0o600;
58 const stream = new Utf8Stream({ dest, sync });
59 stream.on('ready', common.mustCall(() => {
60 assert.ok(stream.write('hello world\n'));
61 assert.ok(stream.write('something else\n'));
62
63 stream.end();
64
65 stream.on('finish', common.mustCall(() => {
66 readFile(dest, 'utf8', common.mustSucceed((data) => {
67 assert.strictEqual(data, 'hello world\nsomething else\n');
68 assert.strictEqual(statSync(dest).mode & 0o700, defaultMode);
69 }));
70 }));
71 }));
72 }
73
74 {
75 const dest = join(getTempFile(), 'out.log');
76 const mode = 0o666;
77 const stream = new Utf8Stream({ dest, mkdir: true, mode, sync });
78
79 stream.on('ready', common.mustCall(() => {
80 assert.ok(stream.write('hello world\n'));
81 stream.flush();
82 stream.on('drain', common.mustCall(() => {
83 readFile(dest, 'utf8', common.mustSucceed((data) => {
84 assert.strictEqual(data, 'hello world\n');
85 stream.end();
86 }));
87 }));
88 }));
89 }

Callers 1

Calls 10

writeMethod · 0.95
endMethod · 0.95
flushMethod · 0.95
writeFileSyncFunction · 0.85
getTempFileFunction · 0.70
readFileFunction · 0.70
statSyncFunction · 0.50
joinFunction · 0.50
onMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…