storybook/code/lib/builder-vite/src/utils/without-vite-plugins.test.ts
2022-12-11 23:11:07 +01:00

201 lines
5.9 KiB
TypeScript

import { withoutVitePlugins } from './without-vite-plugins';
describe('withoutVitePlugins', () => {
describe('should remove', () => {
it('plugin in root', async () => {
const plugins = [{ name: 'vite-plugin-root-to-remove' }, { name: 'vite-plugin-root-keep' }];
const names = ['vite-plugin-root-to-remove'];
expect(await withoutVitePlugins(plugins, names)).toMatchInlineSnapshot(`
Array [
Object {
"name": "vite-plugin-root-keep",
},
]
`);
});
it('plugin in nested array', async () => {
const plugins = [
[{ name: 'vite-plugin-nested-to-remove' }, { name: 'vite-plugin-nested-keep' }],
{ name: 'vite-plugin-root-keep' },
];
const names = ['vite-plugin-nested-to-remove'];
expect(await withoutVitePlugins(plugins, names)).toMatchInlineSnapshot(`
Array [
Array [
Object {
"name": "vite-plugin-nested-keep",
},
],
Object {
"name": "vite-plugin-root-keep",
},
]
`);
});
it('plugin in nested async array', async () => {
const plugins = [
Promise.resolve([
{ name: 'vite-plugin-nested-async-to-remove' },
{ name: 'vite-plugin-nested-async-keep' },
]),
];
const names = ['vite-plugin-nested-async-to-remove'];
expect(await withoutVitePlugins(plugins, names)).toMatchInlineSnapshot(`
Array [
Array [
Object {
"name": "vite-plugin-nested-async-keep",
},
],
]
`);
});
it('async plugin in root', async () => {
const plugins = [
Promise.resolve({ name: 'vite-plugin-async-root-to-remove' }),
Promise.resolve({ name: 'vite-plugin-async-root-keep' }),
];
const names = ['vite-plugin-async-root-to-remove'];
expect(await withoutVitePlugins(plugins, names)).toMatchInlineSnapshot(`
Array [
Object {
"name": "vite-plugin-async-root-keep",
},
]
`);
});
it('async plugin in nested array', async () => {
const plugins = [
[
Promise.resolve({ name: 'vite-plugin-async-nested-to-remove' }),
Promise.resolve({ name: 'vite-plugin-async-nested-keep' }),
],
Promise.resolve({ name: 'vite-plugin-async-root-keep' }),
];
const names = ['vite-plugin-async-nested-to-remove'];
expect(await withoutVitePlugins(plugins, names)).toMatchInlineSnapshot(`
Array [
Array [
Object {
"name": "vite-plugin-async-nested-keep",
},
],
Object {
"name": "vite-plugin-async-root-keep",
},
]
`);
});
it('async plugin in nested async array', async () => {
const plugins = [
Promise.resolve([
Promise.resolve({ name: 'vite-plugin-async-nested-async-to-remove' }),
Promise.resolve({ name: 'vite-plugin-async-nested-async-keep' }),
]),
];
const names = ['vite-plugin-async-nested-async-to-remove'];
expect(await withoutVitePlugins(plugins, names)).toMatchInlineSnapshot(`
Array [
Array [
Object {
"name": "vite-plugin-async-nested-async-keep",
},
],
]
`);
});
it('multiple plugins in root', async () => {
const plugins = [
{ name: 'vite-plugin-root-first-to-remove' },
{ name: 'vite-plugin-root-keep' },
{ name: 'vite-plugin-root-second-to-remove' },
];
const names = ['vite-plugin-root-first-to-remove', 'vite-plugin-root-second-to-remove'];
expect(await withoutVitePlugins(plugins, names)).toMatchInlineSnapshot(`
Array [
Object {
"name": "vite-plugin-root-keep",
},
]
`);
});
it('multiple plugins in all cases', async () => {
const plugins = [
{ name: 'vite-plugin-root-to-remove' },
Promise.resolve({ name: 'vite-plugin-async-root-to-remove' }),
[{ name: 'vite-plugin-nested-to-remove' }],
Promise.resolve([{ name: 'vite-plugin-async-nested-to-remove' }]),
[Promise.resolve({ name: 'vite-plugin-nested-async-to-remove' })],
Promise.resolve([Promise.resolve({ name: 'vite-plugin-async-nested-async-to-remove' })]),
];
const names = [
'vite-plugin-root-to-remove',
'vite-plugin-async-root-to-remove',
'vite-plugin-nested-to-remove',
'vite-plugin-async-nested-to-remove',
'vite-plugin-nested-async-to-remove',
'vite-plugin-async-nested-async-to-remove',
];
expect(await withoutVitePlugins(plugins, names)).toMatchInlineSnapshot(`
Array [
Array [],
Array [],
Array [],
Array [],
]
`);
});
});
it('should no-op if plugins are not found', async () => {
const plugins = [
{ name: 'vite-plugin-root' },
[{ name: 'vite-plugin-in-nested-array' }],
Promise.resolve({ name: 'vite-plugin-async-root' }),
Promise.resolve([{ name: 'vite-plugin-in-nested-async-array' }]),
Promise.resolve([Promise.resolve({ name: 'vite-plugin-async-in-nested-async-array' })]),
];
const names = ['vite-plugin-to-remove-first', 'vite-plugin-to-remove-second'];
expect(await withoutVitePlugins(plugins, names)).toMatchInlineSnapshot(`
Array [
Object {
"name": "vite-plugin-root",
},
Array [
Object {
"name": "vite-plugin-in-nested-array",
},
],
Object {
"name": "vite-plugin-async-root",
},
Array [
Object {
"name": "vite-plugin-in-nested-async-array",
},
],
Array [
Object {
"name": "vite-plugin-async-in-nested-async-array",
},
],
]
`);
});
});