Skip to content

Commit

Permalink
feat: add 'fixtureOutputExt' configuration option (#73)
Browse files Browse the repository at this point in the history
* added 'fixtureOutputExt' configuration option

* Doc for fixtureOutputExt

Co-authored-by: Marek <marek.b@cstechnologies.cz>
  • Loading branch information
CzBuCHi and CzBuCHi authored May 27, 2020
1 parent b5569f4 commit ae67eee
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ Use this to provide your own implementation of babel. This is particularly
useful if you want to use a different version of babel than what's included in
this package.

#### fixtureOutputExt

Use this to provide your own fixture output file extension. This is particularly
useful if you are testing typescript input. If ommited fixture input file extension
will be used.

#### ...rest

The rest of the options you provide will be [`lodash.merge`][lodash.merge]d with
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/fixtures/fixtures/fixtureOutputExt/code.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'use strict';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"fixtureOutputExt": ".js"}
1 change: 1 addition & 0 deletions src/__tests__/fixtures/fixtures/fixtureOutputExt/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'use strict';
13 changes: 7 additions & 6 deletions src/__tests__/plugin-tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,14 @@ test('can pass tests in fixtures relative to the filename', async () => {
}),
)
expect(describeSpy).toHaveBeenCalledTimes(6)
expect(itSpy).toHaveBeenCalledTimes(13)
expect(itSpy).toHaveBeenCalledTimes(14)

expect(itSpy.mock.calls).toEqual([
[`cjs`, expect.any(Function)],
[`js`, expect.any(Function)],
[`normal`, expect.any(Function)],
[`changed`, expect.any(Function)],
[`fixtureOutputExt`, expect.any(Function)],
[`jsx support`, expect.any(Function)],
[`nested a`, expect.any(Function)],
[`nested b`, expect.any(Function)],
Expand Down Expand Up @@ -620,7 +621,7 @@ test('allows formatting fixtures results', async () => {
formatResult: formatResultSpy,
}),
)
expect(formatResultSpy).toHaveBeenCalledTimes(14)
expect(formatResultSpy).toHaveBeenCalledTimes(15)
})

test('works with a formatter adding a empty line', async () => {
Expand All @@ -632,7 +633,7 @@ test('works with a formatter adding a empty line', async () => {
formatResult: formatResultSpy,
}),
)
expect(formatResultSpy).toHaveBeenCalledTimes(14)
expect(formatResultSpy).toHaveBeenCalledTimes(15)
})

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

expect(optionRootFoo).toHaveBeenCalledTimes(13)
expect(optionRootFoo).toHaveBeenCalledTimes(14)
expect(optionFoo).toHaveBeenCalledTimes(2)
expect(optionBar).toHaveBeenCalledTimes(1)
})
Expand Down Expand Up @@ -727,10 +728,10 @@ test('appends to root plugins array', async () => {
}),
)

expect(optionRootFoo).toHaveBeenCalledTimes(13)
expect(optionRootFoo).toHaveBeenCalledTimes(14)
expect(optionFoo).toHaveBeenCalledTimes(2)
expect(optionBar).toHaveBeenCalledTimes(1)
expect(programVisitor).toHaveBeenCalledTimes(14)
expect(programVisitor).toHaveBeenCalledTimes(15)
})

test('endOfLine - default', async () => {
Expand Down
9 changes: 8 additions & 1 deletion src/plugin-tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ const createFixtureTests = (fixturesDir, options) => {
return
}

const ext = `.${codePath.split('.').pop()}`
it(blockTitle, () => {
const {
plugin,
Expand Down Expand Up @@ -345,6 +344,14 @@ const createFixtureTests = (fixturesDir, options) => {
),
)

const {fixtureOutputExt} = fixturePluginOptions
let ext
if (fixtureOutputExt) {
ext = fixtureOutputExt
} else {
ext = `.${codePath.split('.').pop()}`
}

const outputPath = path.join(fixtureDir, `${fixtureOutputName}${ext}`)

if (!fs.existsSync(outputPath)) {
Expand Down

0 comments on commit ae67eee

Please sign in to comment.