-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Add testing mechanism #134
Conversation
I will write a changeset and tests if peeps are on board with this :)
🦋 Changeset detectedLatest commit: fa9dd2f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
const { destination, stdoutMock } = createDestination({ | ||
mock: config.environment === 'test', | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fielding opinions on this interface and the stdoutMock
name in particular
/** | ||
* Convenience method to retrieve a solitary logging call. | ||
* | ||
* Throws an error if more or less than 1 call has been recorded. | ||
* | ||
* This may be asserted against in a test case. | ||
* | ||
* ```typescript | ||
* expect(stdoutMock.onlyCall()).toMatchSnapshot(); | ||
* ``` | ||
*/ | ||
onlyCall: (): object => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we think of any other convenience methods worth implementing in a first cut?
export const createDestination = Object.assign( | ||
(opts: CreateDestinationOptions) => { | ||
const stdoutMock = createStdoutMock( | ||
typeof opts.mock === 'object' ? opts.mock : DEFAULT_MOCK_OPTIONS, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is inherent overhead here in us initialising a stdoutMock
even in production where opts.mock: false
. However this should be truly negligible overhead that is only incurred once on startup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like this. Asserting log output is something that I don't do often but when I want to, it's been a giant pain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙌
I will write a changeset and tests if peeps are on board with this :)