How to use getFileContents method in Cypress

Best JavaScript code snippet using cypress

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

1describe('My First Test', function() {2 it('Gets, types and asserts', function() {3 cy.contains('type').click()4 cy.url().should('include', '/commands/actions')5 cy.get('.action-email')6 .type('

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2 it('Does not do much!', function() {3 cy.contains('type').click()4 cy.url().should('include', '/commands/actions')5 cy.get('.action-email')6 .type('

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2 it('Gets, types and asserts', function() {3 cy.contains('Login').click()4 cy.url().should('include', '/login')5 cy.get('input[name="username"]').type('test')6 cy.get('input[name="password"]').type('test')7 cy.get('button').click()8 cy.url().should('include', '/dashboard')9 cy.contains('Dashboard').click()10 cy.url().should('include', '/dashboard')11 cy.contains('Manage').click()12 cy.url().should('include', '/manage')13 cy.contains('Add').click()14 cy.url().should('include', '/add')15 cy.get('input[name="name"]').type('test')16 cy.get('input[name="email"]').type('

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('test', () => {2 it('test', () => {3 cy.readFile('cypress/fixtures/example.json').then((json) => {4 expect(json).to.have.property('name')5 expect(json.name).to.equal('Using fixtures to represent data')6 })7 })8})

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2 it('Does not do much!', function() {3 cy.readFile('test.txt').then((text) => {4 console.log(text);5 })6 })7})

Full Screen

Using AI Code Generation

copy

Full Screen

1describe("test file contents", () => {2 it("should read the file contents", () => {3 cy.fixture("test.txt").then((fileContent) => {4 expect(fileContent).to.equal("Hello World");5 });6 });7});

Full Screen

Cypress Tutorial

Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.

Chapters:

  1. What is Cypress? -
  2. Why Cypress? - Learn why Cypress might be a good choice for testing your web applications.
  3. Features of Cypress Testing - Learn about features that make Cypress a powerful and flexible tool for testing web applications.
  4. Cypress Drawbacks - Although Cypress has many strengths, it has a few limitations that you should be aware of.
  5. Cypress Architecture - Learn more about Cypress architecture and how it is designed to be run directly in the browser, i.e., it does not have any additional servers.
  6. Browsers Supported by Cypress - Cypress is built on top of the Electron browser, supporting all modern web browsers. Learn browsers that support Cypress.
  7. Selenium vs Cypress: A Detailed Comparison - Compare and explore some key differences in terms of their design and features.
  8. Cypress Learning: Best Practices - Take a deep dive into some of the best practices you should use to avoid anti-patterns in your automation tests.
  9. How To Run Cypress Tests on LambdaTest? - Set up a LambdaTest account, and now you are all set to learn how to run Cypress tests.

Certification

You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.

YouTube

Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.

Run Cypress 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