| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>audit.js: basic tests</title> | 4 <title>audit.js: basic tests</title> |
| 5 <script src="../../resources/testharness.js"></script> | 5 <script src="../../resources/testharness.js"></script> |
| 6 <script src="../../resources/testharnessreport.js"></script> | 6 <script src="../../resources/testharnessreport.js"></script> |
| 7 <script src="../resources/audit.js"></script> | 7 <script src="../resources/audit.js"></script> |
| 8 </head> | 8 </head> |
| 9 <body> | 9 <body> |
| 10 <script> | 10 <script> |
| 11 var audit = Audit.createTaskRunner({ requireResultFile: true }); | 11 var audit = Audit.createTaskRunner({ requireResultFile: true }); |
| 12 | 12 |
| 13 | 13 |
| 14 // Basic assertion testing. | 14 // Basic assertion testing. |
| 15 audit.define('basic', function (task, should) { | 15 audit.define({ |
| 16 task.describe('Simple unit tests for basic assertions.'); | 16 label: 'basic', |
| 17 description: 'Simple unit tests for basic assertions.' |
| 18 }, function (task, should) { |
| 19 should(OfflineAudioContext, 'OfflineAudioContext').exist(); |
| 20 should(function () { var foo1 = 0; }, 'Setting foo1 to 0').notThrow(); |
| 21 should(function () { var foo2 = bar; }).throw(); |
| 22 should(function () { var foo3 = bar; }).throw('ReferenceError'); |
| 23 should(() => { should(); }, 'Calling should() with no argument') |
| 24 .throw('Error'); |
| 25 should(3 < 5, '3 < 5').beTrue(); |
| 26 should(false).beFalse(); |
| 27 should(1).beEqualTo(1) |
| 28 should(1).notBeEqualTo(2) |
| 29 should(typeof AudioContext.prototype).beEqualTo('object'); |
| 30 should(2).beGreaterThan(1); |
| 31 should(2).beGreaterThanOrEqualTo(2); |
| 32 should(1).beLessThan(2); |
| 33 should(1).beLessThanOrEqualTo(1); |
| 34 should(should(1).beEqualTo(1), 'should(1).beEqualTo(1)').beTrue(); |
| 35 should(true, 'The message is').message('truthful!', 'false!'); |
| 17 | 36 |
| 18 should(OfflineAudioContext, 'OfflineAudioContext').exist(); | 37 let oac = new OfflineAudioContext(1, 128, 44100); |
| 19 should(function () { var foo1 = 0; }, 'Setting foo1 to 0').notThrow(); | 38 Promise.all([ |
| 20 should(function () { var foo2 = bar; }).throw(); | 39 should(oac.startRendering(), 'Start OAC rendering').beResolved(), |
| 21 should(function () { var foo3 = bar; }).throw('ReferenceError'); | 40 should(oac.decodeAudioData(), 'Decoding audio data with no argument'
) |
| 22 should(() => { should(); }, 'Calling should() with no argument') | 41 .beRejected(), |
| 23 .throw('Error'); | 42 should(oac.suspend(), 'Suspending OAC with no argument') |
| 24 should(3 < 5, '3 < 5').beTrue(); | 43 .beRejectedWith('TypeError') |
| 25 should(false).beFalse(); | 44 ]).then(task.done.bind(task)); |
| 26 should(1).beEqualTo(1) | 45 } |
| 27 should(1).notBeEqualTo(2) | 46 ); |
| 28 should(typeof AudioContext.prototype).beEqualTo('object'); | |
| 29 should(2).beGreaterThan(1); | |
| 30 should(2).beGreaterThanOrEqualTo(2); | |
| 31 should(1).beLessThan(2); | |
| 32 should(1).beLessThanOrEqualTo(1); | |
| 33 should(should(1).beEqualTo(1), 'should(1).beEqualTo(1)').beTrue(); | |
| 34 should(true, 'The message is').message('truthful!', 'false!'); | |
| 35 | |
| 36 let oac = new OfflineAudioContext(1, 128, 44100); | |
| 37 Promise.all([ | |
| 38 should(oac.startRendering(), 'Start OAC rendering').beResolved(), | |
| 39 should(oac.decodeAudioData(), 'Decoding audio data with no argument') | |
| 40 .beRejected(), | |
| 41 should(oac.suspend(), 'Suspending OAC with no argument') | |
| 42 .beRejectedWith('TypeError') | |
| 43 ]).then(task.done.bind(task)); | |
| 44 }); | |
| 45 | 47 |
| 46 | 48 |
| 47 // Advanced, mostly array-based numerical testing. Note that some codes | 49 // Advanced, mostly array-based numerical testing. Note that some codes |
| 48 // are commented out to avoid the trybot failure. These failures are | 50 // are commented out to avoid the trybot failure. These failures are |
| 49 // intentional, to demonstrate how the detailed failure report works. | 51 // intentional, to demonstrate how the detailed failure report works. |
| 50 audit.define('numerical', function (task, should) { | 52 audit.define({ |
| 51 task.describe('Numerical assertion unit test.'); | 53 label: 'numerical', |
| 54 description: 'Numerical assertion unit test.' |
| 55 }, function (task, should) { |
| 56 should(2.3).beCloseTo(2, { threshold: 0.3 }); |
| 57 should([1, 1, 1]).beConstantValueOf(1); |
| 58 should([1, 0, 1]).notBeConstantValueOf(1); |
| 59 should([1, 0, 0, 1]).notBeConstantValueOf(1); |
| 60 should([1, 1, 1]).beEqualToArray([1, 1, 1]); |
| 61 should([1, 1, 1, 1, 2, 2, 3, 3, 3]) |
| 62 .containValues([1, 2, 3], 'one, two, three'); |
| 63 should([0.5, 0.5, 0.55, 0.5, 0.45, 0.5]).notGlitch(0.06); |
| 64 task.done(); |
| 65 } |
| 66 ); |
| 52 | 67 |
| 53 should(2.3).beCloseTo(2, { threshold: 0.3 }); | |
| 54 should([1, 1, 1]).beConstantValueOf(1); | |
| 55 should([1, 0, 1]).notBeConstantValueOf(1); | |
| 56 should([1, 0, 0, 1]).notBeConstantValueOf(1); | |
| 57 should([1, 1, 1]).beEqualToArray([1, 1, 1]); | |
| 58 should([1, 1, 1, 1, 2, 2, 3, 3, 3]) | |
| 59 .containValues([1, 2, 3], 'one, two, three'); | |
| 60 should([0.5, 0.5, 0.55, 0.5, 0.45, 0.5]).notGlitch(0.06); | |
| 61 | 68 |
| 69 // The task headline needs to be printed even if there is no description is |
| 70 // given. |
| 71 audit.define('dummy-label-string', function (task) { |
| 62 task.done(); | 72 task.done(); |
| 63 }); | 73 }); |
| 64 | 74 |
| 75 |
| 76 // Test the same thing in a differen way. |
| 77 audit.define({ label: 'dummy-label-object' }, function (task) { |
| 78 task.done(); |
| 79 }); |
| 80 |
| 65 | 81 |
| 66 // This task is defined, but you can selectively opt it out when the task | 82 // This task is defined, but you can selectively opt it out when the task |
| 67 // runs. If you would like to see how failure cases get printed, include | 83 // runs. If you would like to see how failure cases get printed, include |
| 68 // this task and launch the task runner. | 84 // this task and launch the task runner. |
| 69 audit.define('empty', function (task, should) { | 85 audit.define('empty', function (task, should) { |
| 70 task.describe('This is an empty task.'); | |
| 71 | |
| 72 task.done(); | 86 task.done(); |
| 73 }); | 87 }); |
| 74 | 88 |
| 75 | 89 |
| 76 // You can enumerate tasks you want to execute in the order, or simply pass | 90 // You can enumerate tasks you want to execute in the order, or simply pass |
| 77 // no argument to run all the defined tasks. | 91 // no argument to run all the defined tasks. |
| 78 audit.run('numerical', 'basic'); | 92 audit.run('numerical', 'basic', 'dummy-label-string', 'dummy-label-object'); |
| 79 </script> | 93 </script> |
| 80 </body> | 94 </body> |
| 81 </html> | 95 </html> |
| OLD | NEW |