Skip to content

Commit

Permalink
test(rollup-plugin): speedup by adding lwc dep to externals (#4534)
Browse files Browse the repository at this point in the history
  • Loading branch information
cardoso authored Sep 9, 2024
1 parent 294d24b commit 19b1e44
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('API versioning', () => {
const bundle = await rollup({
input: path.resolve(__dirname, pathname),
plugins: [lwc(options)],
external: ['lwc'],
onwarn(warning) {
warnings.push(warning);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,36 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import path from 'path';
import { rollup, RollupLog } from 'rollup';
import { rollup, type RollupLog, type RollupBuild } from 'rollup';

import lwc, { type RollupLwcOptions } from '../../index';

async function runRollup(
pathname: string,
options: RollupLwcOptions = {},
{ external = [] as string[] } = {}
): Promise<{ bundle: RollupBuild; warnings: RollupLog[] }> {
const warnings: RollupLog[] = [];

const bundle = await rollup({
input: path.resolve(__dirname, 'fixtures', pathname),
plugins: [lwc(options)],
external: ['lwc', ...external],
onwarn(warning) {
warnings.push(warning);
},
});

import lwc from '../../index';
return {
bundle,
warnings,
};
}

describe('templateConfig', () => {
it('compile with preserveHtmlComments option', async () => {
const bundle = await rollup({
input: path.resolve(__dirname, 'fixtures/test/test.js'),
plugins: [
lwc({
preserveHtmlComments: true,
}),
],
const { bundle } = await runRollup('test/test.js', {
preserveHtmlComments: true,
});

const { output } = await bundle.generate({
Expand All @@ -28,13 +45,8 @@ describe('templateConfig', () => {
});

it('should accept disableSyntheticShadowSupport config flag', async () => {
const bundle = await rollup({
input: path.resolve(__dirname, 'fixtures/test/test.js'),
plugins: [
lwc({
disableSyntheticShadowSupport: true,
}),
],
const { bundle } = await runRollup('test/test.js', {
disableSyntheticShadowSupport: true,
});

const { output } = await bundle.generate({
Expand All @@ -47,13 +59,8 @@ describe('templateConfig', () => {
});

it('should accept enableDynamicComponents config flag', async () => {
const bundle = await rollup({
input: path.resolve(__dirname, 'fixtures/dynamicComponent/dynamicComponent.js'),
plugins: [
lwc({
enableDynamicComponents: true,
}),
],
const { bundle } = await runRollup('dynamicComponent/dynamicComponent.js', {
enableDynamicComponents: true,
});

const { output } = await bundle.generate({
Expand All @@ -64,17 +71,8 @@ describe('templateConfig', () => {
});

it('should accept experimentalDynamicDirective config flag', async () => {
const warnings: RollupLog[] = [];
const bundle = await rollup({
input: path.resolve(__dirname, 'fixtures/experimentalDynamic/experimentalDynamic.js'),
plugins: [
lwc({
experimentalDynamicDirective: true,
}),
],
onwarn(warning) {
warnings.push(warning);
},
const { bundle, warnings } = await runRollup('experimentalDynamic/experimentalDynamic.js', {
experimentalDynamicDirective: true,
});

const { output } = await bundle.generate({
Expand All @@ -92,15 +90,15 @@ describe('templateConfig', () => {
describe('javaScriptConfig', () => {
it('should accept experimentalDynamicComponent config flag', async () => {
const CUSTOM_LOADER = '@salesforce/loader';
const bundle = await rollup({
input: path.resolve(__dirname, 'fixtures/dynamicImportConfig/dynamicImportConfig.js'),
plugins: [
lwc({
experimentalDynamicComponent: { loader: CUSTOM_LOADER, strictSpecifier: true },
}),
],
external: [CUSTOM_LOADER],
});
const { bundle } = await runRollup(
'dynamicImportConfig/dynamicImportConfig.js',
{
experimentalDynamicComponent: { loader: CUSTOM_LOADER, strictSpecifier: true },
},
{
external: [CUSTOM_LOADER],
}
);

const { output } = await bundle.generate({
format: 'esm',
Expand All @@ -116,17 +114,12 @@ describe('lwsConfig', () => {
return string.replace(/\s/g, '');
}

const bundle = await rollup({
input: path.resolve(
__dirname,
'fixtures/lightningWebSecurityTransforms/lightningWebSecurityTransforms.js'
),
plugins: [
lwc({
enableLightningWebSecurityTransforms: true,
}),
],
});
const { bundle } = await runRollup(
'lightningWebSecurityTransforms/lightningWebSecurityTransforms.js',
{
enableLightningWebSecurityTransforms: true,
}
);

const { output } = await bundle.generate({
format: 'esm',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('enableStaticContentOptimization: ', () => {
const bundle = await rollup({
input: path.resolve(__dirname, pathname),
plugins: [lwc(options)],
external: ['lwc'],
onwarn(warning) {
warnings.push(warning);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('integration', () => {
const bundle = await rollup({
input: path.resolve(__dirname, 'fixtures/typescript/typescript.ts'),
plugins: [lwc()],
external: ['lwc'],
});

const result = await bundle.generate({
Expand Down
Loading

0 comments on commit 19b1e44

Please sign in to comment.