Skip to content

Commit 59bdaed

Browse files
committed
Add the ignore test option
1 parent 5a0d197 commit 59bdaed

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,10 @@ return a string that should match the expected output. A second argument `option
121121
This may contain the options of the fixture. These options are read from the `options.cjs`,
122122
`options.js`, `options.json` or `options.mjs` file in the fixture directory.
123123

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

128129
## Compatibility
129130

src/fixtures-directory.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ type Generate<Options> = (
3030
) => Buffer | PromiseLike<Buffer | VFile | string> | VFile | string
3131

3232
interface FixtureTest<Options> {
33+
/**
34+
* If true, assertion failures are ignored. The expected fixture is still written.
35+
*/
36+
ignore?: boolean
37+
3338
/**
3439
* The fixture input file name to read. If the input has an extension, it’s treated as an exact
3540
* file name. Otherwise, a file is looked up in the fixture directory whose base name matches the
@@ -184,6 +189,7 @@ export function createTest<T>(
184189
let generate: Generate<T>
185190
let inputUrl: URL
186191
let expectedUrl: URL
192+
let ignore: boolean | undefined
187193

188194
if (typeof spec === 'function') {
189195
generate = spec
@@ -193,6 +199,7 @@ export function createTest<T>(
193199
generate = spec.generate
194200
inputUrl = await getInputUrl(dir, spec.input)
195201
expectedUrl = new URL(spec.expected ?? name, dir)
202+
ignore = spec.ignore
196203
}
197204

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

245252
/* c8 ignore stop */
246253

247-
throw error
254+
if (!ignore) {
255+
throw error
256+
}
248257
}
249258
}
250259
}

0 commit comments

Comments
 (0)