example.coffee (1337B)
1 exec = require '../js/sync-exec' 2 3 4 delay_count = 0 5 delay_check = -> 6 now = (new Date).getTime() 7 unless res1 and res2 and t + 10000 <= now < t + 12000 8 throw new Error 'Timing error' 9 console.log 'DONE' 10 11 t = (new Date).getTime() 12 setTimeout delay_check, 10 13 14 process.stdout.write 'Test #1 (takes ~3 seconds) ... ' 15 # { stdout: '1\n', 16 # stderr: '', 17 # status: 0 } 18 res1 = exec __dirname + '/sh/out.sh', {forceEmulation: true} 19 unless res1.stdout is '1\n' and res1.stderr is '' and res1.status is 0 20 throw new Error 'Result #1 error:\n' + JSON.stringify res1, null, 2 21 console.log 'DONE' 22 23 # { stdout: '2\n', 24 # stderr: '3\n', 25 # status: 1 } 26 process.stdout.write 'Test #2 (takes ~3 seconds) ... ' 27 res2 = exec __dirname + '/sh/err.sh', {forceEmulation: true} 28 unless res2.stdout is '2\n' and res2.stderr is '3\n' and res2.status is 1 29 throw new Error 'Result #2 error:\n' + JSON.stringify res2, null, 2 30 console.log 'DONE' 31 32 process.stdout.write 'Test #3 (takes ~1 second) ... ' 33 try 34 exec __dirname + '/sh/out.sh', 1000, {forceEmulation: true} 35 failed_to_stop = true 36 if failed_to_stop 37 throw new Error 'Failed timeout' 38 console.log 'DONE' 39 40 process.stdout.write 'Test #4 (takes ~3 second) ... ' 41 exec './out.sh', {cwd: __dirname + '/sh', forceEmulation: true} 42 console.log 'DONE' 43 44 process.stdout.write 'Test #5 ... ' # Timeout order test