-
Notifications
You must be signed in to change notification settings - Fork 256
test(db): add controlled includes oracle drivers #1720
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,66 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { expectAssertionFailure } from './expected-failure.js' | ||
| import { TraceAssertionError } from './trace-runner.js' | ||
|
|
||
| describe(`expected failure guard`, () => { | ||
| it(`accepts an assertion mismatch at the expected checkpoint`, async () => { | ||
| const guarded = expectAssertionFailure( | ||
| () => { | ||
| try { | ||
| expect(`observed`).toBe(`expected`) | ||
| return Promise.resolve() | ||
| } catch (error) { | ||
| return Promise.reject(new TraceAssertionError(2, error)) | ||
| } | ||
| }, | ||
| { checkpoint: 2 }, | ||
| ) | ||
|
|
||
| await guarded() | ||
| }) | ||
|
|
||
| it(`rejects an assertion mismatch from the wrong checkpoint`, async () => { | ||
| const guarded = expectAssertionFailure( | ||
| () => | ||
| Promise.reject( | ||
| new TraceAssertionError(0, new Error(`startup mismatch`)), | ||
| ), | ||
| { checkpoint: 2 }, | ||
| ) | ||
|
|
||
| await expect(guarded()).rejects.toBeInstanceOf(Error) | ||
| }) | ||
|
|
||
| it(`rejects a runtime error from the expected checkpoint`, async () => { | ||
| const guarded = expectAssertionFailure( | ||
| () => | ||
| Promise.reject( | ||
| new TraceAssertionError(2, new TypeError(`projection failed`)), | ||
| ), | ||
| { checkpoint: 2 }, | ||
| ) | ||
|
|
||
| await expect(guarded()).rejects.toBeInstanceOf(Error) | ||
| }) | ||
|
|
||
| it(`accepts an assertion mismatch with the expected message`, async () => { | ||
| const guarded = expectAssertionFailure( | ||
| () => | ||
| Promise.resolve().then(() => { | ||
| expect([`actual`]).toEqual([`expected`]) | ||
| }), | ||
| { message: /expected/ }, | ||
| ) | ||
|
|
||
| await guarded() | ||
| }) | ||
|
|
||
| it(`rejects runtime errors that happen to have the expected message`, async () => { | ||
| const runtimeError = new TypeError(`expected value is missing`) | ||
| const guarded = expectAssertionFailure(() => Promise.reject(runtimeError), { | ||
| message: /expected/, | ||
| }) | ||
|
|
||
| await expect(guarded()).rejects.toBeInstanceOf(Error) | ||
| }) | ||
| }) | ||
This file contains hidden or 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,29 @@ | ||
| import { expect } from 'vitest' | ||
|
|
||
| type ExpectedAssertionFailure = | ||
| | { checkpoint: number } | ||
| | { message: string | RegExp } | ||
|
|
||
| export function expectAssertionFailure<TArgs extends Array<unknown>>( | ||
| assertion: (...args: TArgs) => Promise<void>, | ||
| expected: ExpectedAssertionFailure, | ||
| ): (...args: TArgs) => Promise<void> { | ||
| return async (...args) => { | ||
| if (`checkpoint` in expected) { | ||
| await expect(assertion(...args)).rejects.toMatchObject({ | ||
| name: `TraceAssertionError`, | ||
| checkpoint: expected.checkpoint, | ||
| cause: { name: `AssertionError` }, | ||
| }) | ||
| return | ||
| } | ||
|
|
||
| await expect(assertion(...args)).rejects.toMatchObject({ | ||
| name: `AssertionError`, | ||
| message: | ||
| typeof expected.message === `string` | ||
| ? expected.message | ||
| : expect.stringMatching(expected.message), | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Add a case where the guarded assertion resolves.
The guard exists to lock in known failures. If the underlying defect is fixed, the guarded assertion resolves and the guard must fail. That path is not covered for either the
checkpointbranch or themessagebranch.Based on learnings, test corner cases including resolved promises.
💚 Proposed additional tests
it(`rejects runtime errors that happen to have the expected message`, async () => { const runtimeError = new TypeError(`expected value is missing`) const guarded = expectAssertionFailure(() => Promise.reject(runtimeError), { message: /expected/, }) await expect(guarded()).rejects.toBeInstanceOf(Error) }) + + it(`rejects an assertion that unexpectedly passes`, async () => { + const guardedCheckpoint = expectAssertionFailure( + () => Promise.resolve(), + { checkpoint: 2 }, + ) + const guardedMessage = expectAssertionFailure(() => Promise.resolve(), { + message: /expected/, + }) + + await expect(guardedCheckpoint()).rejects.toBeInstanceOf(Error) + await expect(guardedMessage()).rejects.toBeInstanceOf(Error) + }) })📝 Committable suggestion
🤖 Prompt for AI Agents
Source: Learnings