Skip to content
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

feat: attest integration #6963

Open
wants to merge 51 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
8b3be5e
chore: notes
hi-ogawa Nov 4, 2024
bea78b4
feat: skipSnapshot
hi-ogawa Nov 4, 2024
64f01b0
test: more examples
hi-ogawa Nov 5, 2024
9c90cd0
chore: cleanup
hi-ogawa Nov 5, 2024
4c49f5e
test: test skipTypes
hi-ogawa Nov 5, 2024
7a1bf59
Merge branch 'main' into feat-skip-snapshot-serialize
hi-ogawa Nov 7, 2024
f0bd76d
test: tweak
hi-ogawa Nov 7, 2024
ad2f871
test: debug
hi-ogawa Nov 7, 2024
a747c16
test: debug
hi-ogawa Nov 7, 2024
3e3398e
ci: debug
hi-ogawa Nov 7, 2024
bce4c19
ci: debug
hi-ogawa Nov 7, 2024
d893ba6
ci: debug
hi-ogawa Nov 7, 2024
87239e3
ci: debug
hi-ogawa Nov 7, 2024
e77e0db
ci: debug
hi-ogawa Nov 7, 2024
c82948a
ci: debug
hi-ogawa Nov 7, 2024
ab84ba4
Merge branch 'main' into feat-skip-snapshot-serialize
hi-ogawa Nov 9, 2024
13532e5
refactor: move code
hi-ogawa Nov 9, 2024
f508e5d
chore: workaround with reporter onWatcherRerun for now
hi-ogawa Nov 9, 2024
beddaf5
test: compare with expect-type
hi-ogawa Nov 9, 2024
892de16
Merge branch 'main' into feat-skip-snapshot-serialize
hi-ogawa Nov 15, 2024
f6f0bf5
refactor: use onTestsRerun
hi-ogawa Nov 15, 2024
303a3bc
Merge branch 'main' into feat-skip-snapshot-serialize
hi-ogawa Nov 23, 2024
e02c118
wip: update attest + use unwrap
hi-ogawa Nov 23, 2024
fde8997
wip: update attest + use unwrap
hi-ogawa Nov 23, 2024
15fe09a
Merge branch 'main' into feat-skip-snapshot-serialize
hi-ogawa Nov 26, 2024
d3208ca
Merge remote-tracking branch 'origin/feat-skip-snapshot-serialize' in…
hi-ogawa Nov 26, 2024
c89ddcf
wip: add peer dep
hi-ogawa Nov 26, 2024
9faab66
wip: inline
hi-ogawa Nov 26, 2024
f8ab70b
test: cleanup
hi-ogawa Nov 26, 2024
a03b4ef
chore: remove skipSnapshot
hi-ogawa Nov 26, 2024
9131fb3
fix: introduce __vitest_expect_stack
hi-ogawa Nov 26, 2024
56d2f16
wip: add config
hi-ogawa Nov 26, 2024
1ea7439
chore: ensure installed @ark/attest
hi-ogawa Nov 26, 2024
0954423
wip: support normal attest usage
hi-ogawa Nov 26, 2024
b008122
refactor: minor
hi-ogawa Nov 26, 2024
76ab6bb
wip: toMatchTypeErrorSnapshot
hi-ogawa Nov 26, 2024
41ca919
wip: toMatchTypeCompletionInlineSnapshot
hi-ogawa Nov 26, 2024
96c42cf
chore: lint
hi-ogawa Nov 26, 2024
1425192
chore: cleanup
hi-ogawa Nov 26, 2024
2ee32da
Merge branch 'main' into feat-attest-integration
hi-ogawa Nov 26, 2024
0f75be9
Merge branch 'main' into feat-attest-integration
hi-ogawa Nov 26, 2024
09cface
wip: tweak ensureInstalled
hi-ogawa Nov 27, 2024
f9282f7
wip: project._initAttest
hi-ogawa Nov 27, 2024
e1fea76
chore: comment
hi-ogawa Nov 27, 2024
e485ea0
fix: fix ensureInstalled version
hi-ogawa Nov 27, 2024
76df825
chore: cleanup
hi-ogawa Nov 27, 2024
6999339
refactor: remove PrettyFormatSkipSnapshotError hack
hi-ogawa Nov 27, 2024
9c5f652
chore: rename
hi-ogawa Nov 27, 2024
4e2cd79
refactor: use writeAssertionData
hi-ogawa Nov 27, 2024
c0b565e
chore: comment
hi-ogawa Nov 27, 2024
7d0bfd5
refactor: cleanup inline snapshot regex
hi-ogawa Nov 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: skipSnapshot
  • Loading branch information
hi-ogawa committed Nov 4, 2024
commit bea78b48d0013790be0f4fa5076b77c143311e47
8 changes: 4 additions & 4 deletions packages/pretty-format/src/index.ts
Original file line number Diff line number Diff line change
@@ -69,8 +69,8 @@ const SYMBOL_REGEXP = /^Symbol\((.*)\)(.*)$/
const NEWLINE_REGEXP = /\n/g

class PrettyFormatPluginError extends Error {
constructor(message: string, stack: string) {
super(message)
constructor(message: string, stack: string, cause?: unknown) {
super(message, { cause })
this.stack = stack
this.name = this.constructor.name
}
@@ -332,7 +332,7 @@ function printPlugin(
)
}
catch (error: any) {
throw new PrettyFormatPluginError(error.message, error.stack)
throw new PrettyFormatPluginError(error.message, error.stack, error)
}
if (typeof printed !== 'string') {
throw new TypeError(
@@ -350,7 +350,7 @@ function findPlugin(plugins: Plugins, val: unknown) {
}
}
catch (error: any) {
throw new PrettyFormatPluginError(error.message, error.stack)
throw new PrettyFormatPluginError(error.message, error.stack, error)
}
}

2 changes: 1 addition & 1 deletion packages/snapshot/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { SnapshotClient } from './client'

export { stripSnapshotIndentation } from './port/inlineSnapshot'
export { addSerializer, getSerializers } from './port/plugins'
export { addSerializer, getSerializers, skipSnapshot } from './port/plugins'
export { default as SnapshotState } from './port/state'

export type {
7 changes: 7 additions & 0 deletions packages/snapshot/src/port/plugins.ts
Original file line number Diff line number Diff line change
@@ -39,3 +39,10 @@ export function addSerializer(plugin: PrettyFormatPlugin): void {
export function getSerializers(): PrettyFormatPlugins {
return PLUGINS
}

// TODO: expose from pretty-format?
export class SerializerSkipSnapshotError extends Error {}

export function skipSnapshot(): never {
throw new SerializerSkipSnapshotError()
}
20 changes: 15 additions & 5 deletions packages/snapshot/src/port/state.ts
Original file line number Diff line number Diff line change
@@ -19,8 +19,9 @@ import type { InlineSnapshot } from './inlineSnapshot'
import type { RawSnapshot, RawSnapshotInfo } from './rawSnapshot'
import { parseErrorStacktrace } from '../../../utils/src/source-map'
import { saveInlineSnapshots } from './inlineSnapshot'
import { saveRawSnapshots } from './rawSnapshot'
import { SerializerSkipSnapshotError } from './plugins'

import { saveRawSnapshots } from './rawSnapshot'
import {
addExtraLineBreaks,
getSnapshotData,
@@ -261,10 +262,19 @@ export default class SnapshotState {
// - make snapshot assertion extendable to support such options somehow (not sure)
// - recommend to use a separate `include` combination for type testing like before, so partially skiiping snapshot is not necessary.

let receivedSerialized
= rawSnapshot && typeof received === 'string'
? (received as string)
: serialize(received, undefined, this._snapshotFormat)
let receivedSerialized: string
try {
receivedSerialized
= rawSnapshot && typeof received === 'string'
? (received as string)
: serialize(received, undefined, this._snapshotFormat)
}
catch (e) {
if (e instanceof Error && e.cause instanceof SerializerSkipSnapshotError) {
return { pass: true, actual: '<skipped>', key, count }
}
throw e
}

if (!rawSnapshot) {
receivedSerialized = addExtraLineBreaks(receivedSerialized)
1 change: 1 addition & 0 deletions packages/vitest/src/public/index.ts
Original file line number Diff line number Diff line change
@@ -321,6 +321,7 @@ export type {
SnapshotUpdateState,
UncheckedSnapshot,
} from '@vitest/snapshot'
export { skipSnapshot } from '@vitest/snapshot'

/** @deprecated import from `vitest/node` instead */
export type BrowserScript = BrowserScript_
Loading