|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +const assert = require('assert'); |
| 4 | + |
| 5 | +if (!common.hasCrypto) { |
| 6 | + console.log('1..0 # Skipped: missing crypto'); |
| 7 | + return; |
| 8 | +} |
| 9 | +const crypto = require('crypto'); |
| 10 | +const tls = require('tls'); |
| 11 | + |
| 12 | +process.on('warning', common.mustCall((warning) => { |
| 13 | + assert.strictEqual(warning.name, 'DeprecationWarning'); |
| 14 | + assert.notStrictEqual(expected.indexOf(warning.message), -1, |
| 15 | + `unexpected error message: "${warning.message}"`); |
| 16 | + // Remove a warning message after it is seen so that we guarantee that we get |
| 17 | + // each message only once. |
| 18 | + expected.splice(expected.indexOf(warning.message), 1); |
| 19 | +}, 2)); |
| 20 | + |
| 21 | +var expected = [ |
| 22 | + 'crypto.Credentials is deprecated. Use tls.SecureContext instead.', |
| 23 | + 'crypto.createCredentials is deprecated. Use tls.createSecureContext instead.' |
| 24 | +]; |
| 25 | + |
| 26 | +// Accessing the deprecated function is enough to trigger the warning event. |
| 27 | +// It does not need to be called. So the assert serves the purpose of both |
| 28 | +// triggering the warning event and confirming that the deprected function is |
| 29 | +// mapped to the correct non-deprecated function. |
| 30 | +assert.strictEqual(crypto.Credentials, tls.SecureContext); |
| 31 | +assert.strictEqual(crypto.createCredentials, tls.createSecureContext); |
0 commit comments