How to use getFileContents method in wpt

Best JavaScript code snippet using wpt

FileSystemWritableFileStream-write.js

Source:FileSystemWritableFileStream-write.js Github

copy

Full Screen

2 const handle = await createEmptyFile(t, 'empty_blob', root);3 const stream = await handle.createWritable();4 await stream.write(new Blob([]));5 await stream.close();6 assert_equals(await getFileContents(handle), '');7 assert_equals(await getFileSize(handle), 0);8}, 'write() with an empty blob to an empty file');9directory_test(async (t, root) => {10 const handle = await createEmptyFile(t, 'valid_blob', root);11 const stream = await handle.createWritable();12 await stream.write(new Blob(['1234567890']));13 await stream.close();14 assert_equals(await getFileContents(handle), '1234567890');15 assert_equals(await getFileSize(handle), 10);16}, 'write() a blob to an empty file');17directory_test(async (t, root) => {18 const handle = await createEmptyFile(t, 'write_param_empty', root);19 const stream = await handle.createWritable();20 await stream.write({type: 'write', data: '1234567890'});21 await stream.close();22 assert_equals(await getFileContents(handle), '1234567890');23 assert_equals(await getFileSize(handle), 10);24}, 'write() with WriteParams without position to an empty file');25directory_test(async (t, root) => {26 const handle = await createEmptyFile(t, 'string_zero_offset', root);27 const stream = await handle.createWritable();28 await stream.write({type: 'write', position: 0, data: '1234567890'});29 await stream.close();30 assert_equals(await getFileContents(handle), '1234567890');31 assert_equals(await getFileSize(handle), 10);32}, 'write() a string to an empty file with zero offset');33directory_test(async (t, root) => {34 const handle = await createEmptyFile(t, 'blob_zero_offset', root);35 const stream = await handle.createWritable();36 await stream.write({type: 'write', position: 0, data: new Blob(['1234567890'])});37 await stream.close();38 assert_equals(await getFileContents(handle), '1234567890');39 assert_equals(await getFileSize(handle), 10);40}, 'write() a blob to an empty file with zero offset');41directory_test(async (t, root) => {42 const handle = await createEmptyFile(t, 'write_appends', root);43 const stream = await handle.createWritable();44 await stream.write('12345');45 await stream.write('67890');46 await stream.close();47 assert_equals(await getFileContents(handle), '1234567890');48 assert_equals(await getFileSize(handle), 10);49}, 'write() called consecutively appends');50directory_test(async (t, root) => {51 const handle = await createEmptyFile(t, 'write_appends_object_string', root);52 const stream = await handle.createWritable();53 await stream.write('12345');54 await stream.write({type: 'write', data: '67890'});55 await stream.close();56 assert_equals(await getFileContents(handle), '1234567890');57 assert_equals(await getFileSize(handle), 10);58}, 'write() WriteParams without position and string appends');59directory_test(async (t, root) => {60 const handle = await createEmptyFile(t, 'write_appends_object_blob', root);61 const stream = await handle.createWritable();62 await stream.write('12345');63 await stream.write({type: 'write', data: new Blob(['67890'])});64 await stream.close();65 assert_equals(await getFileContents(handle), '1234567890');66 assert_equals(await getFileSize(handle), 10);67}, 'write() WriteParams without position and blob appends');68directory_test(async (t, root) => {69 const handle = await createEmptyFile(t, 'string_with_offset', root);70 const stream = await handle.createWritable();71 await stream.write('1234567890');72 await stream.write({type: 'write', position: 4, data: 'abc'});73 await stream.close();74 assert_equals(await getFileContents(handle), '1234abc890');75 assert_equals(await getFileSize(handle), 10);76}, 'write() called with a string and a valid offset');77directory_test(async (t, root) => {78const handle = await createEmptyFile(t, 'blob_with_offset', root);79const stream = await handle.createWritable();80await stream.write('1234567890');81await stream.write({type: 'write', position: 4, data: new Blob(['abc'])});82await stream.close();83assert_equals(await getFileContents(handle), '1234abc890');84assert_equals(await getFileSize(handle), 10);85}, 'write() called with a blob and a valid offset');86directory_test(async (t, root) => {87 const handle = await createEmptyFile(t, 'bad_offset', root);88 const stream = await handle.createWritable();89 await promise_rejects_dom(90 t, 'InvalidStateError', stream.write({type: 'write', position: 4, data: new Blob(['abc'])}));91 await promise_rejects_js(92 t, TypeError, stream.close(), 'stream is already closed');93 assert_equals(await getFileContents(handle), '');94 assert_equals(await getFileSize(handle), 0);95}, 'write() called with an invalid offset');96directory_test(async (t, root) => {97 const handle = await createEmptyFile(t, 'empty_string', root);98 const stream = await handle.createWritable();99 await stream.write('');100 await stream.close();101 assert_equals(await getFileContents(handle), '');102 assert_equals(await getFileSize(handle), 0);103}, 'write() with an empty string to an empty file');104directory_test(async (t, root) => {105 const handle = await createEmptyFile(t, 'valid_utf8_string', root);106 const stream = await handle.createWritable();107 await stream.write('foo🤘');108 await stream.close();109 assert_equals(await getFileContents(handle), 'foo🤘');110 assert_equals(await getFileSize(handle), 7);111}, 'write() with a valid utf-8 string');112directory_test(async (t, root) => {113 const handle = await createEmptyFile(t, 'string_with_unix_line_ending', root);114 const stream = await handle.createWritable();115 await stream.write('foo\n');116 await stream.close();117 assert_equals(await getFileContents(handle), 'foo\n');118 assert_equals(await getFileSize(handle), 4);119}, 'write() with a string with unix line ending preserved');120directory_test(async (t, root) => {121 const handle =122 await createEmptyFile(t, 'string_with_windows_line_ending', root);123 const stream = await handle.createWritable();124 await stream.write('foo\r\n');125 await stream.close();126 assert_equals(await getFileContents(handle), 'foo\r\n');127 assert_equals(await getFileSize(handle), 5);128}, 'write() with a string with windows line ending preserved');129directory_test(async (t, root) => {130 const handle = await createEmptyFile(t, 'empty_array_buffer', root);131 const stream = await handle.createWritable();132 const buf = new ArrayBuffer(0);133 await stream.write(buf);134 await stream.close();135 assert_equals(await getFileContents(handle), '');136 assert_equals(await getFileSize(handle), 0);137}, 'write() with an empty array buffer to an empty file');138directory_test(async (t, root) => {139 const handle =140 await createEmptyFile(t, 'valid_string_typed_byte_array', root);141 const stream = await handle.createWritable();142 const buf = new ArrayBuffer(3);143 const intView = new Uint8Array(buf);144 intView[0] = 0x66;145 intView[1] = 0x6f;146 intView[2] = 0x6f;147 await stream.write(buf);148 await stream.close();149 assert_equals(await getFileContents(handle), 'foo');150 assert_equals(await getFileSize(handle), 3);151}, 'write() with a valid typed array buffer');152directory_test(async (t, root) => {153 const dir = await createDirectory(t, 'parent_dir', root);154 const file_name = 'close_fails_when_dir_removed.txt';155 const handle = await createEmptyFile(t, file_name, dir);156 const stream = await handle.createWritable();157 await stream.write('foo');158 await root.removeEntry('parent_dir', {recursive: true});159 await promise_rejects_dom(t, 'NotFoundError', stream.close());160}, 'atomic writes: close() fails when parent directory is removed');161directory_test(async (t, root) => {162 const handle = await createEmptyFile(t, 'atomic_writes.txt', root);163 const stream = await handle.createWritable();164 await stream.write('foox');165 const stream2 = await handle.createWritable();166 await stream2.write('bar');167 assert_equals(await getFileSize(handle), 0);168 await stream2.close();169 assert_equals(await getFileContents(handle), 'bar');170 assert_equals(await getFileSize(handle), 3);171 await stream.close();172 assert_equals(await getFileContents(handle), 'foox');173 assert_equals(await getFileSize(handle), 4);174}, 'atomic writes: writable file streams make atomic changes on close');175directory_test(async (t, root) => {176 const handle = await createEmptyFile(t, 'atomic_write_after_close.txt', root);177 const stream = await handle.createWritable();178 await stream.write('foo');179 await stream.close();180 assert_equals(await getFileContents(handle), 'foo');181 assert_equals(await getFileSize(handle), 3);182 await promise_rejects_js(183 t, TypeError, stream.write('abc'));184}, 'atomic writes: write() after close() fails');185directory_test(async (t, root) => {186 const handle =187 await createEmptyFile(t, 'atomic_truncate_after_close.txt', root);188 const stream = await handle.createWritable();189 await stream.write('foo');190 await stream.close();191 assert_equals(await getFileContents(handle), 'foo');192 assert_equals(await getFileSize(handle), 3);193 await promise_rejects_js(t, TypeError, stream.truncate(0));194}, 'atomic writes: truncate() after close() fails');195directory_test(async (t, root) => {196 const handle = await createEmptyFile(t, 'atomic_close_after_close.txt', root);197 const stream = await handle.createWritable();198 await stream.write('foo');199 await stream.close();200 assert_equals(await getFileContents(handle), 'foo');201 assert_equals(await getFileSize(handle), 3);202 await promise_rejects_js(t, TypeError, stream.close());203}, 'atomic writes: close() after close() fails');204directory_test(async (t, root) => {205 const handle = await createEmptyFile(t, 'there_can_be_only_one.txt', root);206 const stream = await handle.createWritable();207 await stream.write('foo');208 // This test might be flaky if there is a race condition allowing209 // close() to be called multiple times.210 const success_promises =211 [...Array(100)].map(() => stream.close().then(() => 1).catch(() => 0));212 const close_attempts = await Promise.all(success_promises);213 const success_count = close_attempts.reduce((x, y) => x + y);214 assert_equals(success_count, 1);215}, 'atomic writes: only one close() operation may succeed');216directory_test(async (t, root) => {217 const dir = await createDirectory(t, 'parent_dir', root);218 const file_name = 'atomic_writable_file_stream_persists_removed.txt';219 const handle = await createFileWithContents(t, file_name, 'foo', dir);220 const stream = await handle.createWritable();221 await stream.write('bar');222 await dir.removeEntry(file_name);223 await promise_rejects_dom(t, 'NotFoundError', getFileContents(handle));224 await stream.close();225 assert_equals(await getFileContents(handle), 'bar');226 assert_equals(await getFileSize(handle), 3);227}, 'atomic writes: writable file stream persists file on close, even if file is removed');228directory_test(async (t, root) => {229 const handle = await createEmptyFile(t, 'writer_written', root);230 const stream = await handle.createWritable();231 const writer = stream.getWriter();232 await writer.write('foo');233 await writer.write(new Blob(['bar']));234 await writer.write({type: 'seek', position: 0});235 await writer.write({type: 'write', data: 'baz'});236 await writer.close();237 assert_equals(await getFileContents(handle), 'bazbar');238 assert_equals(await getFileSize(handle), 6);239}, 'getWriter() can be used');240directory_test(async (t, root) => {241 const handle = await createFileWithContents(242 t, 'content.txt', 'very long string', root);243 const stream = await handle.createWritable();244 await promise_rejects_dom(245 t, "SyntaxError", stream.write({type: 'truncate'}), 'truncate without size');246}, 'WriteParams: truncate missing size param');247directory_test(async (t, root) => {248 const handle = await createEmptyFile(t, 'content.txt', root);249 const stream = await handle.createWritable();250 await promise_rejects_dom(251 t, "SyntaxError", stream.write({type: 'write'}), 'write without data');...

Full Screen

Full Screen

FileSystemWriter.tentative.https.window.js

Source:FileSystemWriter.tentative.https.window.js Github

copy

Full Screen

...5 const handle = await createEmptyFile(t, 'empty_blob');6 const writer = await handle.createWriter();7 await writer.write(0, new Blob([]));8 await writer.close();9 assert_equals(await getFileContents(handle), '');10 assert_equals(await getFileSize(handle), 0);11}, 'write() with an empty blob to an empty file');12promise_test(async t => {13 const handle = await createEmptyFile(t, 'valid_blob');14 const writer = await handle.createWriter();15 await writer.write(0, new Blob(['1234567890']));16 await writer.close();17 assert_equals(await getFileContents(handle), '1234567890');18 assert_equals(await getFileSize(handle), 10);19}, 'write() a blob to an empty file');20promise_test(async t => {21 const handle = await createEmptyFile(t, 'blob_with_offset');22 const writer = await handle.createWriter();23 await writer.write(0, new Blob(['1234567890']));24 await writer.write(4, new Blob(['abc']));25 await writer.close();26 assert_equals(await getFileContents(handle), '1234abc890');27 assert_equals(await getFileSize(handle), 10);28}, 'write() called with a blob and a valid offset');29promise_test(async t => {30 const handle = await createEmptyFile(t, 'bad_offset');31 const writer = await handle.createWriter();32 await promise_rejects(t, 'InvalidStateError', writer.write(4, new Blob(['abc'])));33 await writer.close();34 assert_equals(await getFileContents(handle), '');35 assert_equals(await getFileSize(handle), 0);36}, 'write() called with an invalid offset');37promise_test(async t => {38 const handle = await createEmptyFile(t, 'empty_string');39 const writer = await handle.createWriter();40 await writer.write(0, '');41 await writer.close();42 assert_equals(await getFileContents(handle), '');43 assert_equals(await getFileSize(handle), 0);44}, 'write() with an empty string to an empty file');45promise_test(async t => {46 const handle = await createEmptyFile(t, 'valid_utf8_string');47 const writer = await handle.createWriter();48 await writer.write(0, 'foo🤘');49 await writer.close();50 assert_equals(await getFileContents(handle), 'foo🤘');51 assert_equals(await getFileSize(handle), 7);52}, 'write() with a valid utf-8 string');53promise_test(async t => {54 const handle = await createEmptyFile(t, 'string_with_unix_line_ending');55 const writer = await handle.createWriter();56 await writer.write(0, 'foo\n');57 await writer.close();58 assert_equals(await getFileContents(handle), 'foo\n');59 assert_equals(await getFileSize(handle), 4);60}, 'write() with a string with unix line ending preserved');61promise_test(async t => {62 const handle = await createEmptyFile(t, 'string_with_windows_line_ending');63 const writer = await handle.createWriter();64 await writer.write(0, 'foo\r\n');65 await writer.close();66 assert_equals(await getFileContents(handle), 'foo\r\n');67 assert_equals(await getFileSize(handle), 5);68}, 'write() with a string with windows line ending preserved');69promise_test(async t => {70 const handle = await createEmptyFile(t, 'empty_array_buffer');71 const writer = await handle.createWriter();72 let buf = new ArrayBuffer(0);73 await writer.write(0, buf);74 await writer.close();75 assert_equals(await getFileContents(handle), '');76 assert_equals(await getFileSize(handle), 0);77}, 'write() with an empty array buffer to an empty file');78promise_test(async t => {79 const handle = await createEmptyFile(t, 'valid_string_typed_byte_array');80 const writer = await handle.createWriter();81 let buf = new ArrayBuffer(3);82 let intView = new Uint8Array(buf);83 intView[0] = 0x66;84 intView[1] = 0x6f;85 intView[2] = 0x6f;86 await writer.write(0, buf);87 await writer.close();88 assert_equals(await getFileContents(handle), 'foo');89 assert_equals(await getFileSize(handle), 3);90}, 'write() with a valid typed array buffer');91promise_test(async t => {92 const handle = await createEmptyFile(t, 'trunc_shrink');93 const writer = await handle.createWriter();94 await writer.write(0, new Blob(['1234567890']));95 await writer.truncate(5);96 await writer.close();97 assert_equals(await getFileContents(handle), '12345');98 assert_equals(await getFileSize(handle), 5);99}, 'truncate() to shrink a file');100promise_test(async t => {101 const handle = await createEmptyFile(t, 'trunc_grow');102 const writer = await handle.createWriter();103 await writer.write(0, new Blob(['abc']));104 await writer.truncate(5);105 await writer.close();106 assert_equals(await getFileContents(handle), 'abc\0\0');107 assert_equals(await getFileSize(handle), 5);108}, 'truncate() to grow a file');109promise_test(async t => {110 const root = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });111 const dir = await createDirectory(t, 'parent_dir', root);112 const file_name = 'create_writer_fails_when_dir_removed.txt';113 const handle = await createEmptyFile(t, file_name, dir);114 await root.removeEntry('parent_dir', {recursive: true});115 await promise_rejects(t, 'NotFoundError', handle.createWriter());116}, 'createWriter() fails when parent directory is removed');117promise_test(async t => {118 const root = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });119 const dir = await createDirectory(t, 'parent_dir', root);120 const file_name = 'write_fails_when_dir_removed.txt';121 const handle = await createEmptyFile(t, file_name, dir);122 const writer = await handle.createWriter();123 await root.removeEntry('parent_dir', {recursive: true});124 await promise_rejects(t, 'NotFoundError', writer.write(0, new Blob(['foo'])));125}, 'write() fails when parent directory is removed');126promise_test(async t => {127 const root = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });128 const dir = await createDirectory(t, 'parent_dir', root);129 const file_name = 'truncate_fails_when_dir_removed.txt';130 const handle = await createEmptyFile(t, file_name, dir);131 const writer = await handle.createWriter();132 await root.removeEntry('parent_dir', {recursive: true});133 await promise_rejects(t, 'NotFoundError', writer.truncate(0));134}, 'truncate() fails when parent directory is removed');135promise_test(async t => {136 const root = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });137 const dir = await createDirectory(t, 'parent_dir', root);138 const file_name = 'close_fails_when_dir_removed.txt';139 const handle = await createEmptyFile(t, file_name, dir);140 const writer = await handle.createWriter();141 await writer.write(0, new Blob(['foo']));142 await root.removeEntry('parent_dir', {recursive: true});143 await promise_rejects(t, 'NotFoundError', writer.close());144}, 'atomic writes: close() fails when parent directory is removed');145promise_test(async t => {146 const handle = await createEmptyFile(t, 'atomic_writes.txt');147 const writer = await handle.createWriter();148 await writer.write(0, new Blob(['foox']));149 const writer2 = await handle.createWriter();150 await writer2.write(0, new Blob(['bar']));151 assert_equals(await getFileSize(handle), 0);152 await writer2.close();153 assert_equals(await getFileContents(handle), 'bar');154 assert_equals(await getFileSize(handle), 3);155 await writer.close();156 assert_equals(await getFileContents(handle), 'foox');157 assert_equals(await getFileSize(handle), 4);158}, 'atomic writes: writers make atomic changes on close');159promise_test(async t => {160 const handle = await createEmptyFile(t, 'atomic_write_after_close.txt');161 const writer = await handle.createWriter();162 await writer.write(0, new Blob(['foo']));163 await writer.close();164 assert_equals(await getFileContents(handle), 'foo');165 assert_equals(await getFileSize(handle), 3);166 await promise_rejects(t, 'InvalidStateError', writer.write(0, new Blob(['abc'])));167}, 'atomic writes: write() after close() fails');168promise_test(async t => {169 const handle = await createEmptyFile(t, 'atomic_truncate_after_close.txt');170 const writer = await handle.createWriter();171 await writer.write(0, new Blob(['foo']));172 await writer.close();173 assert_equals(await getFileContents(handle), 'foo');174 assert_equals(await getFileSize(handle), 3);175 await promise_rejects(t, 'InvalidStateError', writer.truncate(0));176}, 'atomic writes: truncate() after close() fails');177promise_test(async t => {178 const handle = await createEmptyFile(t, 'atomic_close_after_close.txt');179 const writer = await handle.createWriter();180 await writer.write(0, new Blob(['foo']));181 await writer.close();182 assert_equals(await getFileContents(handle), 'foo');183 assert_equals(await getFileSize(handle), 3);184 await promise_rejects(t, 'InvalidStateError', writer.close());185}, 'atomic writes: close() after close() fails');186promise_test(async t => {187 const handle = await createEmptyFile(t, 'there_can_be_only_one.txt');188 const writer = await handle.createWriter();189 await writer.write(0, new Blob(['foo']));190 // This test might be flaky if there is a race condition allowing191 // close() to be called multiple times.192 let success_promises = [...Array(100)].map(() => writer193 .close()194 .then(() => 1)195 .catch(() => 0));196 let close_attempts = await Promise.all(success_promises);197 let success_count = close_attempts.reduce((x,y) => x + y);198 assert_equals(success_count, 1);199}, 'atomic writes: only one close() operation may succeed');200promise_test(async t => {201 const handle = await createFileWithContents(t, 'atomic_file_is_copied.txt', 'fooks');202 const writer = await handle.createWriter({keepExistingData: true});203 await writer.write(0, new Blob(['bar']));204 await writer.close();205 assert_equals(await getFileContents(handle), 'barks');206 assert_equals(await getFileSize(handle), 5);207}, 'createWriter({keepExistingData: true}): atomic writer initialized with source contents');208promise_test(async t => {209 const handle = await createFileWithContents(t, 'atomic_file_is_not_copied.txt', 'very long string');210 const writer = await handle.createWriter({keepExistingData: false});211 await writer.write(0, new Blob(['bar']));212 assert_equals(await getFileContents(handle), 'very long string');213 await writer.close();214 assert_equals(await getFileContents(handle), 'bar');215 assert_equals(await getFileSize(handle), 3);216}, 'createWriter({keepExistingData: false}): atomic writer initialized with empty file');217promise_test(async t => {218 const root = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });219 const dir = await createDirectory(t, 'parent_dir', root);220 const file_name = 'atomic_writer_persists_removed.txt';221 const handle = await createFileWithContents(t, file_name, 'foo', dir);222 const writer = await handle.createWriter();223 await writer.write(0, new Blob(['bar']));224 await dir.removeEntry(file_name);225 await promise_rejects(t, 'NotFoundError', getFileContents(handle));226 await writer.close();227 assert_equals(await getFileContents(handle), 'bar');228 assert_equals(await getFileSize(handle), 3);...

Full Screen

Full Screen

FileSystemWriter.js

Source:FileSystemWriter.js Github

copy

Full Screen

2 const handle = await createEmptyFile(t, 'empty_blob', root);3 const writer = await handle.createWriter();4 await writer.write(0, new Blob([]));5 await writer.close();6 assert_equals(await getFileContents(handle), '');7 assert_equals(await getFileSize(handle), 0);8}, 'write() with an empty blob to an empty file');9directory_test(async (t, root) => {10 const handle = await createEmptyFile(t, 'valid_blob', root);11 const writer = await handle.createWriter();12 await writer.write(0, new Blob(['1234567890']));13 await writer.close();14 assert_equals(await getFileContents(handle), '1234567890');15 assert_equals(await getFileSize(handle), 10);16}, 'write() a blob to an empty file');17directory_test(async (t, root) => {18 const handle = await createEmptyFile(t, 'blob_with_offset', root);19 const writer = await handle.createWriter();20 await writer.write(0, new Blob(['1234567890']));21 await writer.write(4, new Blob(['abc']));22 await writer.close();23 assert_equals(await getFileContents(handle), '1234abc890');24 assert_equals(await getFileSize(handle), 10);25}, 'write() called with a blob and a valid offset');26directory_test(async (t, root) => {27 const handle = await createEmptyFile(t, 'bad_offset', root);28 const writer = await handle.createWriter();29 await promise_rejects(30 t, 'InvalidStateError', writer.write(4, new Blob(['abc'])));31 await writer.close();32 assert_equals(await getFileContents(handle), '');33 assert_equals(await getFileSize(handle), 0);34}, 'write() called with an invalid offset');35directory_test(async (t, root) => {36 const handle = await createEmptyFile(t, 'empty_string', root);37 const writer = await handle.createWriter();38 await writer.write(0, '');39 await writer.close();40 assert_equals(await getFileContents(handle), '');41 assert_equals(await getFileSize(handle), 0);42}, 'write() with an empty string to an empty file');43directory_test(async (t, root) => {44 const handle = await createEmptyFile(t, 'valid_utf8_string', root);45 const writer = await handle.createWriter();46 await writer.write(0, 'foo🤘');47 await writer.close();48 assert_equals(await getFileContents(handle), 'foo🤘');49 assert_equals(await getFileSize(handle), 7);50}, 'write() with a valid utf-8 string');51directory_test(async (t, root) => {52 const handle = await createEmptyFile(t, 'string_with_unix_line_ending', root);53 const writer = await handle.createWriter();54 await writer.write(0, 'foo\n');55 await writer.close();56 assert_equals(await getFileContents(handle), 'foo\n');57 assert_equals(await getFileSize(handle), 4);58}, 'write() with a string with unix line ending preserved');59directory_test(async (t, root) => {60 const handle =61 await createEmptyFile(t, 'string_with_windows_line_ending', root);62 const writer = await handle.createWriter();63 await writer.write(0, 'foo\r\n');64 await writer.close();65 assert_equals(await getFileContents(handle), 'foo\r\n');66 assert_equals(await getFileSize(handle), 5);67}, 'write() with a string with windows line ending preserved');68directory_test(async (t, root) => {69 const handle = await createEmptyFile(t, 'empty_array_buffer', root);70 const writer = await handle.createWriter();71 let buf = new ArrayBuffer(0);72 await writer.write(0, buf);73 await writer.close();74 assert_equals(await getFileContents(handle), '');75 assert_equals(await getFileSize(handle), 0);76}, 'write() with an empty array buffer to an empty file');77directory_test(async (t, root) => {78 const handle =79 await createEmptyFile(t, 'valid_string_typed_byte_array', root);80 const writer = await handle.createWriter();81 let buf = new ArrayBuffer(3);82 let intView = new Uint8Array(buf);83 intView[0] = 0x66;84 intView[1] = 0x6f;85 intView[2] = 0x6f;86 await writer.write(0, buf);87 await writer.close();88 assert_equals(await getFileContents(handle), 'foo');89 assert_equals(await getFileSize(handle), 3);90}, 'write() with a valid typed array buffer');91directory_test(async (t, root) => {92 const handle = await createEmptyFile(t, 'trunc_shrink', root);93 const writer = await handle.createWriter();94 await writer.write(0, new Blob(['1234567890']));95 await writer.truncate(5);96 await writer.close();97 assert_equals(await getFileContents(handle), '12345');98 assert_equals(await getFileSize(handle), 5);99}, 'truncate() to shrink a file');100directory_test(async (t, root) => {101 const handle = await createEmptyFile(t, 'trunc_grow', root);102 const writer = await handle.createWriter();103 await writer.write(0, new Blob(['abc']));104 await writer.truncate(5);105 await writer.close();106 assert_equals(await getFileContents(handle), 'abc\0\0');107 assert_equals(await getFileSize(handle), 5);108}, 'truncate() to grow a file');109directory_test(async (t, root) => {110 const dir = await createDirectory(t, 'parent_dir', root);111 const file_name = 'create_writer_fails_when_dir_removed.txt';112 const handle = await createEmptyFile(t, file_name, dir);113 await root.removeEntry('parent_dir', {recursive: true});114 await promise_rejects(t, 'NotFoundError', handle.createWriter());115}, 'createWriter() fails when parent directory is removed');116directory_test(async (t, root) => {117 const dir = await createDirectory(t, 'parent_dir', root);118 const file_name = 'write_fails_when_dir_removed.txt';119 const handle = await createEmptyFile(t, file_name, dir);120 const writer = await handle.createWriter();121 await root.removeEntry('parent_dir', {recursive: true});122 await promise_rejects(t, 'NotFoundError', writer.write(0, new Blob(['foo'])));123}, 'write() fails when parent directory is removed');124directory_test(async (t, root) => {125 const dir = await createDirectory(t, 'parent_dir', root);126 const file_name = 'truncate_fails_when_dir_removed.txt';127 const handle = await createEmptyFile(t, file_name, dir);128 const writer = await handle.createWriter();129 await root.removeEntry('parent_dir', {recursive: true});130 await promise_rejects(t, 'NotFoundError', writer.truncate(0));131}, 'truncate() fails when parent directory is removed');132directory_test(async (t, root) => {133 const dir = await createDirectory(t, 'parent_dir', root);134 const file_name = 'close_fails_when_dir_removed.txt';135 const handle = await createEmptyFile(t, file_name, dir);136 const writer = await handle.createWriter();137 await writer.write(0, new Blob(['foo']));138 await root.removeEntry('parent_dir', {recursive: true});139 await promise_rejects(t, 'NotFoundError', writer.close());140}, 'atomic writes: close() fails when parent directory is removed');141directory_test(async (t, root) => {142 const handle = await createEmptyFile(t, 'atomic_writes.txt', root);143 const writer = await handle.createWriter();144 await writer.write(0, new Blob(['foox']));145 const writer2 = await handle.createWriter();146 await writer2.write(0, new Blob(['bar']));147 assert_equals(await getFileSize(handle), 0);148 await writer2.close();149 assert_equals(await getFileContents(handle), 'bar');150 assert_equals(await getFileSize(handle), 3);151 await writer.close();152 assert_equals(await getFileContents(handle), 'foox');153 assert_equals(await getFileSize(handle), 4);154}, 'atomic writes: writers make atomic changes on close');155directory_test(async (t, root) => {156 const handle = await createEmptyFile(t, 'atomic_write_after_close.txt', root);157 const writer = await handle.createWriter();158 await writer.write(0, new Blob(['foo']));159 await writer.close();160 assert_equals(await getFileContents(handle), 'foo');161 assert_equals(await getFileSize(handle), 3);162 await promise_rejects(163 t, 'InvalidStateError', writer.write(0, new Blob(['abc'])));164}, 'atomic writes: write() after close() fails');165directory_test(async (t, root) => {166 const handle =167 await createEmptyFile(t, 'atomic_truncate_after_close.txt', root);168 const writer = await handle.createWriter();169 await writer.write(0, new Blob(['foo']));170 await writer.close();171 assert_equals(await getFileContents(handle), 'foo');172 assert_equals(await getFileSize(handle), 3);173 await promise_rejects(t, 'InvalidStateError', writer.truncate(0));174}, 'atomic writes: truncate() after close() fails');175directory_test(async (t, root) => {176 const handle = await createEmptyFile(t, 'atomic_close_after_close.txt', root);177 const writer = await handle.createWriter();178 await writer.write(0, new Blob(['foo']));179 await writer.close();180 assert_equals(await getFileContents(handle), 'foo');181 assert_equals(await getFileSize(handle), 3);182 await promise_rejects(t, 'InvalidStateError', writer.close());183}, 'atomic writes: close() after close() fails');184directory_test(async (t, root) => {185 const handle = await createEmptyFile(t, 'there_can_be_only_one.txt', root);186 const writer = await handle.createWriter();187 await writer.write(0, new Blob(['foo']));188 // This test might be flaky if there is a race condition allowing189 // close() to be called multiple times.190 let success_promises =191 [...Array(100)].map(() => writer.close().then(() => 1).catch(() => 0));192 let close_attempts = await Promise.all(success_promises);193 let success_count = close_attempts.reduce((x, y) => x + y);194 assert_equals(success_count, 1);195}, 'atomic writes: only one close() operation may succeed');196directory_test(async (t, root) => {197 const handle = await createFileWithContents(198 t, 'atomic_file_is_copied.txt', 'fooks', root);199 const writer = await handle.createWriter({keepExistingData: true});200 await writer.write(0, new Blob(['bar']));201 await writer.close();202 assert_equals(await getFileContents(handle), 'barks');203 assert_equals(await getFileSize(handle), 5);204}, 'createWriter({keepExistingData: true}): atomic writer initialized with source contents');205directory_test(async (t, root) => {206 const handle = await createFileWithContents(207 t, 'atomic_file_is_not_copied.txt', 'very long string', root);208 const writer = await handle.createWriter({keepExistingData: false});209 await writer.write(0, new Blob(['bar']));210 assert_equals(await getFileContents(handle), 'very long string');211 await writer.close();212 assert_equals(await getFileContents(handle), 'bar');213 assert_equals(await getFileSize(handle), 3);214}, 'createWriter({keepExistingData: false}): atomic writer initialized with empty file');215directory_test(async (t, root) => {216 const dir = await createDirectory(t, 'parent_dir', root);217 const file_name = 'atomic_writer_persists_removed.txt';218 const handle = await createFileWithContents(t, file_name, 'foo', dir);219 const writer = await handle.createWriter();220 await writer.write(0, new Blob(['bar']));221 await dir.removeEntry(file_name);222 await promise_rejects(t, 'NotFoundError', getFileContents(handle));223 await writer.close();224 assert_equals(await getFileContents(handle), 'bar');225 assert_equals(await getFileSize(handle), 3);...

Full Screen

Full Screen

indent.js

Source:indent.js Github

copy

Full Screen

...21 const fileName = 'tab.json';22 const args = [ `${targetDirectory}/${fileName}` ];23 const result = utils.runAzpBumpCli(args, '-i t');24 assert.deepEqual(result.code, utils.successfulReturnCode);25 const bumpedTaskFileContents = utils.getFileContents(`${targetDirectoryPath}/${fileName}`);26 const expectedTaskFileContents = utils.getFileContents(expectedBumpTabFilePath);27 assert.deepEqual(bumpedTaskFileContents, expectedTaskFileContents);28 });29 test('Should set indent to tab when t specified for indent', () => {30 const fileName = 'tab2.json';31 const args = [ `${targetDirectory}/${fileName}` ];32 const result = utils.runAzpBumpCli(args, '--indent t');33 assert.deepEqual(result.code, utils.successfulReturnCode);34 const bumpedTaskFileContents = utils.getFileContents(`${targetDirectoryPath}/${fileName}`);35 const expectedTaskFileContents = utils.getFileContents(expectedBumpTabFilePath);36 assert.deepEqual(bumpedTaskFileContents, expectedTaskFileContents);37 });38 test('Should set indent to tab when tab specified for shorthand indent', () => {39 const fileName = 'tab3.json';40 const args = [ `${targetDirectory}/${fileName}` ];41 const result = utils.runAzpBumpCli(args, '-i t');42 assert.deepEqual(result.code, utils.successfulReturnCode);43 const bumpedTaskFileContents = utils.getFileContents(`${targetDirectoryPath}/${fileName}`);44 const expectedTaskFileContents = utils.getFileContents(expectedBumpTabFilePath);45 assert.deepEqual(bumpedTaskFileContents, expectedTaskFileContents);46 });47 test('Should set indent to tab when tab specified for indent', () => {48 const fileName = 'tab4.json';49 const args = [ `${targetDirectory}/${fileName}` ];50 const result = utils.runAzpBumpCli(args, '--indent t');51 assert.deepEqual(result.code, utils.successfulReturnCode);52 const bumpedTaskFileContents = utils.getFileContents(`${targetDirectoryPath}/${fileName}`);53 const expectedTaskFileContents = utils.getFileContents(expectedBumpTabFilePath);54 assert.deepEqual(bumpedTaskFileContents, expectedTaskFileContents);55 });56 test('Should set indent to tab when tab character specified for shorthand indent', () => {57 const fileName = 'tab5.json';58 const args = [ `${targetDirectory}/${fileName}` ];59 const result = utils.runAzpBumpCli(args, '-i \\t');60 assert.deepEqual(result.code, utils.successfulReturnCode);61 const bumpedTaskFileContents = utils.getFileContents(`${targetDirectoryPath}/${fileName}`);62 const expectedTaskFileContents = utils.getFileContents(expectedBumpTabFilePath);63 assert.deepEqual(bumpedTaskFileContents, expectedTaskFileContents);64 });65 test('Should set indent to tab when tab character specified for indent', () => {66 const fileName = 'tab6.json';67 const args = [ `${targetDirectory}/${fileName}` ];68 const result = utils.runAzpBumpCli(args, '--indent \\t');69 assert.deepEqual(result.code, utils.successfulReturnCode);70 const bumpedTaskFileContents = utils.getFileContents(`${targetDirectoryPath}/${fileName}`);71 const expectedTaskFileContents = utils.getFileContents(expectedBumpTabFilePath);72 assert.deepEqual(bumpedTaskFileContents, expectedTaskFileContents);73 });74 test('Should set indent to two spaces when 2 specified for shorthand indent', () => {75 const fileName = 'twospace.json';76 const args = [ `${targetDirectory}/${fileName}` ];77 const result = utils.runAzpBumpCli(args, '-i 2');78 assert.deepEqual(result.code, utils.successfulReturnCode);79 const bumpedTaskFileContents = utils.getFileContents(`${targetDirectoryPath}/${fileName}`);80 const expectedTaskFileContents = utils.getFileContents(`${targetDirectoryPath}/expected/${fileName}`);81 assert.deepEqual(bumpedTaskFileContents, expectedTaskFileContents);82 });83 test('Should set indent to two spaces when 2 specified for indent', () => {84 const fileName = 'twospace2.json';85 const args = [ `${targetDirectory}/${fileName}` ];86 const result = utils.runAzpBumpCli(args, '--indent 2');87 assert.deepEqual(result.code, utils.successfulReturnCode);88 const bumpedTaskFileContents = utils.getFileContents(`${targetDirectoryPath}/${fileName}`);89 const expectedTaskFileContents = utils.getFileContents(`${targetDirectoryPath}/expected/twospace.json`);90 assert.deepEqual(bumpedTaskFileContents, expectedTaskFileContents);91 });92 test('Should set indent to four spaces when 4 specified for shorthand indent', () => {93 const fileName = 'fourspace.json';94 const args = [ `${targetDirectory}/${fileName}` ];95 const result = utils.runAzpBumpCli(args, '-i 4');96 assert.deepEqual(result.code, utils.successfulReturnCode);97 const bumpedTaskFileContents = utils.getFileContents(`${targetDirectoryPath}/${fileName}`);98 const expectedTaskFileContents = utils.getFileContents(`${targetDirectoryPath}/expected/${fileName}`);99 assert.deepEqual(bumpedTaskFileContents, expectedTaskFileContents);100 });101 test('Should set indent to four spaces when 4 specified for indent', () => {102 const fileName = 'fourspace2.json';103 const args = [ `${targetDirectory}/${fileName}` ];104 const result = utils.runAzpBumpCli(args, '--indent 4');105 assert.deepEqual(result.code, utils.successfulReturnCode);106 const bumpedTaskFileContents = utils.getFileContents(`${targetDirectoryPath}/${fileName}`);107 const expectedTaskFileContents = utils.getFileContents(`${targetDirectoryPath}/expected/fourspace.json`);108 assert.deepEqual(bumpedTaskFileContents, expectedTaskFileContents);109 });...

Full Screen

Full Screen

NativeFileSystemWritableFileStream.tentative.window.js

Source:NativeFileSystemWritableFileStream.tentative.window.js Github

copy

Full Screen

...4promise_test(async t => {5 const handle = await createEmptyFile(t, 'empty_blob');6 const stream = await handle.createWritable();7 await stream.write(0, new Blob([]));8 assert_equals(await getFileContents(handle), '');9 assert_equals(await getFileSize(handle), 0);10}, 'write() with an empty blob to an empty file');11promise_test(async t => {12 const handle = await createEmptyFile(t, 'valid_blob');13 const stream = await handle.createWritable();14 await stream.write(0, new Blob(['1234567890']));15 assert_equals(await getFileContents(handle), '1234567890');16 assert_equals(await getFileSize(handle), 10);17}, 'write() a blob to an empty file');18promise_test(async t => {19 const handle = await createEmptyFile(t, 'blob_with_offset');20 const stream = await handle.createWritable();21 await stream.write(0, new Blob(['1234567890']));22 await stream.write(4, new Blob(['abc']));23 assert_equals(await getFileContents(handle), '1234abc890');24 assert_equals(await getFileSize(handle), 10);25}, 'write() called with a blob and a valid offset');26promise_test(async t => {27 const handle = await createEmptyFile(t, 'bad_offset');28 const stream = await handle.createWritable();29 await promise_rejects(t, 'InvalidStateError', stream.write(4, new Blob(['abc'])));30 assert_equals(await getFileContents(handle), '');31 assert_equals(await getFileSize(handle), 0);32}, 'write() called with an invalid offset');33promise_test(async t => {34 const handle = await createEmptyFile(t, 'empty_string');35 const stream = await handle.createWritable();36 await stream.write(0, '');37 assert_equals(await getFileContents(handle), '');38 assert_equals(await getFileSize(handle), 0);39}, 'write() with an empty string to an empty file');40promise_test(async t => {41 const handle = await createEmptyFile(t, 'valid_utf8_string');42 const stream = await handle.createWritable();43 await stream.write(0, 'foo🤘');44 assert_equals(await getFileContents(handle), 'foo🤘');45 assert_equals(await getFileSize(handle), 7);46}, 'write() with a valid utf-8 string');47promise_test(async t => {48 const handle = await createEmptyFile(t, 'string_with_unix_line_ending');49 const stream = await handle.createWritable();50 await stream.write(0, 'foo\n');51 assert_equals(await getFileContents(handle), 'foo\n');52 assert_equals(await getFileSize(handle), 4);53}, 'write() with a string with unix line ending preserved');54promise_test(async t => {55 const handle = await createEmptyFile(t, 'string_with_windows_line_ending');56 const stream = await handle.createWritable();57 await stream.write(0, 'foo\r\n');58 assert_equals(await getFileContents(handle), 'foo\r\n');59 assert_equals(await getFileSize(handle), 5);60}, 'write() with a string with windows line ending preserved');61promise_test(async t => {62 const handle = await createEmptyFile(t, 'empty_array_buffer');63 const stream = await handle.createWritable();64 let buf = new ArrayBuffer(0);65 await stream.write(0, buf);66 assert_equals(await getFileContents(handle), '');67 assert_equals(await getFileSize(handle), 0);68}, 'write() with an empty array buffer to an empty file');69promise_test(async t => {70 const handle = await createEmptyFile(t, 'valid_string_typed_byte_array');71 const stream = await handle.createWritable();72 let buf = new ArrayBuffer(3);73 let intView = new Uint8Array(buf);74 intView[0] = 0x66;75 intView[1] = 0x6f;76 intView[2] = 0x6f;77 await stream.write(0, buf);78 assert_equals(await getFileContents(handle), 'foo');79 assert_equals(await getFileSize(handle), 3);80}, 'write() with a valid typed array buffer');81promise_test(async t => {82 const handle = await createEmptyFile(t, 'trunc_shrink');83 const stream = await handle.createWritable();84 await stream.write(0, new Blob(['1234567890']));85 await stream.truncate(5);86 assert_equals(await getFileContents(handle), '12345');87 assert_equals(await getFileSize(handle), 5);88}, 'truncate() to shrink a file');89promise_test(async t => {90 const handle = await createEmptyFile(t, 'trunc_grow');91 const stream = await handle.createWritable();92 await stream.write(0, new Blob(['abc']));93 await stream.truncate(5);94 assert_equals(await getFileContents(handle), 'abc\0\0');95 assert_equals(await getFileSize(handle), 5);...

Full Screen

Full Screen

FileSystemWriter.tentative.window.js

Source:FileSystemWriter.tentative.window.js Github

copy

Full Screen

...4promise_test(async t => {5 const handle = await createEmptyFile(t, 'empty_blob');6 const writer = await handle.createWriter();7 await writer.write(0, new Blob([]));8 assert_equals(await getFileContents(handle), '');9 assert_equals(await getFileSize(handle), 0);10}, 'write() with an empty blob to an empty file');11promise_test(async t => {12 const handle = await createEmptyFile(t, 'valid_blob');13 const writer = await handle.createWriter();14 await writer.write(0, new Blob(['1234567890']));15 assert_equals(await getFileContents(handle), '1234567890');16 assert_equals(await getFileSize(handle), 10);17}, 'write() a blob to an empty file');18promise_test(async t => {19 const handle = await createEmptyFile(t, 'blob_with_offset');20 const writer = await handle.createWriter();21 await writer.write(0, new Blob(['1234567890']));22 await writer.write(4, new Blob(['abc']));23 assert_equals(await getFileContents(handle), '1234abc890');24 assert_equals(await getFileSize(handle), 10);25}, 'write() called with a blob and a valid offset');26promise_test(async t => {27 const handle = await createEmptyFile(t, 'bad_offset');28 const writer = await handle.createWriter();29 await promise_rejects(t, 'InvalidStateError', writer.write(4, new Blob(['abc'])));30 assert_equals(await getFileContents(handle), '');31 assert_equals(await getFileSize(handle), 0);32}, 'write() called with an invalid offset');33promise_test(async t => {34 const handle = await createEmptyFile(t, 'empty_string');35 const writer = await handle.createWriter();36 await writer.write(0, '');37 assert_equals(await getFileContents(handle), '');38 assert_equals(await getFileSize(handle), 0);39}, 'write() with an empty string to an empty file');40promise_test(async t => {41 const handle = await createEmptyFile(t, 'valid_utf8_string');42 const writer = await handle.createWriter();43 await writer.write(0, 'foo🤘');44 assert_equals(await getFileContents(handle), 'foo🤘');45 assert_equals(await getFileSize(handle), 7);46}, 'write() with a valid utf-8 string');47promise_test(async t => {48 const handle = await createEmptyFile(t, 'string_with_unix_line_ending');49 const writer = await handle.createWriter();50 await writer.write(0, 'foo\n');51 assert_equals(await getFileContents(handle), 'foo\n');52 assert_equals(await getFileSize(handle), 4);53}, 'write() with a string with unix line ending preserved');54promise_test(async t => {55 const handle = await createEmptyFile(t, 'string_with_windows_line_ending');56 const writer = await handle.createWriter();57 await writer.write(0, 'foo\r\n');58 assert_equals(await getFileContents(handle), 'foo\r\n');59 assert_equals(await getFileSize(handle), 5);60}, 'write() with a string with windows line ending preserved');61promise_test(async t => {62 const handle = await createEmptyFile(t, 'empty_array_buffer');63 const writer = await handle.createWriter();64 let buf = new ArrayBuffer(0);65 await writer.write(0, buf);66 assert_equals(await getFileContents(handle), '');67 assert_equals(await getFileSize(handle), 0);68}, 'write() with an empty array buffer to an empty file');69promise_test(async t => {70 const handle = await createEmptyFile(t, 'valid_string_typed_byte_array');71 const writer = await handle.createWriter();72 let buf = new ArrayBuffer(3);73 let intView = new Uint8Array(buf);74 intView[0] = 0x66;75 intView[1] = 0x6f;76 intView[2] = 0x6f;77 await writer.write(0, buf);78 assert_equals(await getFileContents(handle), 'foo');79 assert_equals(await getFileSize(handle), 3);80}, 'write() with a valid typed array buffer');81promise_test(async t => {82 const handle = await createEmptyFile(t, 'trunc_shrink');83 const writer = await handle.createWriter();84 await writer.write(0, new Blob(['1234567890']));85 await writer.truncate(5);86 assert_equals(await getFileContents(handle), '12345');87 assert_equals(await getFileSize(handle), 5);88}, 'truncate() to shrink a file');89promise_test(async t => {90 const handle = await createEmptyFile(t, 'trunc_grow');91 const writer = await handle.createWriter();92 await writer.write(0, new Blob(['abc']));93 await writer.truncate(5);94 assert_equals(await getFileContents(handle), 'abc\0\0');95 assert_equals(await getFileSize(handle), 5);...

Full Screen

Full Screen

make-node-commit.test.js

Source:make-node-commit.test.js Github

copy

Full Screen

1var assert = require('assert')2 , createNodeCommiter = require('../../lib/make-node-commit')3describe('release-management node file commiter', function () {4 it('should update package.json and npm-shrinkwrap', function (done) {5 function getFileContents (name, branch, cb) {6 cb(null, '{ "version": "v1.0.0" }')7 }8 function updateFiles (options, cb) {9 updateFilesCalled = true10 var expected =11 { files:12 [ { path: 'package.json'13 , content: '{\n "version": "2.0.0"\n}\n'14 }15 , { path: 'npm-shrinkwrap.json'16 , content: '{\n "version": "2.0.0"\n}\n'17 }18 ]19 , commitMessage: 'v2.0.0 ***no_ci***'20 , baseSha: 'abc123'21 , branch: 'release/test'22 }23 assert.deepEqual(options, expected)24 cb()25 }26 var updateFilesCalled = false27 , sl =28 { repoManager: function () {29 return { getFileContents: getFileContents, updateFiles: updateFiles }30 }31 }32 , makeNodeCommit = createNodeCommiter(sl)33 , pr =34 { branch: 'release/test'35 , headSha: 'abc123'36 }37 makeNodeCommit('v2.0.0', pr, function (error) {38 if (error) return done(error)39 assert.equal(updateFilesCalled, true, 'files were not updated')40 done()41 })42 })43 it('should update package.json even if npm-shrinkwrap does not exist', function (done) {44 function getFileContents (name, branch, cb) {45 if (name === 'npm-shrinkwrap.json') return cb({ code: 404 })46 cb(null, '{ "version": "v1.0.0" }')47 }48 function updateFiles (options, cb) {49 updateFilesCalled = true50 var expected =51 { files:52 [ { path: 'package.json'53 , content: '{\n "version": "2.0.0"\n}\n'54 }55 ]56 , commitMessage: 'v2.0.0 ***no_ci***'57 , baseSha: 'abc123'58 , branch: 'release/test'59 }60 assert.deepEqual(options, expected)61 cb()62 }63 var updateFilesCalled = false64 , sl =65 { repoManager: function () {66 return { getFileContents: getFileContents, updateFiles: updateFiles }67 }68 }69 , makeNodeCommit = createNodeCommiter(sl)70 , pr =71 { branch: 'release/test'72 , headSha: 'abc123'73 }74 makeNodeCommit('v2.0.0', pr, function (error) {75 if (error) return done(error)76 assert.equal(updateFilesCalled, true, 'files were not updated')77 done()78 })79 })80 it('should do nothing if both package.json does not exist', function (done) {81 function getFileContents (name, branch, cb) {82 return cb({ code: 404 })83 }84 function updateFiles (options, cb) {85 updateFilesCalled = true86 cb()87 }88 var updateFilesCalled = false89 , sl =90 { repoManager: function () {91 return { getFileContents: getFileContents, updateFiles: updateFiles }92 }93 }94 , makeNodeCommit = createNodeCommiter(sl)95 , pr =96 { branch: 'release/test'97 , headSha: 'abc123'98 }99 makeNodeCommit('v2.0.0', pr, function (error) {100 assert.equal(error.code, 404)101 assert.equal(updateFilesCalled, false, 'files were updated')102 done()103 })104 })...

Full Screen

Full Screen

ch1_syncfile.js

Source:ch1_syncfile.js Github

copy

Full Screen

...5 * courses, books, articles, and the like. Contact us if you are in doubt.6 * We make no guarantees that this code is fit for any purpose.7 * Visit http://www.pragmaticprogrammer.com/titles/smreactjs for more book information.8***/9function getFileContents(path) {10 if (!fs.existsSync(path)) {11 return '';12 }13 return fs.readFileSync(file);14}15console.log(getFileContents('/etc/passwd'));16function getFileContents(path, callback) {17 fs.exists(path, function(err, exists) {18 if (err || !exists) {19 return callback(new Error('There was a problem retrieving the file'));20 }21 fs.readFile(function(err, contents) {22 if (err) {23 return callback(new Error('There was a problem reading the file'));24 }25 callback(null, contents);26 });27 });28}29getFileContents('/etc/passwd', function(err, contents) {30 console.log(contents);31});32// Don't use try/catch with asynchronous code!33try {34 getFileContents('/etc/passwd', function(err, contents) {35 console.log(contents);36 });37} catch (e) {38 console.error('There was an error retrieving the contents!');39}40getFileContents('/etc/passwd', function(err, contents) {41 if (err) {42 return console.error('There was an error retrieving the file contents!');43 }44 console.log(contents);45});46getFileContents('/etc/passwd', function(err, contents) {47 if (err) {48 console.error('There was an error retrieving the contents!');49 }50 doSomethingWithFile(null, contents);51});52function getFileContents(url) {53 return asyncGetFile(url).then(asyncReadFile);54}55var contentPromise = getFileContents('http://example.com/big_file.txt');56contentPromise.then(57 function success(content) {58 console.log(content);59 }, function error(e) {60 console.error('There was an error retrieving the file', e);61 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.getLocations(function(err, data) {4 if (err) return console.error(err);5 console.log(data);6});7var wpt = require('webpagetest');8var wpt = new WebPageTest('www.webpagetest.org');9 if (err) return console.error(err);10 console.log(data);11});12var wpt = require('webpagetest');13var wpt = new WebPageTest('www.webpagetest.org');14wpt.getTestResults('150608_7T_1e1b', function(err, data) {15 if (err) return console.error(err);16 console.log(data);17});18var wpt = require('webpagetest');19var wpt = new WebPageTest('www.webpagetest.org');20wpt.getTestStatus('150608_7T_1e1b', function(err, data) {21 if (err) return console.error(err);22 console.log(data);23});24var wpt = require('webpagetest');25var wpt = new WebPageTest('www.webpagetest.org');26wpt.getTestRequests('150608_7T_1e1b', function(err, data) {27 if (err) return console.error(err);28 console.log(data);29});30var wpt = require('webpagetest');31var wpt = new WebPageTest('www.webpagetest.org');32wpt.getTestPageSpeed('150608_7T_1e1b', function(err, data) {33 if (err) return console.error(err);34 console.log(data);35});36var wpt = require('webpagetest');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.getLocations(function(err, data) {4 if (err) return console.error(err);5 console.log(data);6});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var options = {3};4wpt.getTestResults('101912_3K_5', function(err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});11wpt.getTestResults('101912_3K_5', true, function(err, data) {12 if (err) {13 console.log(err);14 } else {15 console.log(data);16 }17});18wpt.getTestResults('101912_3K_5', true, true, function(err, data) {19 if (err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25wpt.getTestResults('101912_3K_5', true, true, true, function(err, data) {26 if (err) {27 console.log(err);28 } else {29 console.log(data);30 }31});32wpt.getTestResults('101912_3K_5', true, true, true, true, function(err, data) {33 if (err) {34 console.log(err);35 } else {36 console.log(data);37 }38});39wpt.getTestResults('101912_3K_5', true, true, true, true, true, function(err, data) {40 if (err) {41 console.log(err);42 } else {43 console.log(data);44 }45});46wpt.getTestResults('101912_3K_5', true, true, true, true, true, true, function(err, data) {47 if (err) {48 console.log(err);49 } else {50 console.log(data);51 }52});53wpt.getTestResults('101912_3K_5', true, true, true, true, true, true, true, function(err, data) {54 if (err) {55 console.log(err);56 } else {57 console.log(data);58 }59});60wpt.getTestResults('101912_3K_5', true, true, true, true, true, true, true, true, function(err, data) {61 if (err) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3wptools.getPage('Barack Obama', function(err, page) {4 if (err) {5 console.log(err);6 } else {7 page.getFileContents('Barack Obama.jpg', function(err, data) {8 if (err) {9 console.log(err);10 } else {11 fs.writeFile('image.jpg', data, function(err) {12 if (err) {13 console.log(err);14 } else {15 console.log('File saved.');16 }17 });18 }19 });20 }21});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var path = require('path');4var options = {5};6var wiki = wptools.page('Albert Einstein', options);7wiki.get(function(err, resp) {8 if (err) {9 console.log(err);10 }11 else {12 console.log(resp);13 }14});15var wptools = require('wptools');16var fs = require('fs');17var path = require('path');18var options = {19};20var wiki = wptools.page('Albert Einstein', options);21wiki.get(function(err, resp) {22 if (err) {23 console.log(err);24 }25 else {26 console.log(resp);27 }28});29var wptools = require('wptools');30var fs = require('fs');31var path = require('path');32var options = {33};34var wiki = wptools.page('Albert Einstein', options);35wiki.get(function(err, resp) {36 if (err) {37 console.log(err);38 }39 else {40 console.log(resp);41 }42});43var wptools = require('wptools');44var fs = require('fs');45var path = require('path');46var options = {47};48var wiki = wptools.page('Albert Einstein', options);49wiki.get(function(err, resp) {50 if (err) {51 console.log(err);52 }53 else {54 console.log(resp);55 }56});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var path = require('path');4var file = fs.createWriteStream(path.join(__dirname, 'output.txt'));5var wiki = wptools.page('Albert Einstein').get();6wiki.then(function (result) {7 var content = result.content();8 file.write(content);9 file.end();10 console.log(content);11});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt');2wpt.getFileContents('test.txt', function(err, data){3 if(err){4 console.log('Error reading file');5 } else {6 console.log(data);7 }8});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful