Skip to content

Commit

Permalink
fix(pluginNameInference): remove the inference. Default to "unknown p…
Browse files Browse the repository at this point in the history
…lugin" (#78)

Closes #60

BREAKING CHANGE: Plugin name inference is no longer supported
  • Loading branch information
kentcdodds authored Oct 2, 2020
1 parent 1e12528 commit 91c22ec
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 56 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ function identifierReversePlugin() {

#### pluginName

This is used for the `describe` title as well as the test titles. If it can be
inferred from the `plugin`'s `name` then it will be and you don't need to
provide this option.
This is used for the `describe` title as well as the test titles.

#### pluginOptions

Expand Down Expand Up @@ -221,8 +219,8 @@ 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.
useful if you are testing typescript input. If ommited fixture input file
extension will be used.

#### ...rest

Expand Down Expand Up @@ -588,6 +586,7 @@ Thanks goes to these people ([emoji key][emojis]):

<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors][all-contributors] specification.
Expand Down
2 changes: 0 additions & 2 deletions src/__tests__/__snapshots__/plugin-tester.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ exports[`assert throws if code is unchanged + snapshot enabled 1`] = `Code was u

exports[`assert throws if snapshot and output are both provided 1`] = `\`output\` cannot be provided with \`snapshot: true\``;

exports[`assert throws if the plugin name is not inferable 1`] = `The \`pluginName\` must be inferable or provided.`;

exports[`assert throws if there's no code 1`] = `A string or object with a \`code\` or \`fixture\` property must be provided`;

exports[`can fail tests in fixtures at an absolute path 1`] = `actual output does not match output.js`;
Expand Down
33 changes: 0 additions & 33 deletions src/__tests__/plugin-tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,6 @@ test('plugin is required', async () => {
await expect(runPluginTester()).rejects.toThrowErrorMatchingSnapshot()
})

test('logs when plugin name is not inferable and rethrows errors', async () => {
const error = new Error('hey there')
await expect(
runPluginTester({
plugin: () => {
throw error
},
}),
).rejects.toThrow(error)
expect(errorSpy).toHaveBeenCalledTimes(1)
expect(errorSpy).toHaveBeenCalledWith(
expect.stringMatching(/infer.*name.*plugin/),
)
})

test('assert throws if the plugin name is not inferable', async () => {
await expect(
runPluginTester({
plugin: () => ({}),
}),
).rejects.toThrowErrorMatchingSnapshot()
})

test('exists early if no tests are supplied', async () => {
const {plugin} = getOptions()
await runPluginTester({plugin})
Expand All @@ -115,16 +92,6 @@ test('accepts a title for the describe block', async () => {
expect(describeSpy).toHaveBeenCalledWith(title, expect.any(Function))
})

test('can infer the plugin name for the describe block', async () => {
const name = 'super-great'
const {plugin, tests} = getOptions({
plugin: () => ({name, visitor: {}}),
})
await runPluginTester({plugin, tests})
expect(describeSpy).toHaveBeenCalledTimes(1)
expect(describeSpy).toHaveBeenCalledWith(name, expect.any(Function))
})

test('calls describe and test for a group of tests', async () => {
const pluginName = 'supergirl'
const customTitle = 'some custom title'
Expand Down
17 changes: 1 addition & 16 deletions src/plugin-tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function pluginTester({
/* istanbul ignore next (TODO: write a test for this) */
babel = require('@babel/core'),
plugin = requiredParam('plugin'),
pluginName = getPluginName(plugin, babel),
pluginName = 'unknown plugin',
title: describeBlockTitle = pluginName,
pluginOptions,
tests,
Expand Down Expand Up @@ -442,21 +442,6 @@ function requiredParam(name) {
throw new Error(`${name} is a required parameter.`)
}

function getPluginName(plugin, babel) {
let name
try {
name = plugin(babel).name
} catch (error) {
// eslint-disable-next-line no-console
console.error(
'Attempting to infer the name of your plugin failed. Tried to invoke the plugin which threw the error.',
)
throw error
}
assert(name, 'The `pluginName` must be inferable or provided.')
return name
}

export default pluginTester

// unfortunately the ESLint plugin for Jest thinks this is a test file
Expand Down

0 comments on commit 91c22ec

Please sign in to comment.