Skip to content

Commit

Permalink
Add the ignore test option
Browse files Browse the repository at this point in the history
  • Loading branch information
remcohaszing committed Oct 8, 2024
1 parent 5a0d197 commit 59bdaed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@ return a string that should match the expected output. A second argument `option
This may contain the options of the fixture. These options are read from the `options.cjs`,
`options.js`, `options.json` or `options.mjs` file in the fixture directory.

A test may be an object with the `generate` and optional `input`, `expected` properties. In this
case `input` determines which input file to read, `generate` serves as the generate function, and
`expected` refers to the expected output file.
A test may be an object with the `generate` and optional `input`, `expected`, and `ignore`
properties. In this case `input` determines which input file to read, `generate` serves as the
generate function, and `expected` refers to the expected output file. If `ignore` is true, the
result is written, but assertion failures are ignored.

## Compatibility

Expand Down
11 changes: 10 additions & 1 deletion src/fixtures-directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ type Generate<Options> = (
) => Buffer | PromiseLike<Buffer | VFile | string> | VFile | string

interface FixtureTest<Options> {
/**
* If true, assertion failures are ignored. The expected fixture is still written.
*/
ignore?: boolean

/**
* The fixture input file name to read. If the input has an extension, it’s treated as an exact
* file name. Otherwise, a file is looked up in the fixture directory whose base name matches the
Expand Down Expand Up @@ -184,6 +189,7 @@ export function createTest<T>(
let generate: Generate<T>
let inputUrl: URL
let expectedUrl: URL
let ignore: boolean | undefined

if (typeof spec === 'function') {
generate = spec
Expand All @@ -193,6 +199,7 @@ export function createTest<T>(
generate = spec.generate
inputUrl = await getInputUrl(dir, spec.input)
expectedUrl = new URL(spec.expected ?? name, dir)
ignore = spec.ignore
}

const fixtureOptions = await getOptions(dir)
Expand Down Expand Up @@ -244,7 +251,9 @@ export function createTest<T>(

/* c8 ignore stop */

throw error
if (!ignore) {
throw error
}
}
}
}
Expand Down

0 comments on commit 59bdaed

Please sign in to comment.