(name, expected, code)
| 672 | } |
| 673 | |
| 674 | function _expectWarning(name, expected, code) { |
| 675 | if (typeof expected === 'string') { |
| 676 | expected = [[expected, code]]; |
| 677 | } else if (!Array.isArray(expected)) { |
| 678 | expected = Object.entries(expected).map(([a, b]) => [b, a]); |
| 679 | } else if (expected.length !== 0 && !Array.isArray(expected[0])) { |
| 680 | expected = [[expected[0], expected[1]]]; |
| 681 | } |
| 682 | // Deprecation codes are mandatory, everything else is not. |
| 683 | if (name === 'DeprecationWarning') { |
| 684 | expected.forEach(([_, code]) => assert(code, `Missing deprecation code: ${expected}`)); |
| 685 | } |
| 686 | return mustCall((warning) => { |
| 687 | const expectedProperties = expected.shift(); |
| 688 | if (!expectedProperties) { |
| 689 | assert.fail(`Unexpected extra warning received: ${warning}`); |
| 690 | } |
| 691 | const [ message, code ] = expectedProperties; |
| 692 | assert.strictEqual(warning.name, name); |
| 693 | if (typeof message === 'string') { |
| 694 | assert.strictEqual(warning.message, message); |
| 695 | } else { |
| 696 | assert.match(warning.message, message); |
| 697 | } |
| 698 | assert.strictEqual(warning.code, code); |
| 699 | }, expected.length); |
| 700 | } |
| 701 | |
| 702 | let catchWarning; |
| 703 |
no test coverage detected
searching dependent graphs…