Skip to content

Commit

Permalink
fix(src): fix fixtureOutputExt being ignored in root options.json (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xunnamius authored Oct 9, 2022
1 parent 1f0c78b commit 481be19
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/__snapshots__/plugin-tester.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ exports[`throws error if fixture provided and code changes 1`] = `Expected outpu

exports[`throws error when error expected but no error thrown 1`] = `Expected to throw error, but it did not.`;

exports[`throws error when function doesn't return true 1`] = `[BABEL] unknown: test message (While processing: "base$0")`;
exports[`throws error when function doesn't return true 1`] = `[BABEL] unknown file: test message (While processing: "base$0")`;

exports[`throws if output is incorrect 1`] = `Output is incorrect.`;
1 change: 1 addition & 0 deletions src/__tests__/fixtures/fixtureOutputExt/fixture/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/fixtureOutputExt/fixture/output.js
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 @@
'use strict';
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"}
36 changes: 35 additions & 1 deletion src/__tests__/plugin-tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ test('prettier formatter supported', async () => {
)
})

test('gets options from options.json files when using fixtures', async () => {
test('gets options from local and root options.json files when using fixtures', async () => {
const optionRootFoo = jest.fn()
const optionFoo = jest.fn()
const optionBar = jest.fn()
Expand Down Expand Up @@ -673,6 +673,40 @@ test('gets options from options.json files when using fixtures', async () => {
expect(optionBar).toHaveBeenCalledTimes(1)
})

test('respects fixtureOutputExt from root options.json file when using fixtures', async () => {
await runPluginTester(
getOptions({
fixtures: getFixturePath('root-fixtureOutputExt'),
tests: null,
}),
)

expect(writeFileSyncSpy).toHaveBeenCalledTimes(0)

expect(equalSpy).toHaveBeenCalledWith(
getFixtureContents('root-fixtureOutputExt/root/fixture/code.ts'),
getFixtureContents('root-fixtureOutputExt/root/fixture/output.js'),
expect.any(String),
)
})

test('respects fixtureOutputExt from local options.json file when using fixtures', async () => {
await runPluginTester(
getOptions({
fixtures: getFixturePath('fixtureOutputExt'),
tests: null,
}),
)

expect(writeFileSyncSpy).toHaveBeenCalledTimes(0)

expect(equalSpy).toHaveBeenCalledWith(
getFixtureContents('fixtureOutputExt/fixture/code.ts'),
getFixtureContents('fixtureOutputExt/fixture/output.js'),
expect.any(String),
)
})

test('appends to root plugins array', async () => {
const optionRootFoo = jest.fn()
const optionFoo = jest.fn()
Expand Down
30 changes: 12 additions & 18 deletions src/plugin-tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,20 +275,22 @@ const createFixtureTests = (fixturesDir, options) => {
(fs.existsSync(tsCodePath) && tsCodePath) ||
(fs.existsSync(jsxCodePath) && jsxCodePath) ||
(fs.existsSync(tsxCodePath) && tsxCodePath)
let fixturePluginOptions = {}
let localFixtureOptions = {}
if (fs.existsSync(optionsPath)) {
fixturePluginOptions = require(optionsPath)
localFixtureOptions = require(optionsPath)
}

const mergedFixtureAndPluginOptions = {
...rootFixtureOptions,
...options.pluginOptions,
...localFixtureOptions,
}

if (!codePath) {
describe(blockTitle, () => {
createFixtureTests(fixtureDir, {
...options,
pluginOptions: {
...rootFixtureOptions,
...options.pluginOptions,
...fixturePluginOptions,
},
pluginOptions: mergedFixtureAndPluginOptions,
})
})
return
Expand Down Expand Up @@ -316,16 +318,7 @@ const createFixtureTests = (fixturesDir, options) => {
fullDefaultConfig,
{
babelOptions: {
plugins: [
[
plugin,
{
...rootFixtureOptions,
...pluginOptions,
...fixturePluginOptions,
},
],
],
plugins: [[plugin, mergedFixtureAndPluginOptions]],
// if they have a babelrc, then we'll let them use that
// otherwise, we'll just use our simple config
babelrc: hasBabelrc,
Expand All @@ -352,7 +345,8 @@ const createFixtureTests = (fixturesDir, options) => {
fixLineEndings(transformed.code, endOfLine, input),
)

const {fixtureOutputExt} = fixturePluginOptions
const {fixtureOutputExt} = mergedFixtureAndPluginOptions

if (fixtureOutputExt) {
ext = fixtureOutputExt
} else {
Expand Down

0 comments on commit 481be19

Please sign in to comment.