Skip to content

Commit

Permalink
fix: unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
caohuilin committed Dec 12, 2024
1 parent 52447ce commit dceb150
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 15 deletions.
1 change: 1 addition & 0 deletions packages/runtime/plugin-router-v5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
},
"dependencies": {
"@modern-js/plugin": "workspace:*",
"@modern-js/plugin-v2": "workspace:*",
"@modern-js/runtime-utils": "workspace:*",
"@modern-js/types": "workspace:*",
"@modern-js/utils": "workspace:*",
Expand Down
53 changes: 43 additions & 10 deletions packages/runtime/plugin-router-v5/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { AppContext, manager } from '@modern-js/core';
import RuntimePlugin from '@modern-js/runtime/cli';
import type { AppTools } from '@modern-js/app-tools';
import { createPluginManager } from '@modern-js/plugin-v2';
import { createContext, initPluginAPI } from '@modern-js/plugin-v2/cli';
import runtimePlugin from '@modern-js/runtime/cli';
import plugin, { useHistory, useParams } from '../src';
import cliPlugin from '../src/cli';

Expand All @@ -12,20 +14,51 @@ describe('plugin-router-legacy', () => {
});

describe('cli-router-legacy', () => {
const main = manager.clone().usePlugin(RuntimePlugin, cliPlugin as any);
let runner: any;

beforeAll(async () => {
runner = await main.init();
});
const setup = async () => {
const pluginManager = createPluginManager();
pluginManager.addPlugins([runtimePlugin(), cliPlugin() as Plugin]);
const plugins = pluginManager.getPlugins();
const context = await createContext<AppTools>({
appContext: {
plugins,
} as any,
config: {},
normalizedConfig: { plugins: [] } as any,
});
const pluginAPI = {
...initPluginAPI<AppTools>({
context,
pluginManager,
}),
checkEntryPoint: ({ path, entry }: any) => {
return { path, entry };
},
modifyEntrypoints: ({ entrypoints }: any) => {
return { entrypoints };
},
generateEntryCode: async ({ entrypoints }: any) => {},
_internalRuntimePlugins: ({ entrypoint, plugins }: any) => {
return { entrypoint, plugins };
},
addRuntimeExports: () => {},
modifyFileSystemRoutes: () => {},
onBeforeGenerateRoutes: () => {},
};
context.pluginAPI = pluginAPI;
for (const plugin of plugins) {
await plugin.setup(pluginAPI);
}
return pluginAPI;
};

test('should plugin-router-legacy defined', async () => {
expect(cliPlugin).toBeDefined();
});

it('plugin-router-legacy cli config is defined', async () => {
AppContext.set({ metaName: 'modern-js' } as any);
const config = await runner.config();
const api = await setup();
api.updateAppContext({ metaName: 'modern-js' } as any);
const config = await api.getHooks().config.call();
expect(
config.find(
(item: any) => item.source.alias['@modern-js/runtime/plugins'],
Expand Down
6 changes: 1 addition & 5 deletions packages/runtime/plugin-runtime/tests/document/cli.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import {
} from '@modern-js/plugin-v2';
import { createContext, initPluginAPI } from '@modern-js/plugin-v2/cli';

import type {
AppTools,
AppToolsContext,
AppToolsHooks,
} from '@modern-js/app-tools';
import type { AppTools, AppToolsContext } from '@modern-js/app-tools';
import { getBundleEntry } from '../../../../solutions/app-tools/src/plugins/analyze/getBundleEntry';
import { documentPlugin, getDocumenByEntryName } from '../../src/document/cli';

Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit dceb150

Please sign in to comment.