jest-snapshot
Advanced tools
Comparing version 29.0.0-alpha.5 to 29.0.0-alpha.6
@@ -9,4 +9,4 @@ /** | ||
import type {FS} from 'jest-haste-map'; | ||
import type {MatcherFunctionWithState} from 'expect'; | ||
import type {MatcherState} from 'expect'; | ||
import type {MatcherContext} from 'expect'; | ||
import type {MatcherFunctionWithContext} from 'expect'; | ||
import type {OptionsReceived} from 'pretty-format'; | ||
@@ -33,3 +33,3 @@ import {Plugin as Plugin_2} from 'pretty-format'; | ||
declare interface Context extends MatcherState { | ||
declare interface Context extends MatcherContext { | ||
snapshotState: SnapshotState; | ||
@@ -129,2 +129,3 @@ } | ||
private _snapshotFormat; | ||
private _rootDir; | ||
added: number; | ||
@@ -156,15 +157,16 @@ expand: boolean; | ||
updateSnapshot: Config.SnapshotUpdateState; | ||
prettierPath: string; | ||
prettierPath?: string | null; | ||
expand?: boolean; | ||
snapshotFormat: OptionsReceived; | ||
rootDir: string; | ||
}; | ||
export declare const toMatchInlineSnapshot: MatcherFunctionWithState<Context>; | ||
export declare const toMatchInlineSnapshot: MatcherFunctionWithContext<Context>; | ||
export declare const toMatchSnapshot: MatcherFunctionWithState<Context>; | ||
export declare const toMatchSnapshot: MatcherFunctionWithContext<Context>; | ||
export declare const toThrowErrorMatchingInlineSnapshot: MatcherFunctionWithState<Context>; | ||
export declare const toThrowErrorMatchingInlineSnapshot: MatcherFunctionWithContext<Context>; | ||
export declare const toThrowErrorMatchingSnapshot: MatcherFunctionWithState<Context>; | ||
export declare const toThrowErrorMatchingSnapshot: MatcherFunctionWithContext<Context>; | ||
export {}; |
@@ -100,3 +100,3 @@ 'use strict'; | ||
function saveInlineSnapshots(snapshots, prettierPath) { | ||
function saveInlineSnapshots(snapshots, rootDir, prettierPath) { | ||
let prettier = null; | ||
@@ -123,2 +123,3 @@ | ||
sourceFilePath, | ||
rootDir, | ||
prettier && _semver.default.gte(prettier.version, '1.5.0') | ||
@@ -131,3 +132,3 @@ ? prettier | ||
const saveSnapshotsForFile = (snapshots, sourceFilePath, prettier) => { | ||
const saveSnapshotsForFile = (snapshots, sourceFilePath, rootDir, prettier) => { | ||
const sourceFile = jestReadFile(sourceFilePath, 'utf8'); // TypeScript projects may not have a babel config; make sure they can be parsed anyway. | ||
@@ -150,9 +151,34 @@ | ||
const snapshotMatcherNames = []; | ||
const ast = parseSync(sourceFile, { | ||
filename: sourceFilePath, | ||
plugins, | ||
presets, | ||
root: path.dirname(sourceFilePath) | ||
}); | ||
let ast = null; | ||
try { | ||
ast = parseSync(sourceFile, { | ||
filename: sourceFilePath, | ||
plugins, | ||
presets, | ||
root: rootDir | ||
}); | ||
} catch (error) { | ||
// attempt to recover from missing jsx plugin | ||
if (error.message.includes('@babel/plugin-syntax-jsx')) { | ||
try { | ||
const jsxSyntaxPlugin = [ | ||
require.resolve('@babel/plugin-syntax-jsx'), | ||
{}, // unique name to make sure Babel does not complain about a possible duplicate plugin. | ||
'JSX syntax plugin added by Jest snapshot' | ||
]; | ||
ast = parseSync(sourceFile, { | ||
filename: sourceFilePath, | ||
plugins: [...plugins, jsxSyntaxPlugin], | ||
presets, | ||
root: rootDir | ||
}); | ||
} catch { | ||
throw error; | ||
} | ||
} else { | ||
throw error; | ||
} | ||
} | ||
if (!ast) { | ||
@@ -159,0 +185,0 @@ throw new Error(`jest-snapshot: Failed to parse ${sourceFilePath}`); |
@@ -76,2 +76,3 @@ 'use strict'; | ||
_snapshotFormat; | ||
_rootDir; | ||
added; | ||
@@ -92,3 +93,3 @@ expand; | ||
this._dirty = dirty; | ||
this._prettierPath = options.prettierPath; | ||
this._prettierPath = options.prettierPath ?? null; | ||
this._inlineSnapshots = []; | ||
@@ -105,2 +106,3 @@ this._uncheckedKeys = new Set(Object.keys(this._snapshotData)); | ||
this._snapshotFormat = options.snapshotFormat; | ||
this._rootDir = options.rootDir; | ||
} | ||
@@ -169,2 +171,3 @@ | ||
this._inlineSnapshots, | ||
this._rootDir, | ||
this._prettierPath | ||
@@ -171,0 +174,0 @@ ); |
{ | ||
"name": "jest-snapshot", | ||
"version": "29.0.0-alpha.5", | ||
"version": "29.0.0-alpha.6", | ||
"repository": { | ||
@@ -22,8 +22,9 @@ "type": "git", | ||
"@babel/generator": "^7.7.2", | ||
"@babel/plugin-syntax-jsx": "^7.7.2", | ||
"@babel/plugin-syntax-typescript": "^7.7.2", | ||
"@babel/traverse": "^7.7.2", | ||
"@babel/types": "^7.3.3", | ||
"@jest/expect-utils": "^29.0.0-alpha.4", | ||
"@jest/transform": "^29.0.0-alpha.5", | ||
"@jest/types": "^29.0.0-alpha.4", | ||
"@jest/expect-utils": "^29.0.0-alpha.6", | ||
"@jest/transform": "^29.0.0-alpha.6", | ||
"@jest/types": "^29.0.0-alpha.6", | ||
"@types/babel__traverse": "^7.0.6", | ||
@@ -33,12 +34,12 @@ "@types/prettier": "^2.1.5", | ||
"chalk": "^4.0.0", | ||
"expect": "^29.0.0-alpha.4", | ||
"expect": "^29.0.0-alpha.6", | ||
"graceful-fs": "^4.2.9", | ||
"jest-diff": "^29.0.0-alpha.4", | ||
"jest-diff": "^29.0.0-alpha.6", | ||
"jest-get-type": "^29.0.0-alpha.3", | ||
"jest-haste-map": "^29.0.0-alpha.5", | ||
"jest-matcher-utils": "^29.0.0-alpha.4", | ||
"jest-message-util": "^29.0.0-alpha.4", | ||
"jest-util": "^29.0.0-alpha.4", | ||
"jest-haste-map": "^29.0.0-alpha.6", | ||
"jest-matcher-utils": "^29.0.0-alpha.6", | ||
"jest-message-util": "^29.0.0-alpha.6", | ||
"jest-util": "^29.0.0-alpha.6", | ||
"natural-compare": "^1.4.0", | ||
"pretty-format": "^29.0.0-alpha.4", | ||
"pretty-format": "^29.0.0-alpha.6", | ||
"semver": "^7.3.5" | ||
@@ -49,3 +50,3 @@ }, | ||
"@babel/preset-react": "^7.12.1", | ||
"@jest/test-utils": "^29.0.0-alpha.4", | ||
"@jest/test-utils": "^29.0.0-alpha.6", | ||
"@tsd/typescript": "~4.7.4", | ||
@@ -66,3 +67,3 @@ "@types/graceful-fs": "^4.1.3", | ||
}, | ||
"gitHead": "63e506b5d1558a9132a8fa65151407b0a40be3a5" | ||
"gitHead": "4def94b073cad300e99de378ba900e6ba9b7032f" | ||
} |
93065
24
2634
1
24
+ Added@babel/plugin-syntax-jsx@7.24.1(transitive)
Updated@jest/types@^29.0.0-alpha.6
Updatedexpect@^29.0.0-alpha.6
Updatedjest-diff@^29.0.0-alpha.6
Updatedjest-util@^29.0.0-alpha.6