Skip to content

Commit

Permalink
feat: add fileExtension option (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
milahu authored Jul 8, 2024
1 parent ad1cb3b commit 33d32bd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const toMatchFile: (

declare interface FileMatcherOptions {
diff?: DiffOptions;
fileExtension?: string;
}

declare global {
Expand Down
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ const isEqual = (a, b) => {
*
* @param {string | Buffer} content Output content to match
* @param {string} [filepath] Path to the file to match against
* @param {{ diff?: import('jest-diff').DiffOptions }} options Additional options for matching
* @param {{
* diff?: import('jest-diff').DiffOptions,
* fileExtension?: string,
* }} options
* @this {{ testPath: string, currentTestName: string, assertionCalls: number, isNot: boolean, snapshotState: { added: number, updated: number, unmatched: number, _updateSnapshot: 'none' | 'new' | 'all' } }}
*/
exports.toMatchFile = function toMatchFile(content, filepath, options = {}) {
const { isNot, snapshotState } = this;

const fileExtension = options.fileExtension || '';

const filename =
filepath === undefined
? // If file name is not specified, generate one from the test title
Expand All @@ -37,7 +42,7 @@ exports.toMatchFile = function toMatchFile(content, filepath, options = {}) {
`${filenamify(this.currentTestName, {
replacement: '-',
}).replace(/\s/g, '-')}-${this.assertionCalls}`
)
) + fileExtension
: filepath;

options = {
Expand Down

0 comments on commit 33d32bd

Please sign in to comment.