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

refactor(faster,bundler,core): improve js loader DX #10655

Merged
merged 3 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
add unit tests
  • Loading branch information
slorber committed Nov 8, 2024
commit 7431f8e3fd0802f2df3df7e5b5683dbd3ae0b3c1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions packages/docusaurus/src/server/__tests__/siteMessages.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import path from 'path';
import {fromPartial} from '@total-typescript/shoehorn';
import {collectAllSiteMessages} from '../siteMessages';

function siteDirFixture(name: string) {
return path.resolve(__dirname, '__fixtures__', 'siteMessages', name);
}

describe('collectAllSiteMessages', () => {
describe('uselessBabelConfigMessages', () => {
async function getMessagesFor({
siteDir,
swcJsLoader,
}: {
siteDir: string;
swcJsLoader: boolean;
}) {
return collectAllSiteMessages(
fromPartial({
site: {
props: {
siteDir,
siteConfig: {
future: {
experimental_faster: {
swcJsLoader,
},
},
},
},
},
}),
);
}

it('warns for useless babel config file when SWC enabled', async () => {
const messages = await getMessagesFor({
siteDir: siteDirFixture('siteWithBabelConfigFile'),
swcJsLoader: true,
});
expect(messages).toMatchInlineSnapshot(`
[
{
"message": "Your site is using the SWC js loader. You can safely remove the Babel config file at \`packages/docusaurus/src/server/__tests__/__fixtures__/siteMessages/siteWithBabelConfigFile/babel.config.js\`.",
"type": "warning",
},
]
`);
});

it('does not warn for babel config file when SWC disabled', async () => {
const messages = await getMessagesFor({
siteDir: siteDirFixture('siteWithBabelConfigFile'),
swcJsLoader: false,
});
expect(messages).toMatchInlineSnapshot(`[]`);
});
});
});
4 changes: 3 additions & 1 deletion packages/docusaurus/src/server/siteMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ const uselessBabelConfigMessages: SiteMessageCreator = async ({site}) => {
return [];
};

async function collectAllSiteMessages(params: Params): Promise<SiteMessage[]> {
export async function collectAllSiteMessages(
params: Params,
): Promise<SiteMessage[]> {
const messageCreators: SiteMessageCreator[] = [uselessBabelConfigMessages];
return (
await Promise.all(
Expand Down
Loading