Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(rollup-plugin): speed up and reduce memory usage in tests #4534

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading