Best JavaScript code snippet using stryker-parent
convert.js
Source:convert.js
1'use strict';2var Wav = require( '..' );3var fs = require( 'fs' );4var path = require( 'path' );5describe( 'Convert', function () {6 describe( '#file()', function () {7 describe( 'file-does-not-exist.wav', function () {8 var filename = 'file-that-does-not-exist.wav';9 var inputFilename = path.resolve( path.join( __dirname, 'audio', filename ) );10 var outputFilename = inputFilename + '.wav';11 before( 'ensure input file does not exist', function ( done ) {12 fs.exists( inputFilename, function ( exists ) {13 if ( exists ) {14 return done( new Error( 'Input file exists.' ) );15 }16 done();17 } );18 } );19 before( 'ensure output file does not exist', function ( done ) {20 fs.exists( outputFilename, function ( exists ) {21 if ( !exists ) {22 return done();23 }24 // Remove preexisting output file25 fs.unlink( outputFilename, function ( err ) {26 if ( err ) {27 return done( err );28 }29 done();30 } );31 } );32 } );33 after( 'remove output file', function ( done ) {34 fs.unlink( outputFilename, function ( err ) {35 if ( err ) {36 return done( err );37 }38 done();39 } );40 } );41 it( 'should throw an error', function ( done ) {42 Wav.convert.file( inputFilename, outputFilename, {}, function ( err ) {43 if ( !err ) {44 return done( 'Did not throw an error.' );45 }46 done();47 } );48 } );49 it( 'should not create the output file', function ( done ) {50 fs.exists( outputFilename, function ( exists ) {51 if ( exists ) {52 return done( new Error( 'Created output file.' ) );53 }54 done();55 } );56 } );57 it( 'should not overwrite the output file', function ( done ) {58 // Create empty file for reference59 fs.open( outputFilename, 'w', function ( err, fd ) {60 if ( err ) {61 return done( err );62 }63 fs.close( fd, function ( err ) {64 if ( err ) {65 return done( err );66 }67 fs.stat( outputFilename, function ( err, stats ) {68 if ( err ) {69 return done( err );70 }71 var emptySize = stats.size;72 Wav.convert.file( inputFilename, outputFilename, {}, function ( err ) {73 if ( err ) {74 return done( err );75 }76 fs.stat( outputFilename, function ( err, stats ) {77 if ( err ) {78 return done( err );79 }80 if ( stats.size !== emptySize ) {81 return done( new Error( 'Overwrite output file.' ) );82 }83 done();84 } );85 } );86 } );87 } );88 } );89 } );90 } );91 describe( 'file.js', function () {92 var filename = 'convert.js';93 var inputFilename = path.resolve( path.join( __dirname, filename ) );94 var outputFilename = inputFilename + '.wav';95 before( 'ensure input file exists', function ( done ) {96 fs.exists( inputFilename, function ( exists ) {97 if ( !exists ) {98 return done( new Error( 'Input file does not exist.' ) );99 }100 done();101 } );102 } );103 before( 'ensure output file does not exist', function ( done ) {104 fs.exists( outputFilename, function ( exists ) {105 if ( !exists ) {106 return done();107 }108 // Remove preexisting output file109 fs.unlink( outputFilename, function ( err ) {110 if ( err ) {111 return done( err );112 }113 done();114 } );115 } );116 } );117 after( 'remove output file', function ( done ) {118 fs.unlink( outputFilename, function ( err ) {119 if ( err ) {120 return done( err );121 }122 done();123 } );124 } );125 it( 'should throw an error', function ( done ) {126 Wav.convert.file( inputFilename, outputFilename, {}, function ( err ) {127 if ( !err ) {128 return done( 'Did not throw an error.' );129 }130 done();131 } );132 } );133 it( 'should not create the output file', function ( done ) {134 fs.exists( outputFilename, function ( exists ) {135 if ( exists ) {136 return done( new Error( 'Created output file.' ) );137 }138 done();139 } );140 } );141 it( 'should not overwrite the output file', function ( done ) {142 // Create empty file for reference143 fs.open( outputFilename, 'w', function ( err, fd ) {144 if ( err ) {145 return done( err );146 }147 fs.close( fd, function ( err ) {148 if ( err ) {149 return done( err );150 }151 fs.stat( outputFilename, function ( err, stats ) {152 if ( err ) {153 return done( err );154 }155 var emptySize = stats.size;156 Wav.convert.file( inputFilename, outputFilename, {}, function ( err ) {157 if ( err ) {158 return done( err );159 }160 fs.stat( outputFilename, function ( err, stats ) {161 if ( err ) {162 return done( err );163 }164 if ( stats.size !== emptySize ) {165 return done( new Error( 'Overwrite output file.' ) );166 }167 done();168 } );169 } );170 } );171 } );172 } );173 } );174 } );175 describe( 'T2a6uvl5c4m7ozqnt37wejkt32a.wav', function () {176 var filename = 'T2a6uvl5c4m7ozqnt37wejkt32a.wav';177 var inputFilename = path.resolve( path.join( __dirname, 'audio', filename ) );178 var outputFilename = inputFilename + '.wav';179 before( 'ensure input file exists', function ( done ) {180 fs.exists( inputFilename, function ( exists ) {181 if ( !exists ) {182 return done( new Error( 'Input file does not exist.' ) );183 }184 done();185 } );186 } );187 before( 'ensure output file does not exist', function ( done ) {188 fs.exists( outputFilename, function ( exists ) {189 if ( !exists ) {190 return done();191 }192 // Remove preexisting output file193 fs.unlink( outputFilename, function ( err ) {194 if ( err ) {195 return done( err );196 }197 done();198 } );199 } );200 } );201 after( 'remove output file', function ( done ) {202 fs.unlink( outputFilename, function ( err ) {203 if ( err ) {204 return done( err );205 }206 done();207 } );208 } );209 it( 'should not throw an error', function ( done ) {210 Wav.convert.file( inputFilename, outputFilename, {}, function ( err ) {211 if ( err ) {212 return done( err );213 }214 done();215 } );216 } );217 it( 'should create the output file', function ( done ) {218 fs.exists( outputFilename, function ( exists ) {219 if ( !exists ) {220 return done( new Error( 'Did not create output file.' ) );221 }222 done();223 } );224 } );225 it( 'should overwrite the output file', function ( done ) {226 // Create empty file for reference227 fs.open( outputFilename, 'w', function ( err, fd ) {228 if ( err ) {229 return done( err );230 }231 fs.close( fd, function ( err ) {232 if ( err ) {233 return done( err );234 }235 fs.stat( outputFilename, function ( err, stats ) {236 if ( err ) {237 return done( err );238 }239 var emptySize = stats.size;240 Wav.convert.file( inputFilename, outputFilename, {}, function ( err ) {241 if ( err ) {242 return done( err );243 }244 fs.stat( outputFilename, function ( err, stats ) {245 if ( err ) {246 return done( err );247 }248 if ( stats.size === emptySize ) {249 return done( new Error( 'Did not overwrite output file.' ) );250 }251 done();252 } );253 } );254 } );255 } );256 } );257 } );258 it( 'should create a valid output wav file', function ( done ) {259 // A valid wav file is one that we can read without error260 Wav.file.read( outputFilename, {}, function ( err ) {261 if ( err ) {262 return done( err );263 }264 done();265 } );266 } );267 it( 'should create a correct output wav file', function ( done ) {268 var expected = 'AC7A05D0EE017731F5BDA0CAA45A8A553AE3A8CA828694932C9EB2A49BD4ADC3';269 // A correct conversion occurs if we calculate the expected hash270 Wav.file.hash( outputFilename, function ( err, hash ) {271 if ( err ) {272 return done( err );273 }274 // Ensure hash is correct275 if ( hash !== expected ) {276 return done( new Error( 'Converted incorrectly.' ) );277 }278 done();279 } );280 } );281 } );282 describe( 'T2aaoxo63yfkykfmdr7yehuzqza.wav', function () {283 var filename = 'T2aaoxo63yfkykfmdr7yehuzqza.wav';284 var inputFilename = path.resolve( path.join( __dirname, 'audio', filename ) );285 var outputFilename = inputFilename + '.wav';286 before( 'ensure input file exists', function ( done ) {287 fs.exists( inputFilename, function ( exists ) {288 if ( !exists ) {289 return done( new Error( 'Input file does not exist.' ) );290 }291 done();292 } );293 } );294 before( 'ensure output file does not exist', function ( done ) {295 fs.exists( outputFilename, function ( exists ) {296 if ( !exists ) {297 return done();298 }299 // Remove preexisting output file300 fs.unlink( outputFilename, function ( err ) {301 if ( err ) {302 return done( err );303 }304 done();305 } );306 } );307 } );308 after( 'remove output file', function ( done ) {309 fs.unlink( outputFilename, function ( err ) {310 if ( err ) {311 return done( err );312 }313 done();314 } );315 } );316 it( 'should not throw an error', function ( done ) {317 Wav.convert.file( inputFilename, outputFilename, {}, function ( err ) {318 if ( err ) {319 return done( err );320 }321 done();322 } );323 } );324 it( 'should create the output file', function ( done ) {325 fs.exists( outputFilename, function ( exists ) {326 if ( !exists ) {327 return done( new Error( 'Did not create output file.' ) );328 }329 done();330 } );331 } );332 it( 'should overwrite the output file', function ( done ) {333 // Create empty file for reference334 fs.open( outputFilename, 'w', function ( err, fd ) {335 if ( err ) {336 return done( err );337 }338 fs.close( fd, function ( err ) {339 if ( err ) {340 return done( err );341 }342 fs.stat( outputFilename, function ( err, stats ) {343 if ( err ) {344 return done( err );345 }346 var emptySize = stats.size;347 Wav.convert.file( inputFilename, outputFilename, {}, function ( err ) {348 if ( err ) {349 return done( err );350 }351 fs.stat( outputFilename, function ( err, stats ) {352 if ( err ) {353 return done( err );354 }355 if ( stats.size === emptySize ) {356 return done( new Error( 'Did not overwrite output file.' ) );357 }358 done();359 } );360 } );361 } );362 } );363 } );364 } );365 it( 'should create a valid output wav file', function ( done ) {366 // A valid wav file is one that we can read without error367 Wav.file.read( outputFilename, {}, function ( err ) {368 if ( err ) {369 return done( err );370 }371 done();372 } );373 } );374 it( 'should create a correct output wav file', function ( done ) {375 var expected = '118DA6568EE44D31A7335185563866A447C6B3CC76FFAB181CC00E4EF4BD5AC0';376 // A correct conversion occurs if we calculate the expected hash377 Wav.file.hash( outputFilename, function ( err, hash ) {378 if ( err ) {379 return done( err );380 }381 // Ensure hash is correct382 if ( hash !== expected ) {383 return done( new Error( 'Converted incorrectly.' ) );384 }385 done();386 } );387 } );388 } );389 describe( 'T2aaoxo63yfkykfmdr7yehuzqza.mp3', function () {390 var filename = 'T2aaoxo63yfkykfmdr7yehuzqza.mp3';391 var inputFilename = path.resolve( path.join( __dirname, 'audio', filename ) );392 var outputFilename = inputFilename + '.wav';393 describe( 'options = {}', function () {394 before( 'ensure input file exists', function ( done ) {395 fs.exists( inputFilename, function ( exists ) {396 if ( !exists ) {397 return done( new Error( 'Input file does not exist.' ) );398 }399 done();400 } );401 } );402 before( 'ensure output file does not exist', function ( done ) {403 fs.exists( outputFilename, function ( exists ) {404 if ( !exists ) {405 return done();406 }407 // Remove preexisting output file408 fs.unlink( outputFilename, function ( err ) {409 if ( err ) {410 return done( err );411 }412 done();413 } );414 } );415 } );416 after( 'remove output file', function ( done ) {417 fs.unlink( outputFilename, function ( err ) {418 if ( err ) {419 return done( err );420 }421 done();422 } );423 } );424 it( 'should not throw an error', function ( done ) {425 Wav.convert.file( inputFilename, outputFilename, {}, function ( err ) {426 if ( err ) {427 return done( err );428 }429 done();430 } );431 } );432 it( 'should create the output file', function ( done ) {433 fs.exists( outputFilename, function ( exists ) {434 if ( !exists ) {435 return done( new Error( 'Did not create output file.' ) );436 }437 done();438 } );439 } );440 it( 'should overwrite the output file', function ( done ) {441 // Create empty file for reference442 fs.open( outputFilename, 'w', function ( err, fd ) {443 if ( err ) {444 return done( err );445 }446 fs.close( fd, function ( err ) {447 if ( err ) {448 return done( err );449 }450 fs.stat( outputFilename, function ( err, stats ) {451 if ( err ) {452 return done( err );453 }454 var emptySize = stats.size;455 Wav.convert.file( inputFilename, outputFilename, {}, function ( err ) {456 if ( err ) {457 return done( err );458 }459 fs.stat( outputFilename, function ( err, stats ) {460 if ( err ) {461 return done( err );462 }463 if ( stats.size === emptySize ) {464 return done( new Error( 'Did not overwrite output file.' ) );465 }466 done();467 } );468 } );469 } );470 } );471 } );472 } );473 it( 'should create a valid output wav file', function ( done ) {474 // A valid wav file is one that we can read without error475 Wav.file.read( outputFilename, {}, function ( err, wav_file ) {476 if ( err ) {477 return done( err );478 }479 // Must have only one channel480 if ( wav_file.numChannels !== 2 ) {481 return done( new Error( 'Does not exactly have two channels.' ) );482 }483 done();484 } );485 } );486 it( 'should create a correct output wav file', function ( done ) {487 var expected = 'AA4026AA1A6A2D59AC01427F4A2D3B239CDD955BD309678C4EF1CC8490E968C1';488 // A correct conversion occurs if we calculate the expected hash489 Wav.file.hash( outputFilename, function ( err, hash ) {490 if ( err ) {491 return done( err );492 }493 // Ensure hash is correct494 if ( hash !== expected ) {495 return done( new Error( 'Converted incorrectly.' ) );496 }497 done();498 } );499 } );500 } );501 describe( 'options = { channels: [ 0, 1 ] }', function () {502 before( 'ensure input file exists', function ( done ) {503 fs.exists( inputFilename, function ( exists ) {504 if ( !exists ) {505 return done( new Error( 'Input file does not exist.' ) );506 }507 done();508 } );509 } );510 before( 'ensure output file does not exist', function ( done ) {511 fs.exists( outputFilename, function ( exists ) {512 if ( !exists ) {513 return done();514 }515 // Remove preexisting output file516 fs.unlink( outputFilename, function ( err ) {517 if ( err ) {518 return done( err );519 }520 done();521 } );522 } );523 } );524 after( 'remove output file', function ( done ) {525 fs.unlink( outputFilename, function ( err ) {526 if ( err ) {527 return done( err );528 }529 done();530 } );531 } );532 it( 'should not throw an error', function ( done ) {533 Wav.convert.file( inputFilename, outputFilename, { channels: [ 0, 1 ] }, function ( err ) {534 if ( err ) {535 return done( err );536 }537 done();538 } );539 } );540 it( 'should create the output file', function ( done ) {541 fs.exists( outputFilename, function ( exists ) {542 if ( !exists ) {543 return done( new Error( 'Did not create output file.' ) );544 }545 done();546 } );547 } );548 it( 'should overwrite the output file', function ( done ) {549 // Create empty file for reference550 fs.open( outputFilename, 'w', function ( err, fd ) {551 if ( err ) {552 return done( err );553 }554 fs.close( fd, function ( err ) {555 if ( err ) {556 return done( err );557 }558 fs.stat( outputFilename, function ( err, stats ) {559 if ( err ) {560 return done( err );561 }562 var emptySize = stats.size;563 Wav.convert.file( inputFilename, outputFilename, { channels: [ 0, 1 ] }, function ( err ) {564 if ( err ) {565 return done( err );566 }567 fs.stat( outputFilename, function ( err, stats ) {568 if ( err ) {569 return done( err );570 }571 if ( stats.size === emptySize ) {572 return done( new Error( 'Did not overwrite output file.' ) );573 }574 done();575 } );576 } );577 } );578 } );579 } );580 } );581 it( 'should create a valid output wav file', function ( done ) {582 // A valid wav file is one that we can read without error583 Wav.file.read( outputFilename, {}, function ( err, wav_file ) {584 if ( err ) {585 return done( err );586 }587 // Must have only one channel588 if ( wav_file.numChannels !== 2 ) {589 return done( new Error( 'Does not exactly have two channels.' ) );590 }591 done();592 } );593 } );594 it( 'should create a correct output wav file', function ( done ) {595 var expected = 'AA4026AA1A6A2D59AC01427F4A2D3B239CDD955BD309678C4EF1CC8490E968C1';596 // A correct conversion occurs if we calculate the expected hash597 Wav.file.hash( outputFilename, function ( err, hash ) {598 if ( err ) {599 return done( err );600 }601 // Ensure hash is correct602 if ( hash !== expected ) {603 return done( new Error( 'Converted incorrectly.' ) );604 }605 done();606 } );607 } );608 } );609 describe( 'options = { channels: [ 0 ] }', function () {610 before( 'ensure input file exists', function ( done ) {611 fs.exists( inputFilename, function ( exists ) {612 if ( !exists ) {613 return done( new Error( 'Input file does not exist.' ) );614 }615 done();616 } );617 } );618 before( 'ensure output file does not exist', function ( done ) {619 fs.exists( outputFilename, function ( exists ) {620 if ( !exists ) {621 return done();622 }623 // Remove preexisting output file624 fs.unlink( outputFilename, function ( err ) {625 if ( err ) {626 return done( err );627 }628 done();629 } );630 } );631 } );632 after( 'remove output file', function ( done ) {633 fs.unlink( outputFilename, function ( err ) {634 if ( err ) {635 return done( err );636 }637 done();638 } );639 } );640 it( 'should not throw an error', function ( done ) {641 Wav.convert.file( inputFilename, outputFilename, { channels: [ 0 ] }, function ( err ) {642 if ( err ) {643 return done( err );644 }645 done();646 } );647 } );648 it( 'should create the output file', function ( done ) {649 fs.exists( outputFilename, function ( exists ) {650 if ( !exists ) {651 return done( new Error( 'Did not create output file.' ) );652 }653 done();654 } );655 } );656 it( 'should overwrite the output file', function ( done ) {657 // Create empty file for reference658 fs.open( outputFilename, 'w', function ( err, fd ) {659 if ( err ) {660 return done( err );661 }662 fs.close( fd, function ( err ) {663 if ( err ) {664 return done( err );665 }666 fs.stat( outputFilename, function ( err, stats ) {667 if ( err ) {668 return done( err );669 }670 var emptySize = stats.size;671 Wav.convert.file( inputFilename, outputFilename, { channels: [ 0 ] }, function ( err ) {672 if ( err ) {673 return done( err );674 }675 fs.stat( outputFilename, function ( err, stats ) {676 if ( err ) {677 return done( err );678 }679 if ( stats.size === emptySize ) {680 return done( new Error( 'Did not overwrite output file.' ) );681 }682 done();683 } );684 } );685 } );686 } );687 } );688 } );689 it( 'should create a valid output wav file', function ( done ) {690 // A valid wav file is one that we can read without error691 Wav.file.read( outputFilename, {}, function ( err, wav_file ) {692 if ( err ) {693 return done( err );694 }695 // Must have only one channel696 if ( wav_file.numChannels !== 1 ) {697 return done( new Error( 'Does not exactly have one channel.' ) );698 }699 done();700 } );701 } );702 it( 'should create a correct output wav file', function ( done ) {703 var expected = '8ABFCB1897577AE4AF1D81B65894924ACDA1E7C520438BFAEC85AA7E6FB21794';704 // A correct conversion occurs if we calculate the expected hash705 Wav.file.hash( outputFilename, function ( err, hash ) {706 if ( err ) {707 return done( err );708 }709 // Ensure hash is correct710 if ( hash !== expected ) {711 return done( new Error( 'Converted incorrectly.' ) );712 }713 done();714 } );715 } );716 } );717 describe( 'options = { channels: [ 1 ] }', function () {718 before( 'ensure input file exists', function ( done ) {719 fs.exists( inputFilename, function ( exists ) {720 if ( !exists ) {721 return done( new Error( 'Input file does not exist.' ) );722 }723 done();724 } );725 } );726 before( 'ensure output file does not exist', function ( done ) {727 fs.exists( outputFilename, function ( exists ) {728 if ( !exists ) {729 return done();730 }731 // Remove preexisting output file732 fs.unlink( outputFilename, function ( err ) {733 if ( err ) {734 return done( err );735 }736 done();737 } );738 } );739 } );740 after( 'remove output file', function ( done ) {741 fs.unlink( outputFilename, function ( err ) {742 if ( err ) {743 return done( err );744 }745 done();746 } );747 } );748 it( 'should not throw an error', function ( done ) {749 Wav.convert.file( inputFilename, outputFilename, { channels: [ 1 ] }, function ( err ) {750 if ( err ) {751 return done( err );752 }753 done();754 } );755 } );756 it( 'should create the output file', function ( done ) {757 fs.exists( outputFilename, function ( exists ) {758 if ( !exists ) {759 return done( new Error( 'Did not create output file.' ) );760 }761 done();762 } );763 } );764 it( 'should overwrite the output file', function ( done ) {765 // Create empty file for reference766 fs.open( outputFilename, 'w', function ( err, fd ) {767 if ( err ) {768 return done( err );769 }770 fs.close( fd, function ( err ) {771 if ( err ) {772 return done( err );773 }774 fs.stat( outputFilename, function ( err, stats ) {775 if ( err ) {776 return done( err );777 }778 var emptySize = stats.size;779 Wav.convert.file( inputFilename, outputFilename, { channels: [ 1 ] }, function ( err ) {780 if ( err ) {781 return done( err );782 }783 fs.stat( outputFilename, function ( err, stats ) {784 if ( err ) {785 return done( err );786 }787 if ( stats.size === emptySize ) {788 return done( new Error( 'Did not overwrite output file.' ) );789 }790 done();791 } );792 } );793 } );794 } );795 } );796 } );797 it( 'should create a valid output wav file', function ( done ) {798 // A valid wav file is one that we can read without error799 Wav.file.read( outputFilename, {}, function ( err, wav_file ) {800 if ( err ) {801 return done( err );802 }803 // Must have only one channel804 if ( wav_file.numChannels !== 1 ) {805 return done( new Error( 'Does not exactly have one channel.' ) );806 }807 done();808 } );809 } );810 it( 'should create a correct output wav file', function ( done ) {811 var expected = '6B0037639952CCCCDFB5E7993AF30275F5DA934FD4F54A22E56961721473D9A5';812 // A correct conversion occurs if we calculate the expected hash813 Wav.file.hash( outputFilename, function ( err, hash ) {814 if ( err ) {815 return done( err );816 }817 // Ensure hash is correct818 if ( hash !== expected ) {819 return done( new Error( 'Converted incorrectly.' ) );820 }821 done();822 } );823 } );824 } );825 describe( 'options = { mix: true }', function () {826 before( 'ensure input file exists', function ( done ) {827 fs.exists( inputFilename, function ( exists ) {828 if ( !exists ) {829 return done( new Error( 'Input file does not exist.' ) );830 }831 done();832 } );833 } );834 before( 'ensure output file does not exist', function ( done ) {835 fs.exists( outputFilename, function ( exists ) {836 if ( !exists ) {837 return done();838 }839 // Remove preexisting output file840 fs.unlink( outputFilename, function ( err ) {841 if ( err ) {842 return done( err );843 }844 done();845 } );846 } );847 } );848 after( 'remove output file', function ( done ) {849 fs.unlink( outputFilename, function ( err ) {850 if ( err ) {851 return done( err );852 }853 done();854 } );855 } );856 it( 'should not throw an error', function ( done ) {857 Wav.convert.file( inputFilename, outputFilename, { mix: true }, function ( err ) {858 if ( err ) {859 return done( err );860 }861 done();862 } );863 } );864 it( 'should create the output file', function ( done ) {865 fs.exists( outputFilename, function ( exists ) {866 if ( !exists ) {867 return done( new Error( 'Did not create output file.' ) );868 }869 done();870 } );871 } );872 it( 'should overwrite the output file', function ( done ) {873 // Create empty file for reference874 fs.open( outputFilename, 'w', function ( err, fd ) {875 if ( err ) {876 return done( err );877 }878 fs.close( fd, function ( err ) {879 if ( err ) {880 return done( err );881 }882 fs.stat( outputFilename, function ( err, stats ) {883 if ( err ) {884 return done( err );885 }886 var emptySize = stats.size;887 Wav.convert.file( inputFilename, outputFilename, { mix: true }, function ( err ) {888 if ( err ) {889 return done( err );890 }891 fs.stat( outputFilename, function ( err, stats ) {892 if ( err ) {893 return done( err );894 }895 if ( stats.size === emptySize ) {896 return done( new Error( 'Did not overwrite output file.' ) );897 }898 done();899 } );900 } );901 } );902 } );903 } );904 } );905 it( 'should create a valid output wav file', function ( done ) {906 // A valid wav file is one that we can read without error907 Wav.file.read( outputFilename, {}, function ( err ) {908 if ( err ) {909 return done( err );910 }911 done();912 } );913 } );914 it( 'should create a correct output wav file', function ( done ) {915 var expected = '118DA6568EE44D31A7335185563866A447C6B3CC76FFAB181CC00E4EF4BD5AC0';916 // A correct conversion occurs if we calculate the expected hash917 Wav.file.hash( outputFilename, function ( err, hash ) {918 if ( err ) {919 return done( err );920 }921 // Ensure hash is correct922 if ( hash !== expected ) {923 return done( new Error( 'Converted incorrectly.' ) );924 }925 done();926 } );927 } );928 } );929 describe( 'options = { channels: [ 0, 1 ], mix: true }', function () {930 before( 'ensure input file exists', function ( done ) {931 fs.exists( inputFilename, function ( exists ) {932 if ( !exists ) {933 return done( new Error( 'Input file does not exist.' ) );934 }935 done();936 } );937 } );938 before( 'ensure output file does not exist', function ( done ) {939 fs.exists( outputFilename, function ( exists ) {940 if ( !exists ) {941 return done();942 }943 // Remove preexisting output file944 fs.unlink( outputFilename, function ( err ) {945 if ( err ) {946 return done( err );947 }948 done();949 } );950 } );951 } );952 after( 'remove output file', function ( done ) {953 fs.unlink( outputFilename, function ( err ) {954 if ( err ) {955 return done( err );956 }957 done();958 } );959 } );960 it( 'should not throw an error', function ( done ) {961 Wav.convert.file( inputFilename, outputFilename, { channels: [ 0, 1 ], mix: true }, function ( err ) {962 if ( err ) {963 return done( err );964 }965 done();966 } );967 } );968 it( 'should create the output file', function ( done ) {969 fs.exists( outputFilename, function ( exists ) {970 if ( !exists ) {971 return done( new Error( 'Did not create output file.' ) );972 }973 done();974 } );975 } );976 it( 'should overwrite the output file', function ( done ) {977 // Create empty file for reference978 fs.open( outputFilename, 'w', function ( err, fd ) {979 if ( err ) {980 return done( err );981 }982 fs.close( fd, function ( err ) {983 if ( err ) {984 return done( err );985 }986 fs.stat( outputFilename, function ( err, stats ) {987 if ( err ) {988 return done( err );989 }990 var emptySize = stats.size;991 Wav.convert.file( inputFilename, outputFilename, { channels: [ 0, 1 ], mix: true }, function ( err ) {992 if ( err ) {993 return done( err );994 }995 fs.stat( outputFilename, function ( err, stats ) {996 if ( err ) {997 return done( err );998 }999 if ( stats.size === emptySize ) {1000 return done( new Error( 'Did not overwrite output file.' ) );1001 }1002 done();1003 } );1004 } );1005 } );1006 } );1007 } );1008 } );1009 it( 'should create a valid output wav file', function ( done ) {1010 // A valid wav file is one that we can read without error1011 Wav.file.read( outputFilename, {}, function ( err ) {1012 if ( err ) {1013 return done( err );1014 }1015 done();1016 } );1017 } );1018 it( 'should create a correct output wav file', function ( done ) {1019 var expected = '118DA6568EE44D31A7335185563866A447C6B3CC76FFAB181CC00E4EF4BD5AC0';1020 // A correct conversion occurs if we calculate the expected hash1021 Wav.file.hash( outputFilename, function ( err, hash ) {1022 if ( err ) {1023 return done( err );1024 }1025 // Ensure hash is correct1026 if ( hash !== expected ) {1027 return done( new Error( 'Converted incorrectly.' ) );1028 }1029 done();1030 } );1031 } );1032 } );1033 } );1034 } );1035 describe.skip( '#dir()', function () {1036 it( 'should create correct number of output files' );1037 } );...
acquire.ts
Source:acquire.ts
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3import { strict } from 'assert';4import { pipeline as origPipeline } from 'stream';5import { promisify } from 'util';6import { i } from '../i18n';7import { Session } from '../session';8import { Credentials } from '../util/credentials';9import { ExtendedEmitter } from '../util/events';10import { RemoteFileUnavailable } from '../util/exceptions';11import { Algorithm, Hash } from '../util/hash';12import { Uri } from '../util/uri';13import { get, getStream, RemoteFile, resolveRedirect } from './https';14import { Progress, ProgressTrackingStream } from './streams';15const pipeline = promisify(origPipeline);16const size32K = 1 << 15;17const size64K = 1 << 16;18export interface AcquireOptions extends Hash {19 /** force a redownload even if it's in cache */20 force?: boolean;21 credentials?: Credentials;22 events?: Partial<AcquireEvents>23}24export interface AcquireEvents extends Progress {25 download(file: string, percent: number): void;26 verifying(file: string, percent: number): void;27 complete(): void;28}29export async function acquireArtifactFile(session: Session, uris: Array<Uri>, outputFilename: string, options?: AcquireOptions) {30 await session.cache.createDirectory();31 const outputFile = session.cache.join(outputFilename);32 session.channels.debug(`Acquire file '${outputFilename}' from [${uris.map(each => each.toString()).join(',')}]`);33 if (options?.algorithm && options?.value) {34 session.channels.debug(`We have a hash: ${options.algorithm}/${options.value}`);35 // if we have hash data, check to see if the output file is good.36 if (await outputFile.isFile()) {37 session.channels.debug(`There is an output file already, verifying: ${outputFile.fsPath}`);38 if (await outputFile.hashValid(options)) {39 session.channels.debug(`Cached file matched hash: ${outputFile.fsPath}`);40 return outputFile;41 }42 }43 }44 // is the file present on a local filesystem?45 for (const uri of uris) {46 if (uri.isLocal) {47 // we have a local file48 if (options?.algorithm && options?.value) {49 // we have a hash.50 // is it valid?51 if (await uri.hashValid(options)) {52 session.channels.debug(`Local file matched hash: ${uri.fsPath}`);53 return uri;54 }55 } else if (await uri.exists()) {56 // we don't have a hash, but the file is local, and it exists.57 // we have to return it58 session.channels.debug(`Using local file (no hash, unable to verify): ${uri.fsPath}`);59 return uri;60 }61 // do we have a filename62 }63 }64 // we don't have a local file65 // https is all that we know at the moment.66 const webUris = uris.where(each => each.isHttps);67 if (webUris.length === 0) {68 // wait, no web uris?69 throw new RemoteFileUnavailable(uris);70 }71 return https(session, webUris, outputFilename, options);72}73/** */74async function https(session: Session, uris: Array<Uri>, outputFilename: string, options?: AcquireOptions) {75 const ee = new ExtendedEmitter<AcquireEvents>();76 ee.subscribe(options?.events);77 session.channels.debug(`Attempting to download file '${outputFilename}' from [${uris.map(each => each.toString()).join(',')}]`);78 let resumeAtOffset = 0;79 await session.cache.createDirectory();80 const outputFile = session.cache.join(outputFilename);81 if (options?.force) {82 session.channels.debug(`Acquire '${outputFilename}': force specified, forcing download`);83 // is force specified; delete the current file84 await outputFile.delete();85 }86 // start this peeking at the target uris.87 session.channels.debug(`Acquire '${outputFilename}': checking remote connections`);88 const locations = new RemoteFile(uris, { credentials: options?.credentials });89 let url: Uri | undefined;90 // is there a file in the cache91 if (await outputFile.exists()) {92 session.channels.debug(`Acquire '${outputFilename}': local file exists`);93 if (options?.algorithm) {94 // does it match a hash that we have?95 if (await outputFile.hashValid(options)) {96 session.channels.debug(`Acquire '${outputFilename}': local file hash matches metdata`);97 // yes it does. let's just return done.98 return outputFile;99 }100 }101 // it doesn't match a known hash.102 const contentLength = await locations.contentLength;103 session.channels.debug(`Acquire '${outputFilename}': remote connection info is back`);104 const onDiskSize = await outputFile.size();105 if (!await locations.availableLocation) {106 if (locations.failures.all(each => each.code === 404)) {107 let msg = i`Unable to download file`;108 if (options?.credentials) {109 msg += (i` - It could be that your authentication credentials are not correct`);110 }111 session.channels.error(msg);112 throw new RemoteFileUnavailable(uris);113 }114 }115 // first, make sure that there is a remote that is accessible.116 strict.ok(!!await locations.availableLocation, `Requested file ${outputFilename} has no accessible locations ${uris.map(each => each.toString()).join(',')}`);117 url = await locations.resumableLocation;118 // ok, does it support resume?119 if (url) {120 // yes, let's check what the size is expected to be.121 if (!options?.algorithm) {122 if (contentLength === onDiskSize) {123 session.channels.debug(`Acquire '${outputFilename}': on disk file matches length of remote file`);124 const algorithm = <Algorithm>(await locations.algorithm);125 const value = await locations.hash;126 session.channels.debug(`Acquire '${outputFilename}': remote alg/hash: '${algorithm}'/'${value}`);127 if (algorithm && value && outputFile.hashValid({ algorithm, value, ...options })) {128 session.channels.debug(`Acquire '${outputFilename}': on disk file hash matches the server hash`);129 // so *we* don't have the hash, but ... if the server has a hash, we could see if what we have is what they have?130 // it does match what the server has.131 // I call this an win.132 return outputFile;133 }134 // we don't have a hash, or what we have doesn't match.135 // maybe we will get a match below (or resume)136 }137 }138 if (onDiskSize > size64K) {139 // it's bigger than 64k. Good. otherwise, we're just wasting time.140 // so, how big is the remote141 if (contentLength >= onDiskSize) {142 session.channels.debug(`Acquire '${outputFilename}': local file length is less than or equal to remote file length`);143 // looks like there could be more remotely than we have.144 // lets compare the first 32k and the last 32k of what we have145 // against what they have and see if they match.146 const top = (await get(url, { start: 0, end: size32K - 1, credentials: options?.credentials })).rawBody;147 const bottom = (await get(url, { start: onDiskSize - size32K, end: onDiskSize - 1, credentials: options?.credentials })).rawBody;148 const onDiskTop = await outputFile.readBlock(0, size32K - 1);149 const onDiskBottom = await outputFile.readBlock(onDiskSize - size32K, onDiskSize - 1);150 if (top.compare(onDiskTop) === 0 && bottom.compare(onDiskBottom) === 0) {151 session.channels.debug(`Acquire '${outputFilename}': first/last blocks are equal`);152 // the start and end of what we have does match what they have.153 // is this file the same size?154 if (contentLength === onDiskSize) {155 // same file size, front and back match, let's accept this. begrudgingly156 session.channels.debug(`Acquire '${outputFilename}': file size is identical. keeping this one`);157 return outputFile;158 }159 // looks like we can continue from here.160 session.channels.debug(`Acquire '${outputFilename}': ok to resume`);161 resumeAtOffset = onDiskSize;162 }163 }164 }165 }166 }167 if (resumeAtOffset === 0) {168 // clearly we mean to not resume. clean any existing file.169 session.channels.debug(`Acquire '${outputFilename}': not resuming file, full download`);170 await outputFile.delete();171 }172 url = url || await locations.availableLocation;173 strict.ok(!!url, `Requested file ${outputFilename} has no accessible locations ${uris.map(each => each.toString()).join(',')}`);174 session.channels.debug(`Acquire '${outputFilename}': initiating download`);175 const length = await locations.contentLength;176 const inputStream = getStream(url, { start: resumeAtOffset, end: length > 0 ? length : undefined, credentials: options?.credentials });177 let progressStream;178 if (length > 0) {179 progressStream = new ProgressTrackingStream(resumeAtOffset, length);180 progressStream.on('progress', (filePercentage) => ee.emit('download', outputFilename, filePercentage));181 }182 const outputStream = await outputFile.writeStream({ append: true });183 ee.emit('download', outputFilename, 0);184 // whoooosh. write out the file185 if (progressStream) {186 await pipeline(inputStream, progressStream, outputStream);187 } else {188 await pipeline(inputStream, outputStream);189 }190 // we've downloaded the file, let's see if it matches the hash we have.191 if (options?.algorithm) {192 session.channels.debug(`Acquire '${outputFilename}': checking downloaded file hash`);193 // does it match the hash that we have?194 if (!await outputFile.hashValid(options)) {195 await outputFile.delete();196 throw new Error(i`Downloaded file '${outputFile.fsPath}' did not have the correct hash (${options.algorithm}: ${options.value}) `);197 }198 session.channels.debug(`Acquire '${outputFilename}': downloaded file hash matches specified hash`);199 }200 session.channels.debug(`Acquire '${outputFilename}': downloading file successful`);201 ee.emit('download', outputFilename, 1000);202 ee.emit('complete');203 return outputFile;204}205export async function resolveNugetUrl(session: Session, pkg: string) {206 const [, name, version] = pkg.match(/^(.*)\/(.*)$/) ?? [];207 strict.ok(version, i`package reference '${pkg}' is not a valid nuget package reference ({name}/{version})`);208 // let's resolve the redirect first, since nuget servers don't like us getting HEAD data on the targets via a redirect.209 // even if this wasn't the case, this is lower cost now rather than later.210 const url = await resolveRedirect(session.parseUri(`https://www.nuget.org/api/v2/package/${name}/${version}`));211 session.channels.debug(`Resolving nuget package for '${pkg}' to '${url}'`);212 return url;213}214export async function nuget(session: Session, pkg: string, outputFilename: string, options?: AcquireOptions): Promise<Uri> {215 return https(session, [await resolveNugetUrl(session, pkg)], outputFilename, options);216}217/** @internal */218export async function git(session: Session, repo: Uri, progress: Progress, options?: AcquireOptions): Promise<void> {219 // clone the uri220 // save it to the cache...
index.js
Source:index.js
1const { createCanvas, loadImage } = require('canvas');2const fs = require('fs');3const [filePath] = process.argv.slice(2);4async function draw({ width, height, img, outputFileName }) {5 let canvas = new createCanvas(width, height); //ç«å¸6 let ctx = canvas.getContext('2d');7 ctx.drawImage(img, 0, 0, width, height); //繪ç«ç¯å8 await fs.writeFileSync(`./dist/${outputFileName}`, canvas.toBuffer());9}10async function init() {11 const img = await loadImage(filePath);12 const imageConfigs = [13 {14 width: 192,15 height: 192,16 outputFileName: 'android-chrome-192x192.png',17 },18 {19 width: 512,20 height: 512,21 outputFileName: 'android-chrome-512x512.png',22 },23 {24 width: 192,25 height: 192,26 outputFileName: 'android-chrome-maskable-192x192.png',27 },28 {29 width: 512,30 height: 512,31 outputFileName: 'android-chrome-maskable-512x512.png',32 },33 {34 width: 60,35 height: 60,36 outputFileName: 'apple-touch-icon-60x60.png',37 },38 {39 width: 76,40 height: 76,41 outputFileName: 'apple-touch-icon-76x76.png',42 },43 {44 width: 120,45 height: 120,46 outputFileName: 'apple-touch-icon-120x120.png',47 },48 {49 width: 152,50 height: 152,51 outputFileName: 'apple-touch-icon-152x152.png',52 },53 {54 width: 180,55 height: 180,56 outputFileName: 'apple-touch-icon-180x180.png',57 },58 {59 width: 180,60 height: 180,61 outputFileName: 'apple-touch-icon.png',62 },63 {64 width: 16,65 height: 16,66 outputFileName: 'favicon-16x16.png',67 },68 {69 width: 32,70 height: 32,71 outputFileName: 'favicon-32x32.png',72 },73 {74 width: 144,75 height: 144,76 outputFileName: 'msapplication-icon-144x144.png',77 },78 {79 width: 270,80 height: 270,81 outputFileName: 'mstile-150x150.png',82 },83 ];84 for (let { width, height, outputFileName } of imageConfigs) {85 await draw({ width, height, img, outputFileName });86 }87}...
Using AI Code Generation
1var outputFileName = require('stryker-parent').outputFileName;2console.log(outputFileName('test.js'));3var outputFileName = require('stryker-parent').outputFileName;4console.log(outputFileName('test.js'));5var outputFileName = require('stryker-parent').outputFileName;6console.log(outputFileName('test.js'));7var outputFileName = require('stryker-parent').outputFileName;8console.log(outputFileName('test.js'));9var outputFileName = require('stryker-parent').outputFileName;10console.log(outputFileName('test.js'));11var outputFileName = require('stryker-parent').outputFileName;12console.log(outputFileName('test.js'));13var outputFileName = require('stryker-parent').outputFileName;14console.log(outputFileName('test.js'));15var outputFileName = require('stryker-parent').outputFileName;16console.log(outputFileName('test.js'));17var outputFileName = require('stryker-parent').outputFileName;18console.log(outputFileName('test.js'));19var outputFileName = require('stryker-parent').outputFileName;20console.log(outputFileName('test.js'));21var outputFileName = require('stryker-parent').outputFileName;22console.log(outputFileName('test.js'));
Using AI Code Generation
1var outputFileName = require('stryker-parent').outputFileName;2var outputFile = outputFileName('test.js');3var outputFileName = require('stryker').outputFileName;4var outputFile = outputFileName('test.js');5var outputFileName = require('stryker-parent').outputFileName;6var outputFile = outputFileName('test.js');7var outputFileName = require('stryker').outputFileName;8var outputFile = outputFileName('test.js');9var outputFileName = require('stryker-parent').outputFileName;10var outputFile = outputFileName('test.js');11var outputFileName = require('stryker').outputFileName;12var outputFile = outputFileName('test.js');13var outputFileName = require('stryker-parent').outputFileName;14var outputFile = outputFileName('test.js');15var outputFileName = require('stryker').outputFileName;16var outputFile = outputFileName('test.js');17var outputFileName = require('stryker-parent').outputFileName;18var outputFile = outputFileName('test.js');19var outputFileName = require('stryker').outputFileName;20var outputFile = outputFileName('test.js');
Using AI Code Generation
1var outputFileName = require('stryker-parent').outputFileName;2var fileName = outputFileName('foo.js');3console.log(fileName);4var outputFileName = require('stryker-parent').outputFileName;5var fileName = outputFileName('foo.js');6console.log(fileName);7outputFileName ( fileName : string ) : string8class StrykerTempFolder { constructor ( baseDir : string ) ; create () : string ; clean () : void ; }
Using AI Code Generation
1console.log(outputFileName('test.js'));2console.log(outputFileName('test.js', 'test'));3console.log(outputFileName('test.js', 'test', 'test'));4console.log(outputFileName('test.js', 'test', 'test', 'test'));5console.log(outputFileName('test.js', 'test', 'test', 'test', 'test'));6console.log(outputFileName('test.js', 'test', 'test', 'test', 'test', 'test'));7console.log(outputFileName('test.js', 'test', 'test', 'test', 'test', 'test', 'test'));8console.log(outputFileName('test.js', 'test', 'test', 'test', 'test', 'test', 'test', 'test'));9console.log(outputFileName('test.js', 'test', 'test', 'test', 'test', 'test', 'test', 'test', 'test'));10console.log(outputFileName('test.js', 'test', 'test', 'test', 'test', 'test', 'test', 'test', 'test', 'test'));
Using AI Code Generation
1const outputFileName = require('stryker-parent').outputFileName;2console.log(outputFileName('test.js'));3const outputFileName = require('stryker-parent').outputFileName;4console.log(outputFileName('test.js'));5const outputFileName = require('stryker-parent').outputFileName;6console.log(outputFileName('test.js'));7const outputFileName = require('stryker-parent').outputFileName;8console.log(outputFileName('test.js'));9const outputFileName = require('stryker-parent').outputFileName;10console.log(outputFileName('test.js'));11const outputFileName = require('stryker-parent').outputFileName;12console.log(outputFileName('test.js'));13const outputFileName = require('stryker-parent').outputFileName;14console.log(outputFileName('test.js'));15const outputFileName = require('stryker-parent').outputFileName;16console.log(outputFileName('test.js'));17const outputFileName = require('stryker-parent').outputFileName;18console.log(outputFileName('test.js'));19const outputFileName = require('stryker-parent').outputFileName;20console.log(outputFileName('test.js'));
Using AI Code Generation
1var stryker = require('stryker-parent');2var outputFileName = stryker.outputFileName;3var outputFile = outputFileName('test.js');4var stryker = require('stryker-parent');5var outputFileName = stryker.outputFileName;6var outputFile = outputFileName('test2.js');7var stryker = require('stryker-parent');8var outputFileName = stryker.outputFileName;9var outputFile = outputFileName('test3.js');10var stryker = require('stryker-parent');11var outputFileName = stryker.outputFileName;12var outputFile = outputFileName('test4.js');13var stryker = require('stryker-parent');14var outputFileName = stryker.outputFileName;15var outputFile = outputFileName('test5.js');16var stryker = require('stryker-parent');17var outputFileName = stryker.outputFileName;18var outputFile = outputFileName('test6.js');19var stryker = require('stryker-parent');20var outputFileName = stryker.outputFileName;21var outputFile = outputFileName('test7.js');22var stryker = require('stryker-parent');23var outputFileName = stryker.outputFileName;24var outputFile = outputFileName('test8.js');
Using AI Code Generation
1const outputFileName = require('stryker-parent').outputFileName;2const path = require('path');3console.log(outputFileName('stryker.conf.js', path.resolve(__dirname, 'stryker.conf.js')));4console.log(outputFileName('stryker.conf.js', path.resolve(__dirname, 'src', 'stryker.conf.js')));5console.log(outputFileName('stryker.conf.js', path.resolve(__dirname, 'src', 'test', 'stryker.conf.js')));6console.log(outputFileName('stryker.conf.js', path.resolve(__dirname, 'src', 'test', 'stryker.conf.js'), 'src'));7console.log(outputFileName('stryker.conf.js', path.resolve(__dirname, 'src', 'test', 'stryker.conf.js'), 'src', 'test'));8console.log(outputFileName('stryker.conf.js', path.resolve(__dirname, 'src', 'test', 'stryker.conf.js'), 'src', 'test', 'test'));9console.log(outputFileName('stryker.conf.js', path.resolve(__dirname, 'src', 'test', 'stryker.conf.js'), 'src', 'test', 'test', 'test'));10console.log(outputFileName('stryker.conf.js', path.resolve(__dirname, 'src', 'test', 'stryker.conf.js'), 'src', 'test', 'test', 'test', 'test'));11console.log(outputFileName('stryker.conf.js', path.resolve(__dirname, 'src', 'test', 'stryker.conf.js'), 'src', 'test', 'test', 'test', 'test', 'test'));12console.log(outputFileName('stryker.conf.js', path.resolve(__dirname, 'src', 'test', 'stryker.conf.js'), 'src', 'test', 'test', 'test', 'test', 'test', 'test'));13console.log(outputFileName('stryker.conf.js', path.resolve(__dirname, 'src', 'test', 'stryker.conf.js'), 'src', 'test', 'test', 'test', 'test', 'test', 'test', 'test
Using AI Code Generation
1var outputFileName = require('stryker-parent').outputFileName;2var path = require('path');3var output = outputFileName('test.js');4console.log(output);5var outputFileName = require('stryker').outputFileName;6var path = require('path');7var output = outputFileName('test.js');8console.log(output);9var outputFileName = require('stryker').outputFileName;10var path = require('path');11var output = outputFileName('test.js');12console.log(output);13var outputFileName = require('stryker').outputFileName;14var path = require('path');15var output = outputFileName('test.js');16console.log(output);17var outputFileName = require('stryker').outputFileName;18var path = require('path');19var output = outputFileName('test.js');20console.log(output);21var outputFileName = require('stryker').outputFileName;22var path = require('path');23var output = outputFileName('test.js');24console.log(output);25var outputFileName = require('stryker').outputFileName;26var path = require('path');27var output = outputFileName('test.js');28console.log(output);29var outputFileName = require('stryker').outputFileName;30var path = require('path');31var output = outputFileName('test.js');32console.log(output);33var outputFileName = require('stryker').outputFileName;34var path = require('path');35var output = outputFileName('test.js');36console.log(output);
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!