Skip to content

Commit 91c22ec

Browse files
authored
fix(pluginNameInference): remove the inference. Default to "unknown plugin" (#78)
Closes #60 BREAKING CHANGE: Plugin name inference is no longer supported
1 parent 1e12528 commit 91c22ec

File tree

4 files changed

+5
-56
lines changed

4 files changed

+5
-56
lines changed

Diff for: README.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ function identifierReversePlugin() {
116116

117117
#### pluginName
118118

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

123121
#### pluginOptions
124122

@@ -221,8 +219,8 @@ this package.
221219
#### fixtureOutputExt
222220

223221
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.
222+
useful if you are testing typescript input. If ommited fixture input file
223+
extension will be used.
226224

227225
#### ...rest
228226

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

589587
<!-- markdownlint-enable -->
590588
<!-- prettier-ignore-end -->
589+
591590
<!-- ALL-CONTRIBUTORS-LIST:END -->
592591

593592
This project follows the [all-contributors][all-contributors] specification.

Diff for: src/__tests__/__snapshots__/plugin-tester.js.snap

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ exports[`assert throws if code is unchanged + snapshot enabled 1`] = `Code was u
44

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

7-
exports[`assert throws if the plugin name is not inferable 1`] = `The \`pluginName\` must be inferable or provided.`;
8-
97
exports[`assert throws if there's no code 1`] = `A string or object with a \`code\` or \`fixture\` property must be provided`;
108

119
exports[`can fail tests in fixtures at an absolute path 1`] = `actual output does not match output.js`;

Diff for: src/__tests__/plugin-tester.js

-33
Original file line numberDiff line numberDiff line change
@@ -72,29 +72,6 @@ test('plugin is required', async () => {
7272
await expect(runPluginTester()).rejects.toThrowErrorMatchingSnapshot()
7373
})
7474

75-
test('logs when plugin name is not inferable and rethrows errors', async () => {
76-
const error = new Error('hey there')
77-
await expect(
78-
runPluginTester({
79-
plugin: () => {
80-
throw error
81-
},
82-
}),
83-
).rejects.toThrow(error)
84-
expect(errorSpy).toHaveBeenCalledTimes(1)
85-
expect(errorSpy).toHaveBeenCalledWith(
86-
expect.stringMatching(/infer.*name.*plugin/),
87-
)
88-
})
89-
90-
test('assert throws if the plugin name is not inferable', async () => {
91-
await expect(
92-
runPluginTester({
93-
plugin: () => ({}),
94-
}),
95-
).rejects.toThrowErrorMatchingSnapshot()
96-
})
97-
9875
test('exists early if no tests are supplied', async () => {
9976
const {plugin} = getOptions()
10077
await runPluginTester({plugin})
@@ -115,16 +92,6 @@ test('accepts a title for the describe block', async () => {
11592
expect(describeSpy).toHaveBeenCalledWith(title, expect.any(Function))
11693
})
11794

118-
test('can infer the plugin name for the describe block', async () => {
119-
const name = 'super-great'
120-
const {plugin, tests} = getOptions({
121-
plugin: () => ({name, visitor: {}}),
122-
})
123-
await runPluginTester({plugin, tests})
124-
expect(describeSpy).toHaveBeenCalledTimes(1)
125-
expect(describeSpy).toHaveBeenCalledWith(name, expect.any(Function))
126-
})
127-
12895
test('calls describe and test for a group of tests', async () => {
12996
const pluginName = 'supergirl'
13097
const customTitle = 'some custom title'

Diff for: src/plugin-tester.js

+1-16
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function pluginTester({
3737
/* istanbul ignore next (TODO: write a test for this) */
3838
babel = require('@babel/core'),
3939
plugin = requiredParam('plugin'),
40-
pluginName = getPluginName(plugin, babel),
40+
pluginName = 'unknown plugin',
4141
title: describeBlockTitle = pluginName,
4242
pluginOptions,
4343
tests,
@@ -442,21 +442,6 @@ function requiredParam(name) {
442442
throw new Error(`${name} is a required parameter.`)
443443
}
444444

445-
function getPluginName(plugin, babel) {
446-
let name
447-
try {
448-
name = plugin(babel).name
449-
} catch (error) {
450-
// eslint-disable-next-line no-console
451-
console.error(
452-
'Attempting to infer the name of your plugin failed. Tried to invoke the plugin which threw the error.',
453-
)
454-
throw error
455-
}
456-
assert(name, 'The `pluginName` must be inferable or provided.')
457-
return name
458-
}
459-
460445
export default pluginTester
461446

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

0 commit comments

Comments
 (0)