-
Notifications
You must be signed in to change notification settings - Fork 893
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(future): add flags to anticipate breaking changes
- Loading branch information
1 parent
b393732
commit ebd84c3
Showing
7 changed files
with
117 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,21 @@ | ||
'use strict' | ||
|
||
const warning = require('process-warning')() | ||
module.exports = warning | ||
const warning = require('process-warning') | ||
|
||
// const warnName = 'PinoWarning' | ||
/** | ||
* Future flags, specific to the current major-version of Pino. These flags allow for breaking-changes to be introduced | ||
* on a opt-in basis, anticipating behavior of the next major-version. All future flag must be frozen as false. These | ||
* future flags are specific to Pino major-version 9. | ||
*/ | ||
const future = Object.freeze({ | ||
skipUnconditionalStdSerializers: false // see PINODEP010 | ||
}) | ||
|
||
// warning.create(warnName, 'PINODEP010', 'A new deprecation') | ||
const PINODEP010 = warning.createDeprecation({ code: 'PINODEP010', message: 'Unconditional execution of standard serializers for HTTP Request and Response will be discontinued in the next major version.' }) | ||
|
||
module.exports = { | ||
warning: { | ||
PINODEP010 | ||
}, | ||
future | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict' | ||
const { test } = require('tap') | ||
const { future } = require('../lib/deprecations') | ||
const { futureSym } = require('../lib/symbols') | ||
const pino = require('../') | ||
|
||
test('instance future is copied from default future', async ({ same, not }) => { | ||
const instance = pino() | ||
|
||
not(instance[futureSym], future) | ||
same(instance[futureSym], future) | ||
}) | ||
|
||
test('instance future entries may be individually overridden by opts', async ({ match }) => { | ||
const opts = { future: { skipUnconditionalStdSerializers: true } } | ||
const instance = pino(opts) | ||
|
||
match(instance[futureSym], { skipUnconditionalStdSerializers: true }) | ||
}) | ||
|
||
test('instance future entries are kept, when not individually overridden in opts', async ({ match }) => { | ||
const instance = pino({ future: { foo: '-foo-' } }) | ||
|
||
match(instance[futureSym], future) // this is true because opts.future does not override any default property | ||
match(instance[futureSym], { foo: '-foo-' }) | ||
}) | ||
|
||
test('instance future entries are immutable', async ({ throws }) => { | ||
const instance = pino({ future: { foo: '-foo-' } }) | ||
|
||
throws(() => { instance[futureSym].foo = '-FOO-' }, TypeError) | ||
}) | ||
|
||
test('child instance does not accept opts future', async ({ throws }) => { | ||
const parent = pino({ future: { foo: '-foo-' } }) | ||
|
||
throws(() => parent.child({}, { future: { foo: '-FOO-' } }), RangeError) | ||
}) | ||
|
||
test('child inherits future from parent and it is immutable', async ({ equal, throws }) => { | ||
const parent = pino({ future: { foo: '-foo-' } }) | ||
const child = parent.child({}) | ||
|
||
equal(child[futureSym], parent[futureSym]) | ||
throws(() => { child[futureSym].foo = '-FOO-' }, TypeError) | ||
}) |