Skip to content

Commit ae67eee

Browse files
authored
feat: add 'fixtureOutputExt' configuration option (#73)
* added 'fixtureOutputExt' configuration option * Doc for fixtureOutputExt Co-authored-by: Marek <[email protected]>
1 parent b5569f4 commit ae67eee

File tree

6 files changed

+24
-7
lines changed

6 files changed

+24
-7
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ Use this to provide your own implementation of babel. This is particularly
218218
useful if you want to use a different version of babel than what's included in
219219
this package.
220220

221+
#### fixtureOutputExt
222+
223+
Use this to provide your own fixture output file extension. This is particularly
224+
useful if you are testing typescript input. If ommited fixture input file extension
225+
will be used.
226+
221227
#### ...rest
222228

223229
The rest of the options you provide will be [`lodash.merge`][lodash.merge]d with
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
'use strict';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"fixtureOutputExt": ".js"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
'use strict';

src/__tests__/plugin-tester.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,14 @@ test('can pass tests in fixtures relative to the filename', async () => {
305305
}),
306306
)
307307
expect(describeSpy).toHaveBeenCalledTimes(6)
308-
expect(itSpy).toHaveBeenCalledTimes(13)
308+
expect(itSpy).toHaveBeenCalledTimes(14)
309309

310310
expect(itSpy.mock.calls).toEqual([
311311
[`cjs`, expect.any(Function)],
312312
[`js`, expect.any(Function)],
313313
[`normal`, expect.any(Function)],
314314
[`changed`, expect.any(Function)],
315+
[`fixtureOutputExt`, expect.any(Function)],
315316
[`jsx support`, expect.any(Function)],
316317
[`nested a`, expect.any(Function)],
317318
[`nested b`, expect.any(Function)],
@@ -620,7 +621,7 @@ test('allows formatting fixtures results', async () => {
620621
formatResult: formatResultSpy,
621622
}),
622623
)
623-
expect(formatResultSpy).toHaveBeenCalledTimes(14)
624+
expect(formatResultSpy).toHaveBeenCalledTimes(15)
624625
})
625626

626627
test('works with a formatter adding a empty line', async () => {
@@ -632,7 +633,7 @@ test('works with a formatter adding a empty line', async () => {
632633
formatResult: formatResultSpy,
633634
}),
634635
)
635-
expect(formatResultSpy).toHaveBeenCalledTimes(14)
636+
expect(formatResultSpy).toHaveBeenCalledTimes(15)
636637
})
637638

638639
test('prettier formatter supported', async () => {
@@ -682,7 +683,7 @@ test('gets options from options.json files when using fixtures', async () => {
682683
}),
683684
)
684685

685-
expect(optionRootFoo).toHaveBeenCalledTimes(13)
686+
expect(optionRootFoo).toHaveBeenCalledTimes(14)
686687
expect(optionFoo).toHaveBeenCalledTimes(2)
687688
expect(optionBar).toHaveBeenCalledTimes(1)
688689
})
@@ -727,10 +728,10 @@ test('appends to root plugins array', async () => {
727728
}),
728729
)
729730

730-
expect(optionRootFoo).toHaveBeenCalledTimes(13)
731+
expect(optionRootFoo).toHaveBeenCalledTimes(14)
731732
expect(optionFoo).toHaveBeenCalledTimes(2)
732733
expect(optionBar).toHaveBeenCalledTimes(1)
733-
expect(programVisitor).toHaveBeenCalledTimes(14)
734+
expect(programVisitor).toHaveBeenCalledTimes(15)
734735
})
735736

736737
test('endOfLine - default', async () => {

src/plugin-tester.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ const createFixtureTests = (fixturesDir, options) => {
293293
return
294294
}
295295

296-
const ext = `.${codePath.split('.').pop()}`
297296
it(blockTitle, () => {
298297
const {
299298
plugin,
@@ -345,6 +344,14 @@ const createFixtureTests = (fixturesDir, options) => {
345344
),
346345
)
347346

347+
const {fixtureOutputExt} = fixturePluginOptions
348+
let ext
349+
if (fixtureOutputExt) {
350+
ext = fixtureOutputExt
351+
} else {
352+
ext = `.${codePath.split('.').pop()}`
353+
}
354+
348355
const outputPath = path.join(fixtureDir, `${fixtureOutputName}${ext}`)
349356

350357
if (!fs.existsSync(outputPath)) {

0 commit comments

Comments
 (0)