-
Notifications
You must be signed in to change notification settings - Fork 858
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ejectPlugins): skip registering default plugins
- Loading branch information
Showing
5 changed files
with
138 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { Options, Plugin } from './types'; | ||
import { | ||
debugProxyErrorsPlugin, | ||
loggerPlugin, | ||
errorResponsePlugin, | ||
proxyEventsPlugin, | ||
} from './plugins/default'; | ||
|
||
export function getPlugins(options: Options): Plugin[] { | ||
const defaultPlugins: Plugin[] = !!options.ejectPlugins | ||
? [] // no default plugins when ejecting | ||
: [debugProxyErrorsPlugin, proxyEventsPlugin, loggerPlugin, errorResponsePlugin]; | ||
const userPlugins: Plugin[] = options.plugins ?? []; | ||
return [...defaultPlugins, ...userPlugins]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { Plugin } from '../../src/types'; | ||
import { getPlugins } from '../../src/get-plugins'; | ||
import { | ||
debugProxyErrorsPlugin, | ||
loggerPlugin, | ||
errorResponsePlugin, | ||
proxyEventsPlugin, | ||
} from '../../src/plugins/default'; | ||
|
||
describe('getPlugins', () => { | ||
let plugins: Plugin[]; | ||
|
||
it('should return default plugins when no user plugins are provided', () => { | ||
plugins = getPlugins({}); | ||
|
||
expect(plugins).toHaveLength(4); | ||
expect(plugins.map((plugin) => plugin.name)).toMatchInlineSnapshot(` | ||
Array [ | ||
"debugProxyErrorsPlugin", | ||
"proxyEventsPlugin", | ||
"loggerPlugin", | ||
"errorResponsePlugin", | ||
] | ||
`); | ||
}); | ||
|
||
it('should return no plugins when ejectPlugins is configured in option', () => { | ||
plugins = getPlugins({ | ||
ejectPlugins: true, | ||
}); | ||
|
||
expect(plugins).toHaveLength(0); | ||
}); | ||
|
||
it('should return user plugins with default plugins when user plugins are provided', () => { | ||
const myPlugin: Plugin = () => { | ||
/* noop */ | ||
}; | ||
plugins = getPlugins({ | ||
plugins: [myPlugin], | ||
}); | ||
|
||
expect(plugins).toHaveLength(5); | ||
expect(plugins.map((plugin) => plugin.name)).toMatchInlineSnapshot(` | ||
Array [ | ||
"debugProxyErrorsPlugin", | ||
"proxyEventsPlugin", | ||
"loggerPlugin", | ||
"errorResponsePlugin", | ||
"myPlugin", | ||
] | ||
`); | ||
}); | ||
|
||
it('should only return user plugins when user plugins are provided with ejectPlugins option', () => { | ||
const myPlugin: Plugin = () => { | ||
/* noop */ | ||
}; | ||
plugins = getPlugins({ | ||
ejectPlugins: true, | ||
plugins: [myPlugin], | ||
}); | ||
|
||
expect(plugins).toHaveLength(1); | ||
expect(plugins.map((plugin) => plugin.name)).toMatchInlineSnapshot(` | ||
Array [ | ||
"myPlugin", | ||
] | ||
`); | ||
}); | ||
|
||
it('should return manually added default plugins in different order after using ejectPlugins', () => { | ||
plugins = getPlugins({ | ||
ejectPlugins: true, | ||
plugins: [debugProxyErrorsPlugin, errorResponsePlugin, loggerPlugin, proxyEventsPlugin], // alphabetical order | ||
}); | ||
|
||
expect(plugins).toHaveLength(4); | ||
expect(plugins.map((plugin) => plugin.name)).toMatchInlineSnapshot(` | ||
Array [ | ||
"debugProxyErrorsPlugin", | ||
"errorResponsePlugin", | ||
"loggerPlugin", | ||
"proxyEventsPlugin", | ||
] | ||
`); | ||
}); | ||
}); |