* Runs tests on encoder invokable. * @param {class} EncoderInvokable * @param {Object|Object[]}
(EncoderInvokable, test)
| 14 | * @param {Object|Object[]} |
| 15 | */ |
| 16 | static test (EncoderInvokable, test) { |
| 17 | if (Array.isArray(test)) { |
| 18 | // handle multiple tests |
| 19 | return test.forEach(test => EncoderTester.test(EncoderInvokable, test)) |
| 20 | } |
| 21 | |
| 22 | if (!test.direction || test.direction === 'both') { |
| 23 | // handle test in both directions |
| 24 | EncoderTester.test(EncoderInvokable, { |
| 25 | settings: test.settings, |
| 26 | direction: 'encode', |
| 27 | content: test.content, |
| 28 | expectedResult: test.expectedResult |
| 29 | }) |
| 30 | EncoderTester.test(EncoderInvokable, { |
| 31 | settings: test.settings, |
| 32 | direction: 'decode', |
| 33 | content: test.expectedResult, |
| 34 | expectedResult: test.content |
| 35 | }) |
| 36 | return |
| 37 | } |
| 38 | |
| 39 | // read direction from test entry |
| 40 | const isEncoding = test.direction.toLowerCase() === 'encode' |
| 41 | |
| 42 | // wrap content in Chain |
| 43 | const content = |
| 44 | test.content instanceof Chain |
| 45 | ? test.content |
| 46 | : Chain.wrap(test.content) |
| 47 | |
| 48 | // wrap expected result in Chain |
| 49 | const expectedResult = |
| 50 | test.expectedResult instanceof Chain |
| 51 | ? test.expectedResult |
| 52 | : Chain.wrap(test.expectedResult) |
| 53 | |
| 54 | // create content and result preview that will be logged |
| 55 | const contentPreview = ChainUtil.preview(content) |
| 56 | const expectedResultPreview = ChainUtil.preview(expectedResult) |
| 57 | |
| 58 | it( |
| 59 | `should ${isEncoding ? 'encode' : 'decode'} ` + |
| 60 | `"${isEncoding ? contentPreview : expectedResultPreview}" ` + |
| 61 | `${isEncoding ? '=>' : '<='} ` + |
| 62 | `"${isEncoding ? expectedResultPreview : contentPreview}"`, |
| 63 | done => { |
| 64 | // create encoder brick instance |
| 65 | const encoder = new EncoderInvokable() |
| 66 | |
| 67 | // apply settings, if any |
| 68 | if (test.settings) { |
| 69 | encoder.setSettingValues(test.settings) |
| 70 | } |
| 71 | |
| 72 | // trigger encoder encode or decode |
| 73 | const result = isEncoding |
no test coverage detected