Skip to content
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
5 changes: 4 additions & 1 deletion packages/runtime/plugin-i18n/src/runtime/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ export const useModernI18n = (

// Use history API to navigate without page reload
window.history.pushState(null, '', newUrl);
} else if (updateLanguage) {
}

// Update language state after URL update
if (updateLanguage) {
updateLanguage(newLang);
}
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/alias-set/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('alias set build', () => {
const buildRes = await modernBuild(appDir);
expect(buildRes.code === 0).toBe(true);
expect(existsSync('route.json')).toBe(true);
expect(existsSync('html/main/index.html')).toBe(true);
expect(existsSync('html/index/index.html')).toBe(true);
});
});

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/asset-prefix/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('asset prefix', () => {
});
test(`should generate assetPrefix correctly when dev.assetPrefix is true`, async () => {
const HTML = readFileSync(
path.join(appDir, 'dist/html/main/index.html'),
path.join(appDir, 'dist/html/index/index.html'),
'utf-8',
);
expect(
Expand All @@ -47,7 +47,7 @@ describe('asset prefix', () => {
const expected = `http://${DEFAULT_DEV_HOST}:${appPort}`;

const mainJs = readFileSync(
path.join(appDir, 'dist/static/js/main.js'),
path.join(appDir, 'dist/static/js/index.js'),
'utf-8',
);

Expand Down
6 changes: 3 additions & 3 deletions tests/integration/async-entry/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ describe('generate async entry', () => {

expect(
readFileSync(
path.resolve(appDir, `node_modules/.modern-js/main/index.jsx`),
path.resolve(appDir, `node_modules/.modern-js/index/index.jsx`),
'utf8',
),
).toContain(`import { createRoot } from '@modern-js/runtime/react';`);

expect(
readFileSync(
path.resolve(appDir, `node_modules/.modern-js/main/bootstrap.jsx`),
path.resolve(appDir, `node_modules/.modern-js/index/bootstrap.jsx`),
'utf8',
),
).toContain(`import(/* webpackChunkName: "async-main" */ './index');`);
).toContain(`import(/* webpackChunkName: "async-index" */ './index');`);
});
});
2 changes: 1 addition & 1 deletion tests/integration/basic-app/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('test build', () => {
test(`should get right alias build!`, async () => {
expect(buildRes.code === 0).toBe(true);
expect(existsSync('route.json')).toBe(true);
expect(existsSync('html/main/index.html')).toBe(true);
expect(existsSync('html/index/index.html')).toBe(true);
});

test('should visit page correctly', async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/clean-dist-path/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('clean dist path', () => {
test(`should not clean dist path when output.cleanDistPath is false`, async () => {
const appDir = path.resolve(__dirname, '..');
const tempFile = path.join(appDir, 'dist/foo.txt');
const htmlFile = path.join(appDir, 'dist/html/main/index.html');
const htmlFile = path.join(appDir, 'dist/html/index/index.html');
fs.outputFileSync(tempFile, 'foo');
await modernBuild(appDir);
expect(fs.existsSync(tempFile)).toBeTruthy();
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/compatibility/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ function existsSync(filePath: string) {
test('should generate es5 artifact and pass check syntax by default', async () => {
const appDir = path.resolve(__dirname, '..');
await modernBuild(appDir);
expect(existsSync('html/main/index.html')).toBeTruthy();
expect(existsSync('static/js/main.js')).toBeTruthy();
expect(existsSync('html/index/index.html')).toBeTruthy();
expect(existsSync('static/js/index.js')).toBeTruthy();
});
2 changes: 1 addition & 1 deletion tests/integration/custom-dist-path/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test(`should allow distPath.root to be an absolute path`, async () => {

const distPath = path.join(appDir, 'dist/foo');
const configFile = path.join(distPath, OUTPUT_CONFIG_FILE);
const htmlFile = path.join(distPath, 'html/main/index.html');
const htmlFile = path.join(distPath, 'html/index/index.html');
expect(fs.existsSync(configFile)).toBeTruthy();
expect(fs.existsSync(htmlFile)).toBeTruthy();
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`custom template should allow to custom template by html.template option 1`] = `"<!doctype html><html><head><title>Hello World</title><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no,viewport-fit=cover,minimum-scale=1,maximum-scale=1,user-scalable=no"><meta http-equiv="x-ua-compatible" content="ie=edge"><meta name="renderer" content="webkit"><meta name="layoutmode" content="standard"><meta name="imagemode" content="force"><meta name="wap-font-scale" content="no"><meta name="format-detection" content="telephone=no"><script defer="defer" src="/static/js/main.js"></script></head><body><div id="root"></div></body></html>"`;
exports[`custom template should allow to custom template by html.template option 1`] = `"<!doctype html><html><head><title>Hello World</title><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no,viewport-fit=cover,minimum-scale=1,maximum-scale=1,user-scalable=no"><meta http-equiv="x-ua-compatible" content="ie=edge"><meta name="renderer" content="webkit"><meta name="layoutmode" content="standard"><meta name="imagemode" content="force"><meta name="wap-font-scale" content="no"><meta name="format-detection" content="telephone=no"><script defer="defer" src="/static/js/index.js"></script></head><body><div id="root"></div></body></html>"`;
2 changes: 1 addition & 1 deletion tests/integration/custom-template/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('custom template', () => {
await modernBuild(appDir);

expect(
readFileSync(path.resolve(appDir, `dist/html/main/index.html`), 'utf8'),
readFileSync(path.resolve(appDir, `dist/html/index/index.html`), 'utf8'),
).toMatchSnapshot();
});
});
2 changes: 1 addition & 1 deletion tests/integration/disable-html/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ test(`should not generate html files when tools.htmlPlugin is false`, async () =
await modernBuild(appDir);

expect(
existsSync(path.resolve(appDir, `dist/html/main/index.html`)),
existsSync(path.resolve(appDir, `dist/html/index/index.html`)),
).toBeFalsy();
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default defineConfig({
source: {
disableDefaultEntries: true,
entries: {
main: 'src/app-custom-entries/App.tsx',
index: 'src/app-custom-entries/App.tsx',
'entry-1': {
entry: 'src/entry-1/App.tsx',
customEntry: true,
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/i18n/app-ssr/tests/ssg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ describe('ssg', () => {
const appDir = projectDir;
await modernBuild(appDir, ['--config', 'modern.ssg.config.ts']);

const zhHtmlPath = path.join(appDir, './dist-ssg/html/main/zh/index.html');
const enHtmlPath = path.join(appDir, './dist-ssg/html/main/en/index.html');
const zhHtmlPath = path.join(appDir, './dist/html/index/zh/index.html');
const enHtmlPath = path.join(appDir, './dist/html/index/en/index.html');
const zhContent = fs.readFileSync(zhHtmlPath, 'utf-8');
const enContent = fs.readFileSync(enHtmlPath, 'utf-8');
expect(zhContent).toMatch('你好,世界');
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/i18n/routes-ssr/test/ssg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ describe('ssg', () => {

const zhAboutHtmlPath = path.join(
appDir,
'./dist-ssg/html/main/zh/about/index.html',
'./dist/html/index/zh/about/index.html',
);
const enAboutHtmlPath = path.join(
appDir,
'./dist-ssg/html/main/en/about/index.html',
'./dist/html/index/en/about/index.html',
);
const zhAboutContent = fs.readFileSync(zhAboutHtmlPath, 'utf-8');
const enAboutContent = fs.readFileSync(enAboutHtmlPath, 'utf-8');
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/image-component/modern.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default defineConfig({
router: true,
},
source: {
mainEntryName: 'main',
mainEntryName: 'index',
},
output: {
// disable polyfill and ts checker to make test faster
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/image-component/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe.skip('build', () => {
const buildRes = await modernBuild(appDir);
expect(buildRes.code === 0).toBe(true);
expect(existsSync('route.json')).toBe(true);
expect(existsSync('html/main/index.html')).toBe(true);
expect(existsSync('html/index/index.html')).toBe(true);

const pageName = resolveDist('static/js/async/page.js');
const pageContent = await fs.promises.readFile(pageName, 'utf-8');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('local config', () => {
await modernBuild(appDir);

expect(
existsSync(path.join(appDir, 'dist/foo/html/main/index.html')),
existsSync(path.join(appDir, 'dist/foo/html/index/index.html')),
).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ describe('basic local config', () => {
const appPort = await getPort();
const app = await launchApp(appDir, appPort);
expect(
existsSync(path.join(appDir, 'dist/bar/html/main/index.html')),
existsSync(path.join(appDir, 'dist/bar/html/index/index.html')),
).toBeTruthy();
await killApp(app);
});

test(`should not load local config when running build command`, async () => {
await modernBuild(appDir);
expect(
existsSync(path.join(appDir, 'dist/foo/html/main/index.html')),
existsSync(path.join(appDir, 'dist/foo/html/index/index.html')),
).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('local config', () => {
const app = await launchApp(appDir, appPort);

expect(
existsSync(path.join(appDir, 'dist/bar/html/main/index.html')),
existsSync(path.join(appDir, 'dist/bar/html/index/index.html')),
).toBeTruthy();
await killApp(app);
});
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/server-prod/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('test basic usage', () => {
expect(fs.existsSync(favicon1)).toBe(true);
expect(fs.existsSync(appIcon)).toBe(true);

const mainEntry = path.resolve(appPath, './dist/html/main/index.html');
const mainEntry = path.resolve(appPath, './dist/html/index/index.html');
const activityEntry = path.resolve(
appPath,
'./dist/html/activity/index.html',
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/server-routes/modern.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default applyBaseConfig({
},
server: {
routes: {
main: {
index: {
route: ['/a', '/b', '/main/:id'],
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default defineConfig({
},
output: {
ssgByEntries: {
main: {
index: {
routes: [
'/user',
{
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/ssg/tests/mega-list-routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ it('should render static mega list routes', async () => {

const ids = [0, 100, 9999];
for (const id of ids) {
const htmlPath = path.join(appDir, `dist/html/main/user/${id}/index.html`);
const htmlPath = path.join(appDir, `dist/html/index/user/${id}/index.html`);
const content = fs.readFileSync(htmlPath, 'utf-8');
expect(content).toContain(
`<div class="text-center" id="data">/user/${id}</div>`,
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/ssg/tests/nested-routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ describe('ssg', () => {
});

test('should nested-routes ssg access / work correctly', async () => {
const htmlPath = path.join(distDir, 'html/main/index.html');
const htmlPath = path.join(distDir, 'html/index/index.html');
const html = (await fs.readFile(htmlPath)).toString();
expect(html.includes('Hello, Home')).toBe(true);
});

test('should nested-routes ssg access /user work correctly', async () => {
const htmlPath = path.join(distDir, 'html/main/user/index.html');
const htmlPath = path.join(distDir, 'html/index/user/index.html');
const html = (await fs.readFile(htmlPath)).toString();
expect(html.includes('Hello, User')).toBe(true);
});

test('should nested-routes ssg access /user/1 work correctly with data loading', async () => {
const htmlPath = path.join(distDir, 'html/main/user/1/index.html');
const htmlPath = path.join(distDir, 'html/index/user/1/index.html');
const html = (await fs.readFile(htmlPath)).toString();
expect(html.includes('User 1: John Doe')).toBe(true);
expect(html.includes('User ID: <!-- -->1')).toBe(true);
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/ssg/tests/simple.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('ssg', () => {
const appDir = join(fixtureDir, 'simple');
await modernBuild(appDir);

const htmlPath = path.join(appDir, './dist/html/main/index.html');
const htmlPath = path.join(appDir, './dist/html/index/index.html');
const content = fs.readFileSync(htmlPath, 'utf-8');
expect(content).toMatch('Hello, Modern.js');
});
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/ssg/tests/web-server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('ssg', () => {
const appDir = join(fixtureDir, 'web-server');
await modernBuild(appDir);

const htmlPath = path.join(appDir, './dist/html/main/index.html');
const htmlPath = path.join(appDir, './dist/html/index/index.html');
const content = fs.readFileSync(htmlPath, 'utf-8');
expect(content).toMatch('Hello, Modern.js');
expect(content).toMatch('bytedance');
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/ssr/tests/base-async-entry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ describe('init with SSR', () => {
const loadableStats = fs.readJSONSync(
path.join(appDir, 'dist/loadable-stats.json'),
);
const chunks = loadableStats.namedChunkGroups['async-main'].assets;
const chunks = loadableStats.namedChunkGroups['async-index'].assets;
const urls: string[] = chunks.map((chunk: { name: string }) => {
return `/${chunk.name}`;
});
const existAssets = loadableStats.entrypoints.main.assets.map(
const existAssets = loadableStats.entrypoints.index.assets.map(
(asset: { name: string }) => `/${asset.name}`,
);

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/ssr/tests/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async function redirectInLoader(page: Page, appPort: number) {

async function checkIsPassChunkLoadingGlobal() {
const modernJsDir = join(fixtureDir, 'base', 'node_modules', '.modern-js');
const entryFilePath = join(modernJsDir, 'main', 'index.jsx');
const entryFilePath = join(modernJsDir, 'index', 'index.jsx');
const content = await fs.readFile(entryFilePath, 'utf-8');
expect(content).toMatch(/chunkLoadingGlobal/);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/temp-dir/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ describe('test temp-dir', () => {

test(`should get right alias build!`, async () => {
expect(buildRes.code === 0).toBe(true);
expect(existsSync('node_modules/.temp-dir/main')).toBe(true);
expect(existsSync('node_modules/.temp-dir/index')).toBe(true);
});
});
2 changes: 1 addition & 1 deletion tests/integration/write-to-dist/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ describe('test dev', () => {

test('should not get production in dist', async () => {
expect(existsSync('route.json')).toBeTruthy();
expect(existsSync('html/main/index.html')).toBeFalsy();
expect(existsSync('html/index/index.html')).toBeFalsy();
});
});