level_0
int64
0
10k
index
int64
0
0
repo_id
stringlengths
22
152
file_path
stringlengths
41
203
content
stringlengths
11
11.5M
957
0
petrpan-code/web-infra-dev/modern.js/tests/integration/bff-koa
petrpan-code/web-infra-dev/modern.js/tests/integration/bff-koa/tests/index.test.ts
import path from 'path'; import puppeteer, { Browser, Page } from 'puppeteer'; import { getPort, launchApp, killApp, modernBuild, modernServe, launchOptions, } from '../../../utils/modernTestUtils'; import 'isomorphic-fetch'; const appDir = path.resolve(__dirname, '../'); describe('bff koa in dev', () => { let port = 8080; const host = `http://localhost`; let app: any; let page: Page; let browser: Browser; beforeAll(async () => { jest.setTimeout(1000 * 60 * 2); port = await getPort(); app = await launchApp(appDir, port, {}); browser = await puppeteer.launch(launchOptions as any); page = await browser.newPage(); }); test('stream ssr with bff handle web', async () => { await page.goto(`${host}:${port}?name=bytedance`, { waitUntil: ['networkidle0'], }); const text = await page.$eval('#item', el => el?.textContent); expect(text).toMatch('name: bytedance, age: 18'); }); // TODO fix test.skip('stream ssr with bff handle web, client nav', async () => { await page.goto(`${host}:${port}/user`, { waitUntil: ['networkidle0'], }); await page.click('#home-btn'); await new Promise(resolve => setTimeout(resolve, 1000)); const text = await page.$eval('#item', el => el?.textContent); expect(text).toMatch('name: modernjs, age: 18'); }); afterAll(async () => { await killApp(app); await page.close(); await browser.close(); }); }); describe('bff express in prod', () => { let port = 8080; const host = `http://localhost`; let app: any; let page: Page; let browser: Browser; beforeAll(async () => { port = await getPort(); await modernBuild(appDir, [], {}); app = await modernServe(appDir, port, {}); browser = await puppeteer.launch(launchOptions as any); page = await browser.newPage(); }); test('stream ssr with bff handle web', async () => { await page.goto(`${host}:${port}?name=bytedance`, { waitUntil: ['networkidle0'], }); const text = await page.$eval('#item', el => el?.textContent); expect(text).toMatch('name: bytedance, age: 18'); }); // TODO fix test.skip('stream ssr with bff handle web, client nav', async () => { await page.goto(`${host}:${port}/user`, { waitUntil: ['networkidle0'], }); await page.click('#home-btn'); await new Promise(resolve => setTimeout(resolve, 1000)); const text = await page.$eval('#item', el => el?.textContent); expect(text).toMatch('name: modernjs, age: 18'); }); afterAll(async () => { await killApp(app); await page.close(); await browser.close(); }); });
963
0
petrpan-code/web-infra-dev/modern.js/tests/integration/builder-plugins
petrpan-code/web-infra-dev/modern.js/tests/integration/builder-plugins/tests/index.test.ts
import path from 'path'; import { readFileSync } from 'fs'; import { modernBuild } from '../../../utils/modernTestUtils'; const appDir = path.resolve(__dirname, '../'); describe('builder-plugins', () => { test(`should allow to register builder plugins`, async () => { await modernBuild(appDir); const log = readFileSync(path.join(appDir, 'dist/log'), 'utf-8'); expect(log).toEqual(`before create compiler before create compiler 2 after create compiler after create compiler 2 before build before build 2 after build after build 2`); }); });
969
0
petrpan-code/web-infra-dev/modern.js/tests/integration/clean-dist-path
petrpan-code/web-infra-dev/modern.js/tests/integration/clean-dist-path/tests/index.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { modernBuild } from '../../../utils/modernTestUtils'; 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'); fs.outputFileSync(tempFile, 'foo'); await modernBuild(appDir); expect(fs.existsSync(tempFile)).toBeTruthy(); expect(fs.existsSync(htmlFile)).toBeTruthy(); }); });
975
0
petrpan-code/web-infra-dev/modern.js/tests/integration/compatibility
petrpan-code/web-infra-dev/modern.js/tests/integration/compatibility/tests/index.test.ts
import fs from 'fs'; import path from 'path'; import { modernBuild } from '../../../utils/modernTestUtils'; const appDir = path.resolve(__dirname, '../'); function existsSync(filePath: string) { return fs.existsSync(path.join(appDir, 'dist', filePath)); } 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(); });
982
0
petrpan-code/web-infra-dev/modern.js/tests/integration/copy-assets
petrpan-code/web-infra-dev/modern.js/tests/integration/copy-assets/tests/index.test.ts
import path from 'path'; import { readFileSync } from 'fs'; import { modernBuild } from '../../../utils/modernTestUtils'; export async function testPublicHtml() { const appDir = path.resolve(__dirname, '..'); await modernBuild(appDir, undefined); const copiedHTML = readFileSync( path.join(appDir, `dist/public/demo.html`), 'utf-8', ); expect(copiedHTML).toMatchSnapshot(); } describe('copy assets', () => { test(`should copy public html and replace the assetPrefix variable in rspack`, async () => { await testPublicHtml(); }); });
984
0
petrpan-code/web-infra-dev/modern.js/tests/integration/copy-assets/tests
petrpan-code/web-infra-dev/modern.js/tests/integration/copy-assets/tests/__snapshots__/index.test.ts.snap
// Jest Snapshot v1, https://goo.gl/fbAQLP exports[`copy assets should copy public html and replace the assetPrefix variable in rspack 1`] = ` "<!DOCTYPE html> <html> <head> <script> window.__assetPrefix__ = 'https://demo.com'; window.__assetPrefix2__ = 'https://demo.com'; window.__assetPrefix3__ = 'https://demo.com'; </script> </head> </html> " `;
989
0
petrpan-code/web-infra-dev/modern.js/tests/integration/custom-dist-path
petrpan-code/web-infra-dev/modern.js/tests/integration/custom-dist-path/tests/index.test.ts
import path from 'path'; import { fs, OUTPUT_CONFIG_FILE } from '@modern-js/utils'; import { modernBuild } from '../../../utils/modernTestUtils'; test(`should allow distPath.root to be an absolute path`, async () => { const appDir = path.resolve(__dirname, '..'); await modernBuild(appDir); const distPath = path.join(appDir, 'dist/foo'); const configFile = path.join(distPath, OUTPUT_CONFIG_FILE); const htmlFile = path.join(distPath, 'html/main/index.html'); expect(fs.existsSync(configFile)).toBeTruthy(); expect(fs.existsSync(htmlFile)).toBeTruthy(); });
995
0
petrpan-code/web-infra-dev/modern.js/tests/integration/custom-render
petrpan-code/web-infra-dev/modern.js/tests/integration/custom-render/tests/index.test.ts
import path from 'path'; import puppeteer, { Browser, Page } from 'puppeteer'; import { getPort, killApp, launchApp, launchOptions, } from '../../../utils/modernTestUtils'; const appDir = path.resolve(__dirname, '../'); describe('custom render', () => { let app: any; let appPort: number; let page: Page; let browser: Browser; beforeAll(async () => { appPort = await getPort(); app = await launchApp(appDir, appPort, {}, {}); browser = await puppeteer.launch(launchOptions as any); page = await browser.newPage(); }); afterAll(async () => { await killApp(app); await page.close(); await browser.close(); }); test(`should add custom div correctly`, async () => { await page.goto(`http://localhost:${appPort}/test`, { waitUntil: ['networkidle0'], }); const root = await page.$('#csr'); const targetText = await page.evaluate(el => el?.textContent, root); expect(targetText?.trim()).toEqual('Custom Render'); }); });
1,001
0
petrpan-code/web-infra-dev/modern.js/tests/integration/custom-template
petrpan-code/web-infra-dev/modern.js/tests/integration/custom-template/tests/index.test.ts
import path from 'path'; import { readFileSync } from 'fs'; import { modernBuild } from '../../../utils/modernTestUtils'; describe('custom template', () => { test(`should allow to custom template by html.template option`, async () => { const appDir = path.resolve(__dirname, '..'); await modernBuild(appDir); expect( readFileSync(path.resolve(appDir, `dist/html/main/index.html`), 'utf8'), ).toMatchSnapshot(); }); });
1,002
0
petrpan-code/web-infra-dev/modern.js/tests/integration/custom-template/tests
petrpan-code/web-infra-dev/modern.js/tests/integration/custom-template/tests/__snapshots__/index.test.ts.snap
// 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><script defer="defer" src="/static/js/main.js"></script></head><body><div id="root"></div></body></html>"`;
1,007
0
petrpan-code/web-infra-dev/modern.js/tests/integration/dev-server
petrpan-code/web-infra-dev/modern.js/tests/integration/dev-server/tests/index.test.ts
import path from 'path'; import puppeteer, { Browser, Page } from 'puppeteer'; import { launchApp, killApp, getPort, launchOptions, } from '../../../utils/modernTestUtils'; const appDir = path.resolve(__dirname, '../'); describe('dev', () => { let app: unknown; let appPort: number; let page: Page; let browser: Browser; const errors: string[] = []; beforeAll(async () => { appPort = await getPort(); app = await launchApp(appDir, appPort, {}, {}); browser = await puppeteer.launch(launchOptions as any); page = await browser.newPage(); page.on('pageerror', error => { errors.push(error.message); }); }); test('should return response header set in before correctly', async () => { const response = await page.goto(`http://localhost:${appPort}`); const headers = response!.headers(); expect(headers['x-config']).toBe('test-config'); expect(headers['x-plugin']).toBe('test-plugin'); }); afterAll(async () => { await killApp(app); await page.close(); await browser.close(); }); });
1,025
0
petrpan-code/web-infra-dev/modern.js/tests/integration/devtools
petrpan-code/web-infra-dev/modern.js/tests/integration/devtools/tests/index.test.ts
import fs from 'fs'; import path from 'path'; import puppeteer from 'puppeteer'; import { launchApp, killApp, getPort, launchOptions, modernBuild, } from '../../../utils/modernTestUtils'; const appDir = path.resolve(__dirname, '../'); function existsSync(filePath: string) { return fs.existsSync(path.join(appDir, 'dist', filePath)); } describe.skip('devtools build', () => { test(`should get right devtools build!`, async () => { 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); }); }); describe.skip('devtools dev', () => { test(`should render page correctly`, async () => { const appPort = await getPort(); const app = await launchApp( appDir, appPort, {}, { // FIXME: disable the fast refresh plugin to avoid the `require` not found issue. FAST_REFRESH: 'false', }, ); const errors = []; const browser = await puppeteer.launch(launchOptions as any); const page = await browser.newPage(); page.on('pageerror', error => errors.push(error.message)); await page.goto(`http://localhost:${appPort}`, { waitUntil: ['networkidle0'], }); const root = await page.$('#root'); const targetText = await page.evaluate(el => el?.textContent, root); expect(targetText?.trim()).toEqual('Hello, Modern.js!'); expect(errors.length).toEqual(0); await browser.close(); await killApp(app); }); });
1,031
0
petrpan-code/web-infra-dev/modern.js/tests/integration/disable-html
petrpan-code/web-infra-dev/modern.js/tests/integration/disable-html/tests/index.test.ts
import path from 'path'; import { existsSync } from 'fs'; import { modernBuild } from '../../../utils/modernTestUtils'; test(`should not generate html files when tools.htmlPlugin is false`, async () => { const appDir = path.resolve(__dirname, '..'); await modernBuild(appDir); expect( existsSync(path.resolve(appDir, `dist/html/main/index.html`)), ).toBeFalsy(); });
1,038
0
petrpan-code/web-infra-dev/modern.js/tests/integration/esbuild
petrpan-code/web-infra-dev/modern.js/tests/integration/esbuild/tests/transform-and-minify.test.ts
import path from 'path'; import { readFileSync, rmdirSync, existsSync } from 'fs'; import { modernBuild } from '../../../utils/modernTestUtils'; import { fixtures, getJsFiles } from './utils'; describe('esbuild', () => { test(`should emitted script files correctly when using esbuild transform`, async () => { const appDir = path.resolve(fixtures, 'transform-and-minify'); if (existsSync(path.join(appDir, 'dist'))) { rmdirSync(path.join(appDir, 'dist'), { recursive: true }); } await modernBuild(appDir); const files = getJsFiles(appDir); const mainFile = files.filter(filepath => filepath.startsWith('main'))[0]; expect(files.length).toBe(3); expect( readFileSync(path.resolve(appDir, `dist/static/js/${mainFile}`), 'utf8'), ).toContain('children:"helloworld"'); }); });
1,057
0
petrpan-code/web-infra-dev/modern.js/tests/integration/load-config
petrpan-code/web-infra-dev/modern.js/tests/integration/load-config/tests/async-config-function.test.ts
import path from 'path'; import { existsSync } from 'fs'; import { modernBuild } from '../../../utils/modernTestUtils'; const fixtures = path.resolve(__dirname, '../fixtures'); describe('local config', () => { test(`should allow config file to export an async function`, async () => { const appDir = path.resolve(fixtures, 'async-config-function'); await modernBuild(appDir); expect( existsSync(path.join(appDir, 'dist/foo/html/main/index.html')), ).toBeTruthy(); }); });
1,058
0
petrpan-code/web-infra-dev/modern.js/tests/integration/load-config
petrpan-code/web-infra-dev/modern.js/tests/integration/load-config/tests/basic-local-config.test.ts
import path from 'path'; import { existsSync } from 'fs'; import { getPort, killApp, launchApp, modernBuild, } from '../../../utils/modernTestUtils'; const fixtures = path.resolve(__dirname, '../fixtures'); const appDir = path.resolve(fixtures, 'basic-local-config'); describe('basic local config', () => { test(`should load local config when running dev command`, async () => { const appPort = await getPort(); const app = await launchApp(appDir, appPort); expect( existsSync(path.join(appDir, 'dist/bar/html/main/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')), ).toBeTruthy(); }); });
1,059
0
petrpan-code/web-infra-dev/modern.js/tests/integration/load-config
petrpan-code/web-infra-dev/modern.js/tests/integration/load-config/tests/config-function-params.test.ts
import path from 'path'; import { readFileSync } from 'fs'; import { killApp, launchApp, modernBuild, } from '../../../utils/modernTestUtils'; const fixtures = path.resolve(__dirname, '../fixtures'); const appDir = path.resolve(fixtures, 'config-function-params'); describe('local config', () => { test(`should passing correct config params when running dev command`, async () => { const app = await launchApp(appDir); const rawParams = readFileSync( path.join(appDir, 'dist/params.json'), 'utf-8', ); expect(JSON.parse(rawParams)).toEqual({ env: 'development', command: 'dev', }); await killApp(app); }); test(`should passing correct config params when running build command`, async () => { await modernBuild(appDir); const rawParams = readFileSync( path.join(appDir, 'dist/params.json'), 'utf-8', ); expect(JSON.parse(rawParams)).toEqual({ env: 'production', command: 'build', }); }); });
1,060
0
petrpan-code/web-infra-dev/modern.js/tests/integration/load-config
petrpan-code/web-infra-dev/modern.js/tests/integration/load-config/tests/local-config-function.test.ts
import path from 'path'; import { existsSync } from 'fs'; import { getPort, killApp, launchApp } from '../../../utils/modernTestUtils'; describe('local config', () => { test(`should load local config in function format correctly`, async () => { const fixtures = path.resolve(__dirname, '../fixtures'); const appDir = path.resolve(fixtures, 'local-config-function'); const appPort = await getPort(); const app = await launchApp(appDir, appPort); expect( existsSync(path.join(appDir, 'dist/bar/html/main/index.html')), ).toBeTruthy(); await killApp(app); }); });
1,069
0
petrpan-code/web-infra-dev/modern.js/tests/integration/main-entry-name
petrpan-code/web-infra-dev/modern.js/tests/integration/main-entry-name/tests/index.test.ts
import fs from 'fs'; import path from 'path'; import puppeteer from 'puppeteer'; import { launchApp, killApp, getPort, modernBuild, launchOptions, } from '../../../utils/modernTestUtils'; const appDir = path.resolve(__dirname, '../'); function existsSync(filePath: string) { return fs.existsSync(path.join(appDir, 'dist', filePath)); } describe('test dev', () => { test(`should render page correctly`, async () => { const appPort = await getPort(); const app = await launchApp(appDir, appPort, {}, {}); const errors = []; const browser = await puppeteer.launch(launchOptions as any); const page = await browser.newPage(); page.on('pageerror', error => { errors.push(error.message); }); await page.goto(`http://localhost:${appPort}`, { waitUntil: ['networkidle0'], }); const root = await page.$('.description'); const targetText = await page.evaluate(el => el?.textContent, root); expect(targetText?.trim()).toEqual('Get started by editing src/App.tsx'); expect(errors.length).toEqual(0); await killApp(app); await page.close(); await browser.close(); }); }); describe('test build', () => { let buildRes: { code: number }; beforeAll(async () => { buildRes = await modernBuild(appDir); }); test(`should get right entry name build!`, async () => { expect(buildRes.code === 0).toBe(true); expect(existsSync('route.json')).toBe(true); expect(existsSync('html/index/index.html')).toBe(true); const html = fs.readFileSync( path.join(appDir, 'dist', 'html/index/index.html'), 'utf-8', ); expect(html).toContain('TikTok'); }); });
1,075
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/alias/alias.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../utils'; initBeforeTest(); describe('alias in js project', () => { const fixtureDir = path.join(__dirname, 'js'); it('object usage', async () => { const bundleConfigFile = path.join(fixtureDir, './object.config.ts'); const ret = await runCli({ argv: ['build'], configFile: bundleConfigFile, appDirectory: fixtureDir, }); expect(ret.success).toBe(true); const distFilePath = path.join(fixtureDir, './dist/object/index.js'); expect(fs.existsSync(distFilePath)).toBe(true); const content = fs.readFileSync(distFilePath, 'utf-8'); expect(content.includes('hello world')).toBe(true); }); it('function usage', async () => { const configFile = path.join(fixtureDir, './function.config.ts'); const ret = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); expect(ret.success).toBeTruthy(); const distFilePath = path.join(fixtureDir, './dist/function/index.js'); expect(fs.existsSync(distFilePath)).toBe(true); const content = fs.readFileSync(distFilePath, 'utf-8'); expect(content.includes('hello world')).toBe(true); }); }); describe('alias in ts project', () => { const fixtureDir = path.join(__dirname, 'ts'); it('object usage, buildType is bundle', async () => { const bundleConfigFile = path.join(fixtureDir, './object.config.ts'); const ret = await runCli({ argv: ['build'], configFile: bundleConfigFile, appDirectory: fixtureDir, }); expect(ret.success).toBeTruthy(); const distFilePath = path.join(fixtureDir, './dist/object/index.js'); expect(fs.existsSync(distFilePath)).toBe(true); const content = fs.readFileSync(distFilePath, 'utf-8'); expect(content.includes('hello world')).toBe(true); }); it('function usage', async () => { const configFile = path.join(fixtureDir, './function.config.ts'); await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); const distFilePath = path.join(fixtureDir, './dist/function/index.js'); expect(fs.existsSync(distFilePath)).toBe(true); const content = fs.readFileSync(distFilePath, 'utf-8'); expect(content.includes('hello world')).toBe(true); }); it('tsconfig path', async () => { await runCli({ argv: ['build'], appDirectory: fixtureDir, }); const distFilePath = path.join(fixtureDir, './dist/tsconfig/index.js'); expect(fs.existsSync(distFilePath)).toBe(true); const content = fs.readFileSync(distFilePath, 'utf-8'); expect(content.includes('hello world')).toBe(true); }); });
1,088
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/asset/asset.test.ts
import path from 'path'; import { fs, globby, slash } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../utils'; import { bundleDistPath, bundlelessDistPath } from '../../constants'; initBeforeTest(); describe('asset.path', () => { const fixtureDir = path.join(__dirname, 'path'); it('buildType is bundleless', async () => { const configFile = 'path.bundleless.config.ts'; const ret = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); expect(ret.success).toBeTruthy(); const distDir = path.join(fixtureDir, bundlelessDistPath); const distFilePath = path.join(distDir, './index.js'); const content = await fs.readFile(distFilePath, 'utf-8'); expect(content.includes('./asset/')).toBeTruthy(); }); it('buildType is bundle', async () => { const configFile = 'path.bundle.config.ts'; await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); const distDir = path.join(fixtureDir, bundleDistPath); const distFilePath = path.join(distDir, './index.js'); const content = await fs.readFile(distFilePath, 'utf-8'); expect(content.includes('data:image')).toBeTruthy(); const pngFileDirName = path.join(distDir, './asset'); const files = await globby(slash(`${pngFileDirName}/*.png`)); expect(files.length).toBe(0); }); }); describe('asset.svgr', () => { const fixtureDir = path.join(__dirname, 'svgr'); it('bundle', async () => { const configFile = 'bundle.config.ts'; const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); expect(success).toBeTruthy(); const distFilePath = path.join(fixtureDir, './dist/bundle/index.js'); const content = await fs.readFile(distFilePath, 'utf-8'); expect(content.includes(`jsx("svg"`)).toBeTruthy(); }); it('bundleless', async () => { const configFile = 'bundleless.config.ts'; const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); expect(success).toBeTruthy(); const distFilePath = path.join(fixtureDir, './dist/bundleless/logo.js'); expect(fs.existsSync(distFilePath)).toBeTruthy(); }); it('options with exclude', async () => { const configFile = 'exclude.config.ts'; const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); expect(success).toBeTruthy(); const distFilePath = path.join(fixtureDir, './dist/exclude/index.js'); const content = await fs.readFile(distFilePath, 'utf-8'); expect(content.includes(`data:image`)).toBeTruthy(); }); }); describe('asset.limit', () => { const fixtureDir = path.join(__dirname, 'limit'); it('limit is 0', async () => { await runCli({ argv: ['build'], appDirectory: fixtureDir, }); const distFilePath = path.join(fixtureDir, './dist/index.js'); const content = await fs.readFile(distFilePath, 'utf-8'); expect(content.includes(`import`)).toBeTruthy(); }); }); describe('asset.publicPath', () => { const fixtureDir = path.join(__dirname, 'publicPath'); it('have publicPath', async () => { await runCli({ argv: ['build'], appDirectory: fixtureDir, }); const distFilePath = path.join(fixtureDir, './dist/index.js'); const content = await fs.readFile(distFilePath, 'utf-8'); expect(content.includes(`/public/`)).toBeTruthy(); }); });
1,110
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/autoExtension
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/autoExtension/type-commonjs/type-commonjs.test.ts
import path from 'path'; import { globby, fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../../utils'; initBeforeTest(); describe('autoExtension', () => { const fixtureDir = __dirname; it('type:module', async () => { await runCli({ argv: ['build'], appDirectory: fixtureDir, enableDts: true, }); const cwd = path.join(fixtureDir, 'dist'); const outputDeclarationFile = await globby('*.d.mts', { cwd, }); const outputCjsFile = await globby('*.d.mts', { cwd, }); expect( outputDeclarationFile.length === 3 && outputCjsFile.length === 3, ).toBeTruthy(); const content = await fs.readFile(path.join(cwd, 'index.mjs'), 'utf-8'); expect(content.includes('./common.mjs')); }); });
1,116
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/autoExtension
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/autoExtension/type-module/type-module.test.ts
import path from 'path'; import { globby, fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../../utils'; initBeforeTest(); describe('autoExtension', () => { const fixtureDir = __dirname; it('type:module', async () => { await runCli({ argv: ['build'], appDirectory: fixtureDir, enableDts: true, }); const cwd = path.join(fixtureDir, 'dist'); const outputDeclarationFile = await globby('*.d.cts', { cwd, }); const outputCjsFile = await globby('*.d.cts', { cwd, }); expect( outputDeclarationFile.length === 3 && outputCjsFile.length === 3, ).toBeTruthy(); const content = await fs.readFile(path.join(cwd, 'index.cjs'), 'utf-8'); expect(content.includes('./common.cjs')); }); });
1,119
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/autoExternal/autoExternal.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../utils'; initBeforeTest(); describe('autoExternal usage', () => { const fixtureDir = __dirname; it('build success', async () => { const configFile = path.join(fixtureDir, './config.ts'); const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); expect(success).toBeTruthy(); }); it('autoExternal is false', async () => { const distFilePath = path.join(fixtureDir, './dist/1/index.js'); const content = await fs.readFile(distFilePath, 'utf-8'); expect(await fs.pathExists(distFilePath)).toBeTruthy(); expect(content.includes(`require("react")`)).toBeFalsy(); expect(content.includes(`require("postcss")`)).toBeFalsy(); expect(content.includes(`require("path-browserify")`)).toBeFalsy(); }); it('autoExternal is false with externals', async () => { const distFilePath = path.join(fixtureDir, './dist/2/index.js'); const content = await fs.readFile(distFilePath, 'utf-8'); expect(await fs.pathExists(distFilePath)).toBeTruthy(); expect(content.includes(`require("postcss")`)).toBeFalsy(); expect(content.includes(`require("path-browserify")`)).toBeFalsy(); }); it('autoExternal: { dependencies: true }', async () => { const distFilePath = path.join(fixtureDir, './dist/3/index.js'); const content = await fs.readFile(distFilePath, 'utf-8'); expect(await fs.pathExists(distFilePath)).toBeTruthy(); expect(content.includes(`require("react")`)).toBeFalsy(); expect(content.includes(`require("postcss")`)).toBeFalsy(); expect(content.includes(`require("path-browserify")`)).toBeTruthy(); }); it('autoExternal: { peerDependencies: true }', async () => { const distFilePath = path.join(fixtureDir, './dist/5/index.js'); const content = await fs.readFile(distFilePath, 'utf-8'); expect(await fs.pathExists(distFilePath)).toBeTruthy(); expect(content.includes(`require("react")`)).toBeFalsy(); expect(content.includes(`require("postcss")`)).toBeTruthy(); expect(content.includes(`require("path-browserify")`)).toBeFalsy(); }); });
1,124
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/banner-footer/banner.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../utils'; initBeforeTest(); describe('banner and footer', () => { const fixtureDir = __dirname; it('buildType is bundle', async () => { const configFile = path.join(fixtureDir, './bundle.config.ts'); await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, enableDts: true, }); const [js, css, dts] = await Promise.all([ fs.readFile(path.join(fixtureDir, 'dist/bundle/index.js'), 'utf8'), fs.readFile(path.join(fixtureDir, 'dist/bundle/index.css'), 'utf8'), fs.readFile(path.join(fixtureDir, 'dist/bundle/index.d.ts'), 'utf8'), ]); expect(js).toContain('js banner'); expect(js).toContain('js banner'); expect(css).toContain('css banner'); expect(css).toContain('css banner'); expect(dts).toContain('dts banner'); expect(dts).toContain('dts banner'); }); it('buildType is bundleless', async () => { const configFile = path.join(fixtureDir, './bundleless.config.ts'); await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, enableDts: true, }); const [js, css, dts] = await Promise.all([ fs.readFile(path.join(fixtureDir, 'dist/bundleless/index.js'), 'utf8'), fs.readFile(path.join(fixtureDir, 'dist/bundleless/index.css'), 'utf8'), fs.readFile(path.join(fixtureDir, 'dist/bundleless/index.d.ts'), 'utf8'), ]); expect(js).toContain('js footer'); expect(js).toContain('js footer'); expect(css).toContain('css footer'); expect(css).toContain('css footer'); expect(dts).toContain('dts footer'); expect(dts).toContain('dts footer'); }); });
1,131
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/buildType/buildType.test.ts
import path from 'path'; import { globby, slash } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../utils'; import { bundleDistPath, bundlelessDistPath } from '../../constants'; initBeforeTest(); describe('`buildType` case', () => { const fixtureDir = __dirname; it('buildType is bundle', async () => { const configFile = path.join(fixtureDir, './bundle.config.ts'); await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); const distFiles = await globby( slash(path.join(fixtureDir, bundleDistPath)), ); expect(distFiles.length).toBe(1); }); it('buildType is bundleless', async () => { const configFile = path.join(fixtureDir, './bundleless.config.ts'); await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); const distFiles = await globby( slash(path.join(fixtureDir, bundlelessDistPath)), ); expect(distFiles.length).toBe(2); }); });
1,138
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/copy/copy.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../utils'; initBeforeTest(); describe('copy usage', () => { const fixtureDir = __dirname; const configFile = path.join(fixtureDir, './config-1.ts'); it('build success', async () => { const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); expect(success).toBeTruthy(); }); it('copy file to file', async () => { const distFilePath = path.join(fixtureDir, './dist/temp-1/b.png'); const copyFileExist = await fs.pathExists(distFilePath); expect(copyFileExist).toBeTruthy(); }); it('copy file to dir', async () => { const distFilePath = path.join(fixtureDir, './dist/temp-2/a.png'); const copyFileExist = await fs.pathExists(distFilePath); expect(copyFileExist).toBeTruthy(); }); it('copy dir to dir', async () => { let distFilePath = path.join(fixtureDir, './dist/temp-3/a.png'); let copyFileExist = await fs.pathExists(distFilePath); expect(copyFileExist).toBeTruthy(); distFilePath = path.join(fixtureDir, './dist/temp-3/b.txt'); copyFileExist = await fs.pathExists(distFilePath); expect(copyFileExist).toBeTruthy(); }); it('copy dir to file', async () => { const distFilePath = path.join(fixtureDir, './dist/temp-4/_index.html'); const copyFileExist = await fs.pathExists(distFilePath); expect(copyFileExist).toBeTruthy(); }); it('copy glob to dir', async () => { const distFilePath = path.join(fixtureDir, './dist/temp-5/index.html'); const copyFileExist = await fs.pathExists(distFilePath); expect(copyFileExist).toBeTruthy(); }); it('copy glob to file', async () => { const distFilePath = path.join(fixtureDir, './dist/temp-6/index.html'); const copyFileExist = await fs.pathExists(distFilePath); expect(copyFileExist).toBeTruthy(); }); });
1,140
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/decorator/decorator.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../utils'; initBeforeTest(); describe('decorator', () => { const fixtureDir = __dirname; it('emitDecoratorMetadata', async () => { const configFile = path.join(fixtureDir, './modern.config.ts'); const { success, error } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); console.log(error); expect(success).toBeTruthy(); const distFilePath = path.join(fixtureDir, 'dist/main.js'); const content = await fs.readFile(distFilePath, 'utf-8'); expect(content).toMatchSnapshot(); }); });
1,143
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/decorator
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/decorator/__snapshots__/decorator.test.ts.snap
// Jest Snapshot v1, https://goo.gl/fbAQLP exports[`decorator emitDecoratorMetadata 1`] = ` ""use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var __decorateClass = (decorators, target, key, kind) => { var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target; for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result; if (kind && result) __defProp(target, key, result); return result; }; // src/index.ts var src_exports = {}; __export(src_exports, { Person: () => Person }); module.exports = __toCommonJS(src_exports); function enhancer(name) { return function enhancer2(target) { target.prototype.name = name; }; } var Person = class { constructor() { this.version = "1.0.0"; } }; Person = __decorateClass([ enhancer("module-tools") ], Person); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { Person }); " `;
1,145
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/define/define.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../utils'; import { bundleDistPath, bundlelessDistPath } from '../../constants'; initBeforeTest(); describe('envVars in js project', () => { const fixtureDir = path.join(__dirname, 'js'); it('buildType is bundle', async () => { const configFile = path.join(fixtureDir, './bundle.config.ts'); await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); const distFilePath = path.join(fixtureDir, bundleDistPath, './index.js'); expect(fs.existsSync(distFilePath)).toBe(true); const content = fs.readFileSync(distFilePath, 'utf-8'); expect(content.includes('1.0.1')).toBe(true); }); it('buildType is bundleless', async () => { const bundleConfigFile = path.join(fixtureDir, './bundleless.config.ts'); await runCli({ argv: ['build'], configFile: bundleConfigFile, appDirectory: fixtureDir, }); const distFilePath = path.join( fixtureDir, bundlelessDistPath, './index.js', ); expect(fs.existsSync(distFilePath)).toBe(true); const content = fs.readFileSync(distFilePath, 'utf-8'); expect(content.includes('1.0.1')).toBe(true); }); }); describe('envVars in ts project', () => { const fixtureDir = path.join(__dirname, 'ts'); it('buildType is bundle', async () => { const configFile = path.join(fixtureDir, './bundle.config.ts'); await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); const distFilePath = path.join(fixtureDir, bundleDistPath, './index.js'); expect(fs.existsSync(distFilePath)).toBe(true); const content = fs.readFileSync(distFilePath, 'utf-8'); expect(content.includes('1.0.1')).toBe(true); }); it('buildType is bundleless', async () => { const configFile = path.join(fixtureDir, './bundleless.config.ts'); const ret = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); console.info(ret.error); expect(ret.success).toBe(true); const distFilePath = path.join( fixtureDir, bundlelessDistPath, './index.js', ); expect(fs.existsSync(distFilePath)).toBe(true); const content = fs.readFileSync(distFilePath, 'utf-8'); expect(content.includes('1.0.1')).toBe(true); }); });
1,160
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/dts/dts.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../utils'; initBeforeTest(); beforeAll(() => { // MaxListenersExceededWarning, becasue of `createCli->init` in @modern-js/core require('events').EventEmitter.defaultMaxListeners = 15; }); afterAll(() => { require('events').EventEmitter.defaultMaxListeners = 10; }); const fixtureDir = __dirname; const enableDts = true; describe('dts is false', () => { it('buildType is bundle', async () => { const configFile = path.join(fixtureDir, './false-bundle.ts'); const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, enableDts, }); expect(success).toBeTruthy(); const distDtsFilePath = path.join( fixtureDir, './dist/false-bundle/index.d.ts', ); expect(await fs.pathExists(distDtsFilePath)).toBeFalsy(); }); it('buildType is bundleless', async () => { const configFile = path.join(fixtureDir, './false-bundleless.ts'); const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, enableDts, }); expect(success).toBeTruthy(); const distDtsFilePath = path.join( fixtureDir, './dist/false-bundleless/index.d.ts', ); expect(await fs.pathExists(distDtsFilePath)).toBeFalsy(); }); }); describe('dts.distPath', () => { it('buildType is bundle', async () => { const configFile = path.join(fixtureDir, './distPath-bundle.ts'); const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, enableDts, }); expect(success).toBeTruthy(); const distDtsFilePath = path.join( fixtureDir, './dist/bundle-dist-path/types/index.d.ts', ); expect(await fs.pathExists(distDtsFilePath)).toBeTruthy(); }); it('buildType is bundleless', async () => { const configFile = path.join(fixtureDir, './distPath-bundleless.ts'); const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, enableDts, }); expect(success).toBeTruthy(); let distDtsFilePath = path.join( fixtureDir, './dist/bundleless-dist-path/types/index.d.ts', ); expect(await fs.pathExists(distDtsFilePath)).toBeTruthy(); distDtsFilePath = path.join( fixtureDir, './dist/bundleless-dist-path/types/b.d.ts', ); expect(await fs.pathExists(distDtsFilePath)).toBeTruthy(); }); }); describe('dts.tsconfigPath', () => { it('buildType is bundle', async () => { const configFile = path.join(fixtureDir, './tsconfigPath-bundle.ts'); const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, enableDts, }); expect(success).toBeTruthy(); const distDtsFilePath = path.join( fixtureDir, './dist/tsconfig-path/bundle/index.d.ts', ); expect(await fs.pathExists(distDtsFilePath)).toBeTruthy(); }); it('buildType is bundleless', async () => { const configFile = path.join(fixtureDir, './tsconfigPath-bundleless.ts'); const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, enableDts, }); expect(success).toBeTruthy(); let distDtsFilePath = path.join( fixtureDir, './dist/tsconfig-path/bundleless/index.d.ts', ); expect(await fs.pathExists(distDtsFilePath)).toBeTruthy(); distDtsFilePath = path.join( fixtureDir, './dist/tsconfig-path/bundleless/b.d.ts', ); expect(await fs.pathExists(distDtsFilePath)).toBeTruthy(); }); }); describe('dts.only is true', () => { it('buildType is bundle', async () => { const configFile = path.join(fixtureDir, './only-bundle.ts'); const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, enableDts, }); expect(success).toBeTruthy(); let distDtsFilePath = path.join( fixtureDir, './dist/only-bundle/index.d.ts', ); expect(await fs.pathExists(distDtsFilePath)).toBeTruthy(); distDtsFilePath = path.join(fixtureDir, './dist/only-bundle/index.js'); expect(await fs.pathExists(distDtsFilePath)).toBeFalsy(); }); it('buildType is bundleless', async () => { const configFile = path.join(fixtureDir, './only-bundleless.ts'); const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, enableDts, }); expect(success).toBeTruthy(); let distDtsFilePath = path.join( fixtureDir, './dist/only-bundleless/index.d.ts', ); expect(await fs.pathExists(distDtsFilePath)).toBeTruthy(); distDtsFilePath = path.join(fixtureDir, './dist/only-bundleless/index.js'); expect(await fs.pathExists(distDtsFilePath)).toBeFalsy(); }); }); describe('dts.abortOnError is false', () => { it('buildType is bundle', async () => { const configFile = path.join(fixtureDir, './abortOnError-bundle.ts'); const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, enableDts, }); expect(success).toBeTruthy(); }); it('buildType is bundleless', async () => { const configFile = path.join(fixtureDir, './abortOnError-bundleless.ts'); const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, enableDts, }); expect(success).toBeTruthy(); }); });
1,179
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/esbuildOptions/esbuildOptions.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../utils'; initBeforeTest(); describe('esbuild format is esm', () => { const fixtureDir = __dirname; it('buildType is bundle', async () => { const configFile = path.join(fixtureDir, './modern.config.ts'); await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); const distFilePath = path.join(fixtureDir, './dist/index.js'); const content = await fs.readFile(distFilePath, 'utf-8'); expect(content.includes('module.exports')).toBe(true); }); });
1,184
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/externals/externals.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../utils'; initBeforeTest(); describe('externals usage', () => { const fixtureDir = __dirname; it('externals is string[] or RegExp[]', async () => { const configFile = path.join(fixtureDir, './config.ts'); const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); expect(success).toBeTruthy(); let distFilePath = path.join(fixtureDir, './dist/string/index.js'); let content = await fs.readFile(distFilePath, 'utf-8'); expect(await fs.pathExists(distFilePath)).toBeTruthy(); expect(content.includes(`require("react")`)).toBeTruthy(); distFilePath = path.join(fixtureDir, './dist/regexp/index.js'); content = await fs.readFile(distFilePath, 'utf-8'); expect(await fs.pathExists(distFilePath)).toBeTruthy(); expect(content.includes(`require("react")`)).toBeTruthy(); }); });
1,192
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/format/format.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { bundleDistPath, bundlelessDistPath, REQUIRE_REGEX, IMPORT_FROM_REGEX, IIFE_REGEX, } from '../../constants'; import { runCli, initBeforeTest } from '../../utils'; initBeforeTest(); const configDir = __dirname; describe('format is esm', () => { const fixtureDir = path.join(__dirname, 'esm'); it('buildType is bundle', async () => { const configFile = path.join(configDir, './esm-bundle.config.ts'); await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); const distFilePath = path.join(fixtureDir, bundleDistPath, './index.js'); const content = await fs.readFile(distFilePath, 'utf-8'); expect(content.includes('export default')).toBe(true); expect(REQUIRE_REGEX.test(content)).toBe(false); expect(content).toMatchSnapshot(); }); it('buildType is bundleless', async () => { const configFile = path.join(configDir, './esm-bundleless.config.ts'); const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); expect(success).toBe(true); const distIndexPath = path.join( fixtureDir, bundlelessDistPath, './index.js', ); const content1 = await fs.readFile(distIndexPath, 'utf-8'); expect(content1.includes('export default')).toBe(true); // expect(REQUIRE_REG.test(content1)).toBe(false); expect(content1).toMatchSnapshot(); const distUtilsPath = path.join( fixtureDir, bundlelessDistPath, './utils.js', ); const content2 = await fs.readFile(distUtilsPath, 'utf-8'); expect(content2.includes('export default')).toBe(true); expect(REQUIRE_REGEX.test(content2)).toBe(false); expect(content2).toMatchSnapshot(); }); }); describe('format is cjs', () => { const fixtureDir = path.join(__dirname, 'cjs'); it('buildType is bundle', async () => { const configFile = path.join(configDir, './cjs-bundle.config.ts'); await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); const distFilePath = path.join(fixtureDir, bundleDistPath, './index.js'); const content = await fs.readFile(distFilePath, 'utf-8'); expect(content.includes('module.exports')).toBe(true); expect(content).toMatchSnapshot(); }); it('buildType is bundleless', async () => { const configFile = path.join(configDir, './cjs-bundleless.config.ts'); await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); const distIndexPath = path.join( fixtureDir, bundlelessDistPath, './index.js', ); const content1 = await fs.readFile(distIndexPath, 'utf-8'); // TODO check use swc to transform // expect( // content1.includes('Object.defineProperty(exports, "__esModule", {'), // ).toBe(true); expect(IMPORT_FROM_REGEX.test(content1)).toBe(false); expect(content1).toMatchSnapshot(); const distUtilsPath = path.join( fixtureDir, bundlelessDistPath, './utils.js', ); const content2 = await fs.readFile(distUtilsPath, 'utf-8'); // expect( // content2.includes('Object.defineProperty(exports, "__esModule", {'), // ).toBe(true); expect(IMPORT_FROM_REGEX.test(content2)).toBe(false); expect(content2).toMatchSnapshot(); }); }); describe('format is umd', () => { const fixtureDir = path.join(__dirname, 'umd'); it('buildType is bundle', async () => { const configFile = path.join(configDir, './umd-bundle.config.ts'); await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); const distFilePath = path.join(fixtureDir, bundleDistPath, './index.js'); const content = await fs.readFile(distFilePath, 'utf-8'); expect(content.includes('(function(global, factory) {')).toBe(true); expect(content).toMatchSnapshot(); }); it('buildType is bundleless', async () => { const configFile = path.join(configDir, './umd-bundleless.config.ts'); const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); expect(success).toBeFalsy(); }); }); describe('format is iife', () => { const fixtureDir = path.join(__dirname, 'iife'); it('buildType is bundle', async () => { const configFile = path.join(configDir, './iife-bundle.config.ts'); await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); const distFilePath = path.join(fixtureDir, bundleDistPath, './index.js'); const content = await fs.readFile(distFilePath, 'utf-8'); expect(IIFE_REGEX.test(content)).toBe(true); expect(content).toMatchSnapshot(); }); it('buildType is bundleless', async () => { const configFile = path.join(configDir, './iife-bundleless.config.ts'); const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); expect(success).toBeFalsy(); }); });
1,197
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/format
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/format/__snapshots__/format.test.ts.snap
// Jest Snapshot v1, https://goo.gl/fbAQLP exports[`format is cjs buildType is bundle 1`] = ` "var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.js var src_exports = {}; __export(src_exports, { default: () => src_default }); module.exports = __toCommonJS(src_exports); // src/utils.js var addPrefix = (prefix, str) => \`\${prefix}\${str}\`; // src/index.js var src_default = (str) => addPrefix("DEBUG:", str); " `; exports[`format is cjs buildType is bundleless 1`] = ` "var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var src_exports = {}; __export(src_exports, { default: () => src_default }); module.exports = __toCommonJS(src_exports); var import_utils = require("./utils"); var src_default = (str) => (0, import_utils.addPrefix)("DEBUG:", str); " `; exports[`format is cjs buildType is bundleless 2`] = ` "var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var utils_exports = {}; __export(utils_exports, { addPrefix: () => addPrefix }); module.exports = __toCommonJS(utils_exports); const addPrefix = (prefix, str) => \`\${prefix}\${str}\`; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { addPrefix }); " `; exports[`format is esm buildType is bundle 1`] = ` "var __getOwnPropNames = Object.getOwnPropertyNames; var __commonJS = function(cb, mod) { return function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; }; // src/utils.js var require_utils = __commonJS({ "src/utils.js": function(exports, module) { var addPrefix = function(prefix, str) { return "".concat(prefix).concat(str); }; module.exports = { addPrefix: addPrefix }; } }); // src/index.js var require_src = __commonJS({ "src/index.js": function(exports, module) { var addPrefix = require_utils().addPrefix; module.exports = function(str) { return addPrefix("DEBUG:", str); }; } }); export default require_src(); " `; exports[`format is esm buildType is bundleless 1`] = ` "var __getOwnPropNames = Object.getOwnPropertyNames; var __commonJS = function(cb, mod) { return function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; }; var require_src = __commonJS({ "src/index.js": function(exports, module) { var addPrefix = require("./utils").addPrefix; module.exports = function(str) { return addPrefix("DEBUG:", str); }; } }); export default require_src(); " `; exports[`format is esm buildType is bundleless 2`] = ` "var __getOwnPropNames = Object.getOwnPropertyNames; var __commonJS = function(cb, mod) { return function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; }; var require_utils = __commonJS({ "src/utils.js": function(exports, module) { var addPrefix = function(prefix, str) { return "".concat(prefix).concat(str); }; module.exports = { addPrefix: addPrefix }; } }); export default require_utils(); " `; exports[`format is iife buildType is bundle 1`] = ` "(() => { var __getOwnPropNames = Object.getOwnPropertyNames; var __commonJS = (cb, mod) => function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; // src/utils.js var require_utils = __commonJS({ "src/utils.js"(exports, module) { var addPrefix = (prefix, str) => \`\${prefix}\${str}\`; module.exports = { addPrefix }; } }); // src/index.js var require_src = __commonJS({ "src/index.js"(exports, module) { var { addPrefix } = require_utils(); module.exports = (str) => addPrefix("DEBUG:", str); } }); require_src(); })(); " `; exports[`format is umd buildType is bundle 1`] = ` "(function(global, factory) { if (typeof module === "object" && typeof module.exports === "object") factory(exports); else if (typeof define === "function" && define.amd) define([ "exports" ], factory); else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.index = {}); })(this, function(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "default", { enumerable: true, get: function() { return _default; } }); var __getOwnPropNames = Object.getOwnPropertyNames; var __commonJS = (cb, mod)=>function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; // src/utils.js var require_utils = __commonJS({ "src/utils.js" (exports, module1) { var addPrefix = (prefix, str)=>\`\${prefix}\${str}\`; module1.exports = { addPrefix }; } }); // src/index.js var require_src = __commonJS({ "src/index.js" (exports, module1) { var { addPrefix } = require_utils(); module1.exports = (str)=>addPrefix("DEBUG:", str); } }); const _default = require_src(); }); " `;
1,211
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/input/input.test.ts
import path from 'path'; import { fs, globby, slash } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../utils'; initBeforeTest(); const fixtureDir = __dirname; describe('input usage', () => { it('entry is object', async () => { const configFile = path.join(fixtureDir, './object.ts'); const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); expect(success).toBeTruthy(); const distFilePath = path.join(fixtureDir, './dist/object/main.js'); expect(await fs.pathExists(distFilePath)).toBeTruthy(); }); it('entry is array', async () => { const configFile = path.join(fixtureDir, './array.ts'); const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); expect(success).toBeTruthy(); const distFilePath = path.join(fixtureDir, './dist/array/index.js'); expect(await fs.pathExists(distFilePath)).toBeTruthy(); const distBrowserFilePath = path.join( fixtureDir, './dist/array/browser.js', ); expect(await fs.pathExists(distBrowserFilePath)).toBeTruthy(); }); }); describe('input filter', () => { it('build success', async () => { const configFile = path.join(fixtureDir, './modern.config.ts'); const ret = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); expect(ret.success).toBeTruthy(); }); it('filter *.a.ts:pattern 1', async () => { const distPath = path.join(fixtureDir, './dist/pattern-1'); const distPattern = path.join(distPath, '*'); const files = await globby(slash(distPattern)); expect(files.length).toBe(3); }); it('filter *.a.ts:pattern 2', async () => { const distPath = path.posix.join(fixtureDir, './dist/pattern-2'); const distPattern = path.posix.join(distPath, '*'); const files = await globby(slash(distPattern)); expect(files.length).toBe(3); }); });
1,221
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/jsx/jsx.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../utils'; initBeforeTest(); const fixtureDir = __dirname; describe('jsx', () => { it('automatic', async () => { const configFile = path.join(fixtureDir, './automatic.config.ts'); const ret = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); expect(ret.success).toBeTruthy(); const distFilePath = path.join(fixtureDir, './dist/automatic/index.js'); const content = await fs.readFile(distFilePath, 'utf8'); expect(content.includes('react/jsx-runtime')).toBeTruthy(); }); it('transform', async () => { const configFile = path.join(fixtureDir, './transform.config.ts'); await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); const distFilePath = path.join(fixtureDir, './dist/transform/index.js'); const content = await fs.readFile(distFilePath, 'utf8'); expect(content.includes('React.createElement')).toBeTruthy(); }); it('preserve', async () => { const configFile = path.join(fixtureDir, './preserve.config.ts'); await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); const distFilePath = path.join(fixtureDir, './dist/preserve/index.js'); const content = await fs.readFile(distFilePath, 'utf8'); expect(content.includes('<div>')).toBeTruthy(); }); });
1,227
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/metafile/metafile.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../utils'; initBeforeTest(); describe('metafile', () => { const fixtureDir = __dirname; it('metafile is true', async () => { const configFile = path.join(fixtureDir, './config.ts'); const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); expect(success).toBeTruthy(); const distPath = path.join(fixtureDir, './dist'); expect(fs.readdirSync(distPath).length === 2).toBeTruthy(); }); });
1,232
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/minify/minify.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../utils'; initBeforeTest(); describe('minify usage', () => { const fixtureDir = __dirname; it('false, esbuild, terser', async () => { const configFile = path.join(fixtureDir, './config.ts'); const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); expect(success).toBeTruthy(); const distEsbuildFilePath = path.join( fixtureDir, './dist/esbuild/index.js', ); expect(await fs.pathExists(distEsbuildFilePath)).toBeTruthy(); const distTerserFilePath = path.join(fixtureDir, './dist/terser/index.js'); expect(await fs.pathExists(distTerserFilePath)).toBeTruthy(); const distFilePath = path.join(fixtureDir, './dist/false/index.js'); expect(await fs.pathExists(distFilePath)).toBeTruthy(); const contentByEsbuildMinify = await fs.readFile( distEsbuildFilePath, 'utf-8', ); const esbuildMinifyStat = fs.stat(distEsbuildFilePath); const contentByTerserMinify = await fs.readFile( distTerserFilePath, 'utf-8', ); const terserMinifyStat = fs.stat(distTerserFilePath); const stat = fs.stat(distFilePath); expect(contentByEsbuildMinify === contentByTerserMinify).not.toBeTruthy(); expect((await esbuildMinifyStat).size).toBeLessThan((await stat).size); expect((await terserMinifyStat).size).toBeLessThan((await stat).size); }); it('umd + terser', async () => { await runCli({ argv: ['build'], appDirectory: fixtureDir, }); const content = await fs.readFile( path.join(fixtureDir, './dist/umd/index.js'), 'utf-8', ); expect(content).toMatchSnapshot(); }); });
1,235
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/minify
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/minify/__snapshots__/minify.test.ts.snap
// Jest Snapshot v1, https://goo.gl/fbAQLP exports[`minify usage umd + terser 1`] = `"var e,t;e=this,t=function(e,t){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(e,"__esModule",{value:!0}),Object.defineProperty(e,"debug",{enumerable:!0,get:function(){return l}}),t=r(t);var n,o=Object.defineProperty,i=Object.getOwnPropertyNames,u={};((e,t)=>{for(var r in t)o(e,r,{get:t[r],enumerable:!0})})(u,{addPrefix:()=>n});var a,d,f=(a={"src/common.ts"(){n=(e,t)=>\`\${e}:\${t}\`}},function(){return a&&(d=(0,a[i(a)[0]])(a=0)),d}),l=e=>{return r=void 0,n=null,o=function*(){const{addPrefix:r}=yield Promise.resolve().then((()=>(f(),u)));r("DEBUG:",t.default.join(e))},new Promise(((e,t)=>{var i=e=>{try{a(o.next(e))}catch(r){t(r)}},u=e=>{try{a(o.throw(e))}catch(r){t(r)}},a=t=>t.done?e(t.value):Promise.resolve(t.value).then(i,u);a((o=o.apply(r,n)).next())}));var r,n,o}},"object"===typeof module&&"object"===typeof module.exports?t(exports,require("path")):"function"===typeof define&&define.amd?define(["exports","path"],t):(e="undefined"!==typeof globalThis?globalThis:e||self)&&t(e.index={},e.path);"`;
1,241
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/platform/platform.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../utils'; initBeforeTest(); describe('platform usage', () => { const fixtureDir = __dirname; // https://esbuild.github.io/api/#platform it('platform is node', async () => { const configFile = path.join(fixtureDir, './node.ts'); const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); expect(success).toBeTruthy(); const distFilePath = path.join(fixtureDir, './dist/node/index.js'); const content = await fs.readFile(distFilePath, 'utf-8'); expect(content.includes(`require("path")`)).toBeTruthy(); }); it('platform is browser', async () => { const configFile = path.join(fixtureDir, './browser.ts'); const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); expect(success).toBeTruthy(); const distFilePath = path.join(fixtureDir, './dist/browser/index.js'); const content = await fs.readFile(distFilePath, 'utf-8'); expect(content.includes(`path-browserify`)).toBeTruthy(); }); });
1,246
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/redirect/redirect.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../utils'; initBeforeTest(); describe('redirect', () => { const fixtureDir = __dirname; it('no-redirect', async () => { const configFile = path.join(fixtureDir, './no-redirect.ts'); await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); const distFilePath = path.join(fixtureDir, './dist/no-redirect/index.js'); const content = await fs.readFile(distFilePath, 'utf-8'); expect( content.includes(`import css from "./index.module.css"`), ).toBeTruthy(); }); it('redirect alias and style and asset', async () => { const configFile = path.join(fixtureDir, './redirect.ts'); await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); const distJsFilePath = path.join(fixtureDir, './dist/redirect/index.js'); const jsContent = await fs.readFile(distJsFilePath, 'utf-8'); // redirect alias expect(jsContent.includes(`@/alias`)).toBeFalsy(); // redirect autoExtension expect(jsContent.includes(`./extension.js`)).toBeTruthy(); // redirect style expect( jsContent.includes(`import css from "./index.module";`), ).toBeTruthy(); // redirect asset expect(jsContent.includes(`import svg from "./assets/logo`)).toBeTruthy(); const distJsonFilePath = path.join( fixtureDir, './dist/redirect/index.module.js', ); const distCssFilePath = path.join( fixtureDir, './dist/redirect/index_module.css', ); expect(fs.existsSync(distJsonFilePath)).toBeTruthy(); expect(fs.existsSync(distCssFilePath)).toBeTruthy(); }); });
1,254
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/resolve
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/resolve/data-url/dataurl.test.ts
import { runCli, initBeforeTest } from '../../../utils'; initBeforeTest(); describe('resolve', () => { const fixtureDir = __dirname; it('data-url', async () => { const { success } = await runCli({ argv: ['build'], appDirectory: fixtureDir, }); expect(success).toBeTruthy(); }); });
1,258
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/resolve
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/resolve/false/false.test.ts
import { runCli, initBeforeTest } from '../../../utils'; initBeforeTest(); describe('resolve', () => { const fixtureDir = __dirname; it('false', async () => { const { success } = await runCli({ argv: ['build'], appDirectory: fixtureDir, }); expect(success).toBeTruthy(); }); });
1,266
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/resolve
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/resolve/node-protocol/protocol.test.ts
import { runCli, initBeforeTest } from '../../../utils'; initBeforeTest(); describe('resolve', () => { const fixtureDir = __dirname; it('node-protocol', async () => { const { success } = await runCli({ argv: ['build'], appDirectory: fixtureDir, }); expect(success).toBeTruthy(); }); });
1,274
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/resolve
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/resolve/with-condition-exports/resolve-with-condition-exports.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../../utils'; initBeforeTest(); describe('resovle', () => { const fixtureDir = __dirname; it('with-condition-exports: browser', async () => { const { success } = await runCli({ argv: ['build'], appDirectory: fixtureDir, }); expect(success).toBeTruthy(); const outDir = path.join(fixtureDir, 'dist/browser'); const entry1 = path.join(outDir, 'entry1.js'); const entry2 = path.join(outDir, 'entry2.js'); const entry3 = path.join(outDir, 'entry3.js'); const entry4 = path.join(outDir, 'entry4.js'); const content1 = await fs.readFile(entry1, 'utf-8'); const content2 = await fs.readFile(entry2, 'utf-8'); const content3 = await fs.readFile(entry3, 'utf-8'); const content4 = await fs.readFile(entry4, 'utf-8'); // import expect(content1).toContain('lib1 mjs'); // module expect(content2).toContain('lib2 module'); expect(content3).toContain('browser'); // require expect(content4).toContain('lib1 cjs'); }); it('with-condition-exports: node', async () => { const { success } = await runCli({ argv: ['build'], appDirectory: fixtureDir, configFile: 'modern-node.config.ts', }); expect(success).toBeTruthy(); const outDir = path.join(fixtureDir, 'dist/node'); const entry3 = path.join(outDir, 'entry3.js'); const content3 = await fs.readFile(entry3, 'utf-8'); expect(content3).toContain('node'); }); });
1,289
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/resolve
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/resolve/with-js-extensions/resolve-with-js-extensions.test.ts
import { runCli, initBeforeTest } from '../../../utils'; initBeforeTest(); describe('resovle', () => { const fixtureDir = __dirname; it('with-condition-exports', async () => { const { success } = await runCli({ argv: ['build'], appDirectory: fixtureDir, }); expect(success).toBeTruthy(); }); });
1,294
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/resolve
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/resolve/with-mainFields/resolve-with-mainFields.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../../utils'; initBeforeTest(); describe('resovle', () => { const fixtureDir = __dirname; it('with-condition-exports', async () => { const { success } = await runCli({ argv: ['build'], appDirectory: fixtureDir, }); expect(success).toBeTruthy(); const browserContent = fs.readFileSync( path.join(__dirname, 'dist/browser/entry2.js'), 'utf8', ); expect(browserContent).toContain('browser'); const nodeContent = fs.readFileSync( path.join(__dirname, 'dist/node/entry2.js'), 'utf8', ); expect(nodeContent).toContain('main'); }); });
1,302
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/shims/shims.test.ts
import path from 'path'; import { execa } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../utils'; initBeforeTest(); describe('shims', () => { const fixtureDir = __dirname; it('shims', async () => { const { success } = await runCli({ argv: ['build'], appDirectory: fixtureDir, }); expect(success).toBeTruthy(); const cjs_bundle_path = path.join(fixtureDir, 'dist/cjs/bundle.js'); const cjs_bundleless_path = path.join(fixtureDir, 'dist/cjs/index.js'); const esm_bundle_path = path.join(fixtureDir, 'dist/esm/bundle.mjs'); const esm_bundleless_path = path.join(fixtureDir, 'dist/esm/index.mjs'); const { command } = execa; const output = await Promise.all([ command(`node ${cjs_bundle_path}`), command(`node ${cjs_bundleless_path}`), command(`node ${esm_bundle_path}`), command(`node ${esm_bundleless_path}`), ]); expect(output.every(o => !o.failed)).toBeTruthy(); }); });
1,310
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/sideEffects/sideEffects.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../utils'; initBeforeTest(); describe('sideEffects', () => { const fixtureDir = __dirname; it('base usage', async () => { await runCli({ argv: ['build'], appDirectory: fixtureDir, }); const distIndexPath = path.join(fixtureDir, './dist/index.js'); expect( (await fs.readFile(distIndexPath, 'utf-8')).length === 0, ).toBeTruthy(); const distLibPath = path.join(fixtureDir, './dist/index.js'); expect((await fs.readFile(distLibPath, 'utf-8')).length === 0).toBeTruthy(); }); });
1,316
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/sourceDir/sourceDir.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../utils'; initBeforeTest(); describe('sourceDir', () => { const fixtureDir = __dirname; it('base usage', async () => { const configFile = path.join(fixtureDir, './config.ts'); const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); expect(success).toBeTruthy(); const distIndexPath = path.join(fixtureDir, './dist/index.js'); const distBrowserPath = path.join(fixtureDir, './dist/browser.js'); const distCommonPath = path.join(fixtureDir, './dist/common.js'); expect(await fs.pathExists(distIndexPath)).toBeTruthy(); expect(await fs.pathExists(distBrowserPath)).toBeTruthy(); expect(await fs.pathExists(distCommonPath)).toBeTruthy(); }); });
1,324
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/sourceMap/sourceMap.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../utils'; initBeforeTest(); describe('sourcemap usage', () => { const fixtureDir = __dirname; it('sourcemap is true', async () => { const configFile = path.join(fixtureDir, './true.ts'); await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); const distSourceMapFilePath = path.join( fixtureDir, './dist/true/index.js.map', ); expect(await fs.pathExists(distSourceMapFilePath)).toBe(true); const content = fs.readFileSync(distSourceMapFilePath, 'utf-8'); expect(JSON.parse(content)).toMatchSnapshot(); }); it('sourcemap with swc', async () => { const configFile = path.join(fixtureDir, './swc.ts'); await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); const distSourceMapFilePath = path.join( fixtureDir, './dist/swc/index.js.map', ); expect(await fs.pathExists(distSourceMapFilePath)).toBe(true); const content = fs.readFileSync(distSourceMapFilePath, 'utf-8'); const map = JSON.parse(content); expect(map).toMatchSnapshot(); expect(map.sources[0]).toBe('../../src/index.js'); }); it('sourcemap is false', async () => { const configFile = path.join(fixtureDir, './false.ts'); await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); const distSourceMapFilePath = path.join( fixtureDir, './dist/false/index.js.map', ); expect(await fs.pathExists(distSourceMapFilePath)).toBe(false); }); it('sourcemap is inline', async () => { const configFile = path.join(fixtureDir, './inline.ts'); await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); const distFilePath = path.join(fixtureDir, './dist/inline/index.js'); const distSourceMapFilePath = path.join( fixtureDir, './dist/inline/index.js.map', ); expect(await fs.pathExists(distSourceMapFilePath)).toBe(false); const content = fs.readFileSync(distFilePath, 'utf-8'); expect( content.includes('sourceMappingURL=data:application/json;'), ).toBeTruthy(); }); it('sourcemap is external', async () => { const configFile = path.join(fixtureDir, './external.ts'); await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); const distSourceMapFilePath = path.join( fixtureDir, './dist/external/index.js.map', ); expect(await fs.pathExists(distSourceMapFilePath)).toBe(true); const content = fs.readFileSync(distSourceMapFilePath, 'utf-8'); expect(JSON.parse(content)).toMatchSnapshot(); }); });
1,327
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/sourceMap
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/sourceMap/__snapshots__/sourceMap.test.ts.snap
// Jest Snapshot v1, https://goo.gl/fbAQLP exports[`sourcemap usage sourcemap is external 1`] = ` { "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,YAAY,CAAC,QAAQ,QAAQ,GAAG,MAAM,IAAI,GAAG;;;ADEnD,IAAM,QAAQ,SAAO,UAAU,UAAU,GAAG;", "names": [], "sources": [ "../../src/index.js", "../../src/utils.js", ], "sourcesContent": [ "import { addPrefix } from './utils'; export const debug = str => addPrefix('DEBUG:', str); ", "export const addPrefix = (prefix, str) => \`\${prefix}:\${str}\`; ", ], "version": 3, } `; exports[`sourcemap usage sourcemap is true 1`] = ` { "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,YAAY,CAAC,QAAQ,QAAQ,GAAG,MAAM,IAAI,GAAG;;;ADEnD,IAAM,QAAQ,SAAO,UAAU,UAAU,GAAG;", "names": [], "sources": [ "../../src/index.js", "../../src/utils.js", ], "sourcesContent": [ "import { addPrefix } from './utils'; export const debug = str => addPrefix('DEBUG:', str); ", "export const addPrefix = (prefix, str) => \`\${prefix}:\${str}\`; ", ], "version": 3, } `; exports[`sourcemap usage sourcemap with swc 1`] = ` { "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAO,IAAMA,YAAY,CAACC,QAAQC,QAAQ,GAAGD,UAAUC;;;ADEhD,IAAMC,QAAQD,SAAOF,UAAU,UAAUE;", "names": [ "addPrefix", "prefix", "str", "debug", ], "sources": [ "../../src/index.js", "../../src/utils.js", ], "sourcesContent": [ "import { addPrefix } from './utils'; export const debug = str => addPrefix('DEBUG:', str); ", "export const addPrefix = (prefix, str) => \`\${prefix}:\${str}\`; ", ], "version": 3, } `;
1,333
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/splitting/splitting.test.ts
import path from 'path'; import { fastGlob } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../utils'; initBeforeTest(); beforeAll(() => { jest.setTimeout(30000); }); describe('splitting usage', () => { const fixtureDir = __dirname; // https://esbuild.github.io/api/#splitting it('splitting is true', async () => { const configFile = path.join(fixtureDir, './config.ts'); const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); expect(success).toBeTruthy(); const files = await fastGlob('dist/*', { cwd: fixtureDir, }); expect(files.length === 3).toBeTruthy(); }); it('cjs splitting', async () => { const configFile = path.join(fixtureDir, './config.ts'); const { success } = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); expect(success).toBeTruthy(); }); });
1,337
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/style
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/style/css/import.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../../utils'; initBeforeTest(); describe('css', () => { const appDirectory = __dirname; it('all', async () => { const { success } = await runCli({ argv: ['build'], appDirectory, }); expect(success).toBeTruthy(); }); });
1,344
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/style
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/style/less/less.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../../utils'; initBeforeTest(); describe('less', () => { const appDirectory = __dirname; it('options usage', async () => { await runCli({ argv: ['build'], appDirectory, }); const distFilePath = path.join(appDirectory, './dist/options/index.css'); const content = await fs.readFile(distFilePath, 'utf-8'); expect( content.includes(`5px`) && content.includes(`rgba(198, 83, 140, 0.88)`), ).toBeTruthy(); }); it('import', async () => { const { success, error } = await runCli({ argv: ['build'], appDirectory, configFile: 'import.config.ts', }); console.log(error); expect(success).toBeTruthy(); }); });
1,362
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/style
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/style/others/style.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../../utils'; initBeforeTest(); describe('style', () => { const fixtureDir = __dirname; it('inject and modules and autoModules usage', async () => { await runCli({ argv: ['build'], appDirectory: fixtureDir, }); const content = await fs.readFile( path.join(fixtureDir, './dist/index.js'), 'utf8', ); expect( content.includes('contentWrapper') && content.includes('styleInject'), ).toBeTruthy(); }); });
1,365
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/style
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/style/postcss/postcss.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../../utils'; initBeforeTest(); describe('postcss', () => { const fixtureDir = __dirname; it('postcss function usage', async () => { await runCli({ argv: ['build'], appDirectory: fixtureDir, }); const content1 = await fs.readFile( path.join(fixtureDir, './dist/function/style.css'), 'utf8', ); const content2 = await fs.readFile( path.join(fixtureDir, './dist/object/style.css'), 'utf8', ); expect( content1.includes('font-size: 16px;') && content1.includes('background: white;'), ).toBeTruthy(); expect(content1 === content2).toBeTruthy(); }); });
1,370
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/style
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/style/sass/scss.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../../utils'; initBeforeTest(); describe('scss usage', () => { const appDirectory = __dirname; it('all', async () => { await runCli({ argv: ['build'], appDirectory, }); const distFilePath = path.join(appDirectory, './dist/index.css'); const content = await fs.readFile(distFilePath, 'utf-8'); expect(content.includes(`rgba(198, 83, 140, 0.88)`)).toBeTruthy(); }); });
1,381
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/style
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/style/tailwindcss/tailwindcss.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../../utils'; initBeforeTest(); describe('tailwindcss', () => { const fixtureDir = __dirname; it('tailwindcss usage', async () => { await runCli({ argv: ['build'], appDirectory: fixtureDir, enableTailwindCss: true, }); const content1 = await fs.readFile( path.join(fixtureDir, './dist/function/style.css'), 'utf8', ); const content2 = await fs.readFile( path.join(fixtureDir, './dist/object/style.css'), 'utf8', ); expect(content1.includes('0 0 0') && content1 === content2).toBeTruthy(); }); it('design system', async () => { await runCli({ argv: ['build'], appDirectory: fixtureDir, enableTailwindCss: true, configFile: 'design-system.config.ts', }); const content = await fs.readFile( path.join(fixtureDir, './dist/design-system/style.css'), 'utf8', ); expect(content.includes('0 0 0')).toBeTruthy(); }); });
1,384
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/target/target.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../utils'; initBeforeTest(); describe('target usage', () => { const fixtureDir = __dirname; it('target is es5', async () => { const configFile = 'es5.config.ts'; await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); const distFilePath = path.join(fixtureDir, './dist/index.js'); const content = await fs.readFile(distFilePath, 'utf-8'); expect(content.includes(`function(`)).toBeTruthy(); }); });
1,388
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/transformImport/transformImport.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../utils'; initBeforeTest(); describe('transformImport', () => { const fixtureDir = __dirname; it('import style', async () => { await runCli({ argv: ['build'], configFile: path.join(fixtureDir, 'modern.config.ts'), appDirectory: fixtureDir, }); const outFile = fs.readFileSync( path.resolve(__dirname, 'dist/index.js'), 'utf8', ); expect(outFile).toContain('es/button/style'); }); });
1,392
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/transformLodash/transformLodash.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../utils'; initBeforeTest(); describe('transformLodash', () => { const fixtureDir = __dirname; it('build success', async () => { const ret = await runCli({ argv: ['build'], configFile: path.join(fixtureDir, 'modern.config.ts'), appDirectory: fixtureDir, }); expect(ret.success).toBeTruthy(); }); it('should not transform lodash when transformLodash is false', async () => { const distFileCJSPath = path.join(fixtureDir, './dist/cjs/a.js'); const distFileESMPath = path.join(fixtureDir, './dist/esm/a.js'); expect(fs.existsSync(distFileCJSPath)).toBe(true); expect(fs.existsSync(distFileESMPath)).toBe(true); const cjsContent = fs.readFileSync(distFileCJSPath, 'utf-8'); expect(cjsContent).toContain(`require("lodash")`); const esmContent = fs.readFileSync(distFileESMPath, 'utf-8'); expect(esmContent).toContain(`import _ from "lodash";`); }); it('should transform lodash when transformLodash is true', async () => { const distFileESMPath = path.join(fixtureDir, './dist/esm/b.js'); const distFileCJSPath = path.join(fixtureDir, './dist/cjs/b.js'); expect(fs.existsSync(distFileESMPath)).toBe(true); expect(fs.existsSync(distFileCJSPath)).toBe(true); const esmContent = fs.readFileSync(distFileESMPath, 'utf-8'); expect(esmContent).toContain('lodash/map'); expect(esmContent).toContain('lodash/fp/add'); const cjsContent = fs.readFileSync(distFileCJSPath, 'utf-8'); expect(cjsContent).toContain('lodash/map'); expect(cjsContent).toContain('lodash/fp/add'); }); });
1,398
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/tsconfig/tsconfig.test.ts
import { runCli, initBeforeTest } from '../../utils'; initBeforeTest(); describe('dts.tsconfigPath', () => { it('buildType is bundle', async () => { const fixtureDir = __dirname; const { success } = await runCli({ argv: ['build'], appDirectory: fixtureDir, }); expect(success).toBeTruthy(); }); });
1,403
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/umdGlobals/umdGlobals.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../utils'; initBeforeTest(); describe('globals usage', () => { const fixtureDir = __dirname; it(`globals is { react: 'React' }`, async () => { await runCli({ argv: ['build'], appDirectory: fixtureDir, }); const distFilePath = path.join(fixtureDir, './dist/index.js'); const content = await fs.readFile(distFilePath, 'utf-8'); expect( content.includes( `(typeof globalThis !== "undefined" ? globalThis : typeof global !== "undefined" ? global : self || Function("return this")())["React"]`, ), ).toBeTruthy(); }); });
1,408
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/build/umdModuleName/umdModuleName.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../utils'; initBeforeTest(); describe('umdModuleName usage', () => { const fixtureDir = __dirname; it(`build success`, async () => { const configFile = path.join(fixtureDir, './config.ts'); const ret = await runCli({ argv: ['build'], configFile, appDirectory: fixtureDir, }); expect(ret.success).toBeTruthy(); const distFilePath = path.join(fixtureDir, './dist/index.js'); const content = await fs.readFile(distFilePath, 'utf-8'); // refre: https://github.com/babel/babel/blob/main/packages/babel-types/src/converters/toIdentifier.ts expect(content.includes('global.demo')).toBeTruthy(); }); });
1,415
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/dev/dev.test.ts
import path from 'path'; import { runCli, initBeforeTest } from '../utils'; initBeforeTest(); jest.mock('@modern-js/utils', () => { const originalModule = jest.requireActual('@modern-js/utils'); return { __esModule: true, ...originalModule, inquirer: { prompt: () => { return { choiceDevTool: 'dev-1' }; }, }, }; }); const fixtureDir = __dirname; describe('`dev` case', () => { afterEach(() => { jest.clearAllMocks(); }); it('normal usage', async () => { const configFile = path.join(fixtureDir, './config.ts'); const _exit = process.exit; process.exit = jest.fn(() => 0) as any; const exit = jest.spyOn(process, 'exit'); await runCli({ argv: ['dev'], configFile, appDirectory: fixtureDir, }); expect(exit).toBeCalled(); process.exit = _exit; }); it('one plugin', async () => { const configFile = path.join(fixtureDir, './config-with-plugin.ts'); const ret = await runCli({ argv: ['dev'], configFile, appDirectory: fixtureDir, }); expect(ret.success).toBeTruthy(); }); it('more plugins', async () => { const configFile = path.join(fixtureDir, './config-with-plugins.ts'); const ret = await runCli({ argv: ['dev'], configFile, appDirectory: fixtureDir, }); expect(ret.success).toBeTruthy(); }); it('beforeDevMenu', async () => { const configFile = path.join(fixtureDir, './before-dev-menu.ts'); jest.mock('@modern-js/utils', () => { const originalModule = jest.requireActual('@modern-js/utils'); return { __esModule: true, ...originalModule, inquirer: { prompt: () => { return { choiceDevTool: 'dev-1' }; }, }, }; }); const ret = await runCli({ argv: ['dev'], configFile, appDirectory: fixtureDir, }); expect(ret.success).toBeTruthy(); }); it('dev with params', async () => { const configFile = path.join(fixtureDir, './config-with-plugin.ts'); const ret = await runCli({ argv: ['dev', 'plugin-1'], configFile, appDirectory: fixtureDir, }); expect(ret.success).toBeTruthy(); }); });
1,422
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/platform/buildPlatform.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../utils'; initBeforeTest(); describe('build platform case', () => { const fixtureDir = __dirname; it('no platform plugin', async () => { const configFile = path.join(fixtureDir, './config.ts'); const ret = await runCli({ argv: ['build', '--platform'], configFile, appDirectory: fixtureDir, }); expect(ret.success).toBeTruthy(); }); it('no platform plugin with platform params', async () => { const configFile = path.join(fixtureDir, './config.ts'); const ret = await runCli({ argv: ['build', '--platform', 'plugin-1', 'plugin-2'], configFile, appDirectory: fixtureDir, }); expect(ret.success).toBeTruthy(); }); it('with plugin, and build --platform', async () => { const configFile = path.join(fixtureDir, './config-with-plugin.ts'); const ret = await runCli({ argv: ['build', '--platform'], configFile, appDirectory: fixtureDir, }); console.info(ret.error); expect(ret.success).toBeTruthy(); const distPath = path.join(fixtureDir, './dist/plugin-1.json'); expect(await fs.pathExists(distPath)); }); it('with plugin, and build --platform plugin-2', async () => { const configFile = path.join(fixtureDir, './config-with-plugin2.ts'); const ret = await runCli({ argv: ['build', '--platform', 'plugin-2'], configFile, appDirectory: fixtureDir, }); expect(ret.success).toBeTruthy(); const distPath = path.join(fixtureDir, './dist/plugin-2.json'); expect(await fs.pathExists(distPath)); }); it('with plugin, and build --platform plugin-3 plugin-4', async () => { const configFile = path.join(fixtureDir, './config-with-plugins.ts'); const ret = await runCli({ argv: ['build', '--platform', 'plugin-3', 'plugin-4'], configFile, appDirectory: fixtureDir, }); expect(ret.success).toBeTruthy(); const plugin3DistPath = path.join(fixtureDir, './dist/plugin-3.json'); expect(await fs.pathExists(plugin3DistPath)).toBeTruthy(); const plugin4DistPath = path.join(fixtureDir, './dist/plugin-4.json'); expect(await fs.pathExists(plugin4DistPath)).toBeTruthy(); }); it('nothing platform params', async () => { const configFile = path.join(fixtureDir, './config.ts'); const ret = await runCli({ argv: ['build', '--platform', 'plugin-5'], configFile, appDirectory: fixtureDir, }); expect(ret.success).toBeTruthy(); }); it('nothing platform params', async () => { const configFile = path.join(fixtureDir, './config.ts'); const ret = await runCli({ argv: ['build', '--platform', 'plugin-5'], configFile, appDirectory: fixtureDir, }); expect(ret.success).toBeTruthy(); }); it('have non-existent platform options', async () => { const configFile = path.join(fixtureDir, './config-with-plugins-1.ts'); const ret = await runCli({ argv: ['build', '--platform', 'plugin-5', 'plugin-7'], configFile, appDirectory: fixtureDir, }); expect(ret.success).toBeTruthy(); const distPath = path.join(fixtureDir, './dist/plugin-5.json'); expect(await fs.pathExists(distPath)).toBeTruthy(); }); it('have non-existent platform options', async () => { const configFile = path.join(fixtureDir, './config-with-plugins-1.ts'); const ret = await runCli({ argv: ['build', '--platform', 'plugin-7'], configFile, appDirectory: fixtureDir, }); expect(ret.success).toBeTruthy(); }); });
1,437
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures
petrpan-code/web-infra-dev/modern.js/tests/integration/module/fixtures/preset/buildPreset.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../utils'; initBeforeTest(); describe('`buildPreset` case', () => { const fixtureDir = __dirname; it('buildPreset is string', async () => { const appDirectory = path.join(fixtureDir, './string'); const configFile = path.join(fixtureDir, './string.config.ts'); const ret = await runCli({ argv: ['build'], configFile, appDirectory, }); expect(ret.success).toBeTruthy(); const distPath = path.join(appDirectory, 'dist'); expect( await fs.pathExists(path.join(distPath, './lib/index.js')), ).toBeTruthy(); expect( await fs.pathExists(path.join(distPath, './es/index.js')), ).toBeTruthy(); expect( await fs.pathExists(path.join(distPath, './types/index.d.ts')), ).toBeFalsy(); }); it('buildPreset is function', async () => { const appDirectory = path.join(fixtureDir, './function'); const configFile = path.join(fixtureDir, './function.config.ts'); const ret = await runCli({ argv: ['build'], configFile, appDirectory, }); expect(ret.success).toBeTruthy(); const distPath = path.join(appDirectory, 'dist'); expect( await fs.pathExists(path.join(distPath, './lib/index.js')), ).toBeTruthy(); expect( await fs.pathExists(path.join(distPath, './es/index.js')), ).toBeTruthy(); expect( await fs.pathExists(path.join(distPath, './umd/index.js')), ).toBeTruthy(); }); it('use extendPreset', async () => { const appDirectory = path.join(fixtureDir, './function'); const configFile = path.join(fixtureDir, './extend-preset.config.ts'); const ret = await runCli({ argv: ['build'], configFile, appDirectory, }); expect(ret.success).toBeTruthy(); const distPath = path.join(appDirectory, 'dist'); expect( await fs.pathExists(path.join(distPath, './esm/index.js')), ).toBeTruthy(); expect( await fs.pathExists(path.join(distPath, './cjs/index.js')), ).toBeTruthy(); expect( await fs.readFile(path.join(distPath, './esm/utils.js'), 'utf-8'), ).toContain('test'); expect( await fs.readFile(path.join(distPath, './cjs/utils.js'), 'utf-8'), ).toContain('test'); }); it('error1', async () => { const appDirectory = path.join(fixtureDir, './error1'); const configFile = path.join(fixtureDir, './error-1.config.ts'); const ret = await runCli({ argv: ['build'], configFile, appDirectory, }); expect(ret.success).toBeFalsy(); expect( ret.error?.message.includes( 'The `buildPreset` function does not allow no return value', ), ).toBeTruthy(); }); it('error2', async () => { const appDirectory = path.join(fixtureDir, './error2'); const configFile = path.join(fixtureDir, './error-2.config.ts'); const ret = await runCli({ argv: ['build'], configFile, appDirectory, }); expect(ret.success).toBeFalsy(); expect( ret.error?.message.includes( 'when buildType is bundleless, the format must be equal to one of the allowed values: (cjs, esm)', ), ).toBeTruthy(); }); it('error3', async () => { const appDirectory = path.join(fixtureDir, './error3'); const configFile = path.join(fixtureDir, './error-3.config.ts'); const ret = await runCli({ argv: ['build'], configFile, appDirectory, }); expect(ret.success).toBeFalsy(); expect( ret.error?.message.includes( 'when buildType is bundleless, the format must be equal to one of the allowed values: (cjs, esm)', ), ).toBeTruthy(); }); });
1,454
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/plugins
petrpan-code/web-infra-dev/modern.js/tests/integration/module/plugins/babel/babel.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../fixtures/utils'; initBeforeTest(); describe('plugin-babel', () => { const fixtureDir = __dirname; it('preset-env', async () => { await runCli({ argv: ['build'], appDirectory: fixtureDir, }); const outFile = fs.readFileSync( path.resolve(__dirname, 'dist/index.js'), 'utf8', ); const map = fs.readFileSync( path.resolve(__dirname, 'dist/index.js.map'), 'utf8', ); expect(outFile).toContain('_regeneratorRuntime'); expect(JSON.parse(map).sources[0]).toBe('../src/index.js'); }); });
1,458
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/plugins
petrpan-code/web-infra-dev/modern.js/tests/integration/module/plugins/hooks/hooks.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../fixtures/utils'; initBeforeTest(); describe('plugin-hooks', () => { const fixtureDir = __dirname; it('resolveModuleUserConfig', async () => { await runCli({ argv: ['build'], appDirectory: fixtureDir, }); expect( fs.pathExistsSync(path.resolve(__dirname, 'dist/index.js')), ).toBeTruthy(); }); });
1,463
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/plugins
petrpan-code/web-infra-dev/modern.js/tests/integration/module/plugins/node-polyfill/node-polyfill.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../fixtures/utils'; initBeforeTest(); describe('plugin-node-polyfill', () => { const fixtureDir = __dirname; it('inject global', async () => { await runCli({ argv: ['build'], appDirectory: fixtureDir, }); const content = fs.readFileSync( path.resolve(__dirname, 'dist/index.js'), 'utf8', ); expect(content).toContain('init_globals'); }); });
1,468
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/plugins
petrpan-code/web-infra-dev/modern.js/tests/integration/module/plugins/polyfill/polyfill.test.ts
import path from 'path'; import { fs } from '@modern-js/utils'; import { runCli, initBeforeTest } from '../../fixtures/utils'; initBeforeTest(); describe('plugin-polyfill', () => { const fixtureDir = __dirname; it('ie10', async () => { await runCli({ argv: ['build'], appDirectory: fixtureDir, }); const outFile = fs.readFileSync( path.resolve(__dirname, 'dist/index.js'), 'utf8', ); expect(outFile).toContain('core-js-pure'); }); });
1,472
0
petrpan-code/web-infra-dev/modern.js/tests/integration/module/plugins
petrpan-code/web-infra-dev/modern.js/tests/integration/module/plugins/vue/vue.test.ts
import { runCli, initBeforeTest } from '../../fixtures/utils'; initBeforeTest(); describe('plugin-babel', () => { const fixtureDir = __dirname; it('preset-env', async () => { const { success } = await runCli({ argv: ['build'], appDirectory: fixtureDir, }); expect(success).toBeTruthy(); }); });
1,495
0
petrpan-code/web-infra-dev/modern.js/tests/integration/nonce
petrpan-code/web-infra-dev/modern.js/tests/integration/nonce/tests/index.test.ts
import path from 'path'; import puppeteer, { Browser, Page } from 'puppeteer'; import { launchApp, getPort, killApp, launchOptions, } from '../../../utils/modernTestUtils'; const appPath = path.resolve(__dirname, '../'); describe('test nonce', () => { let app: any; let port: number; let page: Page; let browser: Browser; beforeAll(async () => { jest.setTimeout(1000 * 60 * 2); browser = await puppeteer.launch(launchOptions as any); page = await browser.newPage(); await page.deleteCookie(); port = await getPort(); app = await launchApp(appPath, port); }); afterAll(async () => { if (app) { await killApp(app); } await page.close(); await browser.close(); }); test('should inject nonce correctly', async () => { await page.goto(`http://localhost:${port}`); const scriptArr = await page.$$eval('head > script', scripts => scripts .filter(script => script.type !== 'application/json') .map(script => { return script.nonce; }), ); const nonceArr = scriptArr.filter(nonce => nonce === 'test-nonce'); expect(nonceArr.length).toBe(scriptArr.length); }); });
1,560
0
petrpan-code/web-infra-dev/modern.js/tests/integration/routes
petrpan-code/web-infra-dev/modern.js/tests/integration/routes/tests/index.test.ts
/* eslint-disable max-lines */ import path from 'path'; import puppeteer, { Browser } from 'puppeteer'; import { fs, ROUTE_MANIFEST_FILE } from '@modern-js/utils'; import { ROUTE_MANIFEST } from '@modern-js/utils/universal/constants'; import type { // Browser, Page, } from 'puppeteer'; import { launchApp, killApp, getPort, modernBuild, modernServe, launchOptions, } from '../../../utils/modernTestUtils'; import { SequenceWait } from '../../../utils/testInSequence'; // declare const browser: Browser; const appDir = path.resolve(__dirname, '../'); const renderSelfRoute = async ( page: Page, errors: string[], appPort: number, ) => { await page.goto(`http://localhost:${appPort}/one`, { waitUntil: ['networkidle0'], }); const description = await page.$('.description'); const targetText = await page.evaluate(el => el?.textContent, description); expect(targetText?.trim()).toEqual('Get started by editing src/App.tsx'); expect(errors.length).toEqual(0); }; const renderPageRoute = async ( page: Page, errors: string[], appPort: number, ) => { await page.goto(`http://localhost:${appPort}/two/user`, { waitUntil: ['networkidle0'], }); const element = await page.$('.user'); const targetText = await page.evaluate(el => el?.textContent, element); expect(targetText?.trim()).toEqual('user'); expect(errors.length).toEqual(0); }; const renderDynamicRoute = async ( page: Page, errors: string[], appPort: number, ) => { await page.goto(`http://localhost:${appPort}/two/item/1234`, { waitUntil: ['networkidle0'], }); const element = await page.$('.item'); const targetText = await page.evaluate(el => el?.textContent, element); expect(targetText?.trim()).toEqual('1234'); expect(errors.length).toEqual(0); }; const renderOptionalParamsRoute = async ( page: Page, errors: string[], appPort: number, ) => { await page.goto(`http://localhost:${appPort}/two/act/bar`, { waitUntil: ['networkidle0'], }); const element = await page.$('.item'); const targetText = await page.evaluate(el => el?.textContent, element); expect(targetText?.trim()).toEqual('bid exist'); expect(errors.length).toEqual(0); await page.goto(`http://localhost:${appPort}/two/act/bar/1234`, { waitUntil: ['networkidle0'], }); const element1 = await page.$('.item'); const targetText1 = await page.evaluate(el => el?.textContent, element1); expect(targetText1?.trim()).toEqual('1234 bid exist'); expect(errors.length).toEqual(0); await page.goto(`http://localhost:${appPort}/two/act/foo`, { waitUntil: ['networkidle0'], }); const element3 = await page.$('.item'); const targetText3 = await page.evaluate(el => el?.textContent, element3); expect(targetText3?.trim()).toEqual('uid exist'); expect(errors.length).toEqual(0); await page.goto(`http://localhost:${appPort}/two/act/foo/1234`, { waitUntil: ['networkidle0'], }); const element4 = await page.$('.item'); const targetText4 = await page.evaluate(el => el?.textContent, element4); expect(targetText4?.trim()).toEqual('1234 uid exist'); expect(errors.length).toEqual(0); await page.goto(`http://localhost:${appPort}/two/act/bar/detail`, { waitUntil: ['networkidle0'], }); const element5 = await page.$('.item'); const targetText5 = await page.evaluate(el => el?.textContent, element5); expect(targetText5?.trim()).toEqual('bid detail'); expect(errors.length).toEqual(0); await page.goto(`http://localhost:${appPort}/two/act/bar/1234/detail`, { waitUntil: ['networkidle0'], }); const element6 = await page.$('.item'); const targetText6 = await page.evaluate(el => el?.textContent, element6); expect(targetText6?.trim()).toEqual('bid detail 1234'); expect(errors.length).toEqual(0); }; const supportGlobalLayout = async ( page: Page, errors: string[], appPort: number, ) => { await page.goto(`http://localhost:${appPort}/two/user`, { waitUntil: ['networkidle0'], }); const element = await page.$('.global-layout'); const targetText = await page.evaluate( el => el?.firstChild?.textContent, element, ); expect(targetText?.startsWith('global layout')); expect(targetText?.trim()).toEqual('global layout'); expect(errors.length).toEqual(0); }; const supportLayout = async (page: Page, errors: string[], appPort: number) => { await page.goto(`http://localhost:${appPort}/two/shop`, { waitUntil: ['networkidle0'], }); const globalLayoutElm = await page.$('.global-layout'); const text = await page.evaluate( el => el?.firstChild?.textContent, globalLayoutElm, ); expect(text?.trim()).toEqual('global layout'); const shopLayoutElm = await globalLayoutElm!.$('.shop-layout'); const text1 = await page.evaluate( el => el?.firstChild?.textContent, shopLayoutElm, ); expect(text1?.trim()).toEqual('shop layout'); const shopElm = await shopLayoutElm!.$('.shop'); const text2 = await page.evaluate(el => el?.textContent, shopElm); expect(text2?.trim()).toEqual('shop'); expect(errors.length).toEqual(0); }; const supportNestedRoutes = async ( page: Page, errors: string[], appPort: number, ) => { await page.goto(`http://localhost:${appPort}/three/user`, { waitUntil: ['networkidle0'], }); const rootElm = await page.$('#root'); const text = await page.evaluate(el => el?.textContent, rootElm); expect(text?.includes('root layout')).toBeTruthy(); expect(text?.includes('user layout')).toBeTruthy(); expect(text?.includes('user page')).toBeTruthy(); await page.goto(`http://localhost:${appPort}/three/user/profile`, { waitUntil: ['networkidle0'], }); const rootElm1 = await page.$('#root'); const text1 = await page.evaluate(el => el?.textContent, rootElm1); expect(text1?.includes('root layout')).toBeTruthy(); expect(text1?.includes('user layout')).toBeTruthy(); expect(text1?.includes('profile layout')).toBeTruthy(); expect(text1?.includes('profile page')).toBeTruthy(); expect(errors.length).toEqual(0); }; const supportDynamaicPaths = async ( page: Page, errors: string[], appPort: number, ) => { await page.goto(`http://localhost:${appPort}/three/user/1234`, { waitUntil: ['networkidle0'], }); const rootElm = await page.$('#root'); const text = await page.evaluate(el => el?.textContent, rootElm); expect(text?.includes('root layout')).toBeTruthy(); expect(text?.includes('1234')).toBeTruthy(); expect(errors.length).toEqual(0); }; const supportNoLayoutDir = async ( page: Page, errors: string[], appPort: number, ) => { await page.goto(`http://localhost:${appPort}/three/user/1234/profile`, { waitUntil: ['networkidle0'], }); const rootElm = await page.$('#root'); const text = await page.evaluate(el => el?.textContent, rootElm); expect(text?.includes('root layout')).toBeTruthy(); expect(text?.includes('user layout')).toBeTruthy(); expect(text?.includes('item page, param is 1234')).toBeTruthy(); expect(errors.length).toEqual(0); }; const supportPathLessLayout = async ( page: Page, errors: string[], appPort: number, ) => { await page.goto(`http://localhost:${appPort}/three`, { waitUntil: ['networkidle0'], }); const rootElm = await page.$('#root'); const text = await page.evaluate(el => el?.textContent, rootElm); expect(text?.includes('root layout')).toBeTruthy(); expect(text?.includes('auth layout')).toBeFalsy(); await page.goto(`http://localhost:${appPort}/three/item`, { waitUntil: ['networkidle0'], }); const rootElm1 = await page.$('#root'); const text1 = await page.evaluate(el => el?.textContent, rootElm1); expect(text1?.includes('root layout')).toBeTruthy(); expect(text1?.includes('auth layout')).toBeTruthy(); expect(text1?.includes('shop layout')).toBeTruthy(); expect(text1?.includes('item page')).toBeTruthy(); expect(errors.length).toEqual(0); }; const supportPathWithoutLayout = async ( page: Page, errors: string[], appPort: number, ) => { await page.goto(`http://localhost:${appPort}/three/user/profile/name`, { waitUntil: ['networkidle0'], }); const rootElm = await page.$('#root'); const text = await page.evaluate(el => el?.textContent, rootElm); expect(text?.includes('root layout')).toBeTruthy(); expect(text?.includes('user layout')).toBeFalsy(); expect(text?.includes('user profile name layout')).toBeTruthy(); expect(text?.includes('profile name page')).toBeTruthy(); expect(errors.length).toEqual(0); }; const nestedRouteOverPage = async ( page: Page, errors: string[], appPort: number, ) => { await page.goto(`http://localhost:${appPort}/four`, { waitUntil: ['networkidle0'], }); const rootElm = await page.$('#root'); const text = await page.evaluate(el => el?.textContent, rootElm); expect(text?.includes('root layout')).toBeTruthy(); expect(text?.includes('page index')).toBeFalsy(); expect(errors.length).toEqual(0); }; const supportNestedRouteAndPage = async ( page: Page, _errors: string[], appPort: number, ) => { await page.goto(`http://localhost:${appPort}/four/item/1234`, { waitUntil: ['networkidle0'], }); const rootElm = await page.$('#root'); const text = await page.evaluate(el => el?.textContent, rootElm); expect(text?.includes('root layout')).toBeFalsy(); expect(text?.includes('1234')).toBeTruthy(); await page.goto(`http://localhost:${appPort}/four/user/1234`, { waitUntil: ['networkidle0'], }); const rootElm1 = await page.$('#root'); const text1 = await page.evaluate(el => el?.textContent, rootElm1); expect(text1?.includes('root layout')).toBeTruthy(); expect(text1?.includes('1234')).toBeTruthy(); await page.goto(`http://localhost:${appPort}/four/act`, { waitUntil: ['networkidle0'], }); const rootElm2 = await page.$('.act'); const text2 = await page.evaluate(el => el?.textContent, rootElm2); expect(text2?.includes('act page, param is')).toBeTruthy(); expect(text2?.includes('1234')).toBeFalsy(); await page.goto(`http://localhost:${appPort}/four/act/1234`, { waitUntil: ['networkidle0'], }); const rootElm3 = await page.$('.act'); const text3 = await page.evaluate(el => el?.textContent, rootElm3); expect(text3?.includes('act page, param is 1234')).toBeTruthy(); }; const supportHandleLoaderError = async ( page: Page, errors: string[], appPort: number, ) => { await page.goto(`http://localhost:${appPort}/three`, { waitUntil: ['domcontentloaded'], }); await Promise.all([ page.click('.loader-error-btn'), page.waitForSelector('.error-case'), ]); const errorElm = await page.$('.error-case'); const text = await page.evaluate(el => el?.textContent, errorElm); expect(text?.includes('loader error')).toBeTruthy(); expect(errors.length).toBe(0); }; const supportLoadChunksParallelly = async () => { const distDir = path.join(appDir, './dist'); const manifestFile = path.join(distDir, ROUTE_MANIFEST_FILE); expect(await fs.pathExists(manifestFile)).toBeTruthy(); const threeHtmlPath = path.join(distDir, 'html/three/index.html'); const threeHtml = await fs.readFile(threeHtmlPath); expect(threeHtml.includes(ROUTE_MANIFEST)).toBeTruthy(); }; const supportHandleConfig = async (page: Page, appPort: number) => { await page.goto(`http://localhost:${appPort}/three/user/profile/name`, { waitUntil: ['networkidle0'], }); await (expect(page) as any).toMatchTextContent( 'root/user.profile.name.layout/user.profile.name.page', ); }; const supportLoader = async (page: Page, errors: string[], appPort: number) => { // const page = await browser.newPage(); await page.goto(`http://localhost:${appPort}/three/user`, { waitUntil: ['domcontentloaded'], }); await Promise.all([page.waitForSelector('.user-layout')]); const userLayout = await page.$('.user-layout'); const text = await page.evaluate(el => { console.info(el); return el?.textContent; }, userLayout); expect(text).toBe('user layout'); expect(errors.length).toBe(0); }; const supportLoaderForSSRAndCSR = async ( page: Page, errors: string[], appPort: number, ) => { await page.goto(`http://localhost:${appPort}/three`, { waitUntil: ['domcontentloaded'], }); await page.click('.user-btn'); await page.waitForSelector('.user-layout'); const userLayout = await page.$(`.user-layout`); const text = await page.evaluate(el => { return el?.textContent; }, userLayout); expect(text).toBe('user layout'); expect(errors.length).toBe(0); }; const supportLoaderForCSR = async ( page: Page, errors: string[], appPort: number, ) => { await page.goto(`http://localhost:${appPort}/four/user/123`, { waitUntil: ['networkidle0'], }); const rootElm = await page.$('#root'); const text = await page.evaluate(el => el?.textContent, rootElm); expect(text?.includes('user layout')).toBeTruthy(); expect(errors.length).toBe(0); }; const supportRedirectForSSR = async ( page: Page, errors: string[], appPort: number, ) => { await page.goto(`http://localhost:${appPort}/three/redirect`, { waitUntil: ['networkidle0'], }); const rootElm = await page.$('#root'); const text = await page.evaluate(el => el?.textContent, rootElm); expect(text?.includes('profile page')).toBeTruthy(); expect(errors.length).toBe(0); }; const supportRedirectForCSR = async ( page: Page, errors: string[], appPort: number, ) => { await page.goto(`http://localhost:${appPort}/three/user`, { waitUntil: ['networkidle0'], }); await page.click('.redirect-btn'); await page.waitForSelector('.user-profile'); const rootElm = await page.$('.user-profile'); const text = await page.evaluate(el => el?.textContent, rootElm); expect(text?.includes('profile page')).toBeTruthy(); expect(errors.length).toBe(0); }; const supportDefineInit = async ( page: Page, errors: string[], appPort: number, ) => { await page.goto(`http://127.0.0.1:${appPort}/four/user`, { waitUntil: ['networkidle0'], }); const isBrowser = await page.evaluate(() => (window as any).__isBrowser); expect(isBrowser).toBeTruthy(); expect(errors.length).toBe(0); }; const supportClientLoader = async ( page: Page, errors: string[], appPort: number, ) => { await page.goto(`http://localhost:${appPort}/three`, { waitUntil: ['networkidle0'], }); await Promise.all([ page.click('.client-loader-btn'), page.waitForSelector('.client-loader-layout'), ]); const clientLoaderLayout = await page.$('.client-loader-layout'); const text = await page.evaluate(el => el?.textContent, clientLoaderLayout); expect(text?.includes('layout from client loader')).toBeTruthy(); const clientLoaderPage = await page.$('.client-loader-page'); const text1 = await page.evaluate(el => el?.textContent, clientLoaderPage); expect(text1?.includes('page from server loader')).toBeTruthy(); expect(errors.length).toBe(0); }; const supportCatchAll = async ( page: Page, errors: string[], appPort: number, ) => { await page.goto(`http://localhost:${appPort}/four/user/1234/1234`, { waitUntil: ['networkidle0'], }); const rootElm = await page.$('#root'); const text = await page.evaluate(el => el?.textContent, rootElm); expect(text?.includes('root layout')).toBeTruthy(); expect(text?.includes('catch all')).toBeTruthy(); expect(errors.length).toEqual(0); }; const getStaticJSDir = (appDir: string) => path.join(appDir, './dist/static/js'); const getHtmlDir = (appDir: string) => path.join(appDir, './dist/html'); const getEntryFile = async (staticJSDir: string) => { const files = await fs.readdir(staticJSDir); return files.find(file => /^three(\.\w+)?\.js$/.test(file)); }; const testRouterPlugin = async (appDir: string) => { const htmlDir = getHtmlDir(appDir); const threeHtmlPath = path.join(htmlDir, 'three', 'index.html'); const threeHtml = await fs.readFile(threeHtmlPath); expect(threeHtml.includes('three.')).toBe(true); expect(!threeHtml.includes('four.')).toBe(true); }; const hasHashCorrectly = async (appDir: string) => { const staticJSDir = getStaticJSDir(appDir); const entryFile = await getEntryFile(staticJSDir); expect(entryFile).toBeDefined(); const htmlDir = getHtmlDir(appDir); const threeHtmlPath = path.join(htmlDir, 'three', 'index.html'); const threeHtml = (await fs.readFile(threeHtmlPath)).toString(); const threeUserFiles = await fs.readdir( path.join(staticJSDir, 'async/three_user'), ); const testFile = threeUserFiles.find( file => file.startsWith('page') && file.endsWith('.js'), ); const matched = testFile!.match(/page\.(\w+)\.js$/); expect(matched).toBeDefined(); const hash = matched![1]; expect(threeHtml.includes(hash)).toBe(true); }; const supportActionInCSR = async ( page: Page, errors: string[], appPort: number, ) => { await page.goto(`http://localhost:${appPort}/four/user/profile`, { waitUntil: ['networkidle0'], }); const rootElm = await page.$('#root'); await page.click('.action-btn'); await page.waitForSelector('.data-wrapper'); const text = await page.evaluate(el => el?.textContent, rootElm); expect(text?.includes('profile page')).toBeTruthy(); expect(text?.includes('modern_four_action')).toBeTruthy(); }; const supportActionInSSR = async ( page: Page, errors: string[], appPort: number, ) => { expect(errors.length).toBe(0); await page.goto(`http://localhost:${appPort}/three/user/1234/profile`, { waitUntil: ['networkidle0'], }); const rootElm = await page.$('#root'); await page.click('.action-btn'); await page.waitForSelector('.data-wrapper'); const text = await page.evaluate(el => el?.textContent, rootElm); expect(text?.includes('modern_three_action')).toBeTruthy(); }; const supportShouldRevalidateInSSR = async ( page: Page, errors: string[], appPort: number, ) => { expect(errors.length).toBe(0); await page.goto(`http://localhost:${appPort}/three`, { waitUntil: ['networkidle0'], }); await page.click('.should-revalidate'); await new Promise(resolve => setTimeout(resolve, 300)); const rootElm = await page.$('#root'); const text = await page.evaluate(el => el?.textContent, rootElm); expect(text?.includes('param is 111')).toBeTruthy(); await page.click('.should-not-revalidate'); await new Promise(resolve => setTimeout(resolve, 400)); const text1 = await page.evaluate(el => el?.textContent, rootElm); expect(text1?.includes('param is 111')).toBeTruthy(); }; const supportShouldRevalidateInCSR = async ( page: Page, errors: string[], appPort: number, ) => { expect(errors.length).toBe(0); await page.goto(`http://localhost:${appPort}/four/user/111`, { waitUntil: ['networkidle0'], }); const rootElm = await page.$('#root'); const text = await page.evaluate(el => el?.textContent, rootElm); expect(text?.includes('param is 111')).toBeTruthy(); await page.click('.should-not-revalidate'); await new Promise(resolve => setTimeout(resolve, 400)); const text1 = await page.evaluate(el => el?.textContent, rootElm); expect(text1?.includes('param is 111')).toBeTruthy(); }; const supportPrefetchInIntentMode = async ( page: Page, errors: string[], appPort: number, ) => { expect(errors.length).toBe(0); await page.goto(`http://localhost:${appPort}/three`, { waitUntil: ['networkidle0'], }); let isRequestJS = false; let isRequestProfileLayoutData = false; let isRequestProfilePageData = false; page.on('request', interceptedRequest => { if ( /three_user\/profile\/layout\.([^.]*\.)?js/.test(interceptedRequest.url()) ) { isRequestJS = true; } if ( interceptedRequest .url() .includes('user/profile?__loader=three_user%2Fprofile%2Flayout') ) { isRequestProfileLayoutData = true; } if ( interceptedRequest .url() .includes('user/profile?__loader=three_user%2Fprofile%2Fpage') ) { isRequestProfilePageData = true; } }); await page.waitForSelector('.user-profile-btn'); await page.hover('.user-profile-btn'); await new Promise(resolve => setTimeout(resolve, 400)); expect(isRequestJS).toBe(true); expect(isRequestProfileLayoutData).toBe(true); expect(isRequestProfilePageData).toBe(true); }; const supportPrefetchWithShouldRevalidate = async ( page: Page, errors: string[], appPort: number, ) => { expect(errors.length).toBe(0); await page.goto(`http://localhost:${appPort}/three/user/222`, { waitUntil: ['networkidle0'], }); // make sure assets have been loaded await new Promise(resolve => setTimeout(resolve, 800)); await page.click('.root-btn'); await new Promise(resolve => setTimeout(resolve, 400)); let isRequestLayoutData = false; let isRequestPageData = false; page.on('request', interceptedRequest => { if (interceptedRequest.url().includes('__loader=three_user%2Flayout')) { isRequestLayoutData = true; } if ( interceptedRequest.url().includes('__loader=three_user%2F%28id%29%2Fpage') ) { isRequestPageData = true; } }); await page.hover('.should-not-revalidate'); await new Promise(resolve => setTimeout(resolve, 400)); expect(isRequestLayoutData).toBe(true); expect(isRequestPageData).toBe(false); }; const curSequence = new SequenceWait(); curSequence.add('dev-test'); curSequence.add('build-test'); describe('dev', () => { let app: unknown; let appPort: number; let page: Page; let browser: Browser; const errors: string[] = []; beforeAll(async () => { appPort = await getPort(); app = await launchApp(appDir, appPort, {}, {}); browser = await puppeteer.launch(launchOptions as any); page = await browser.newPage(); await page.setRequestInterception(true); page.on('request', interceptedRequest => { interceptedRequest.continue(); }); page.on('pageerror', error => { console.log(error.message); errors.push(error.message); }); }); describe('self control route', () => { test('should render correctly', async () => renderSelfRoute(page, errors, appPort)); }); describe('pages routes', () => { test('render pages route correctly', async () => renderPageRoute(page, errors, appPort)); test('render dynamic pages route correctly', async () => renderDynamicRoute(page, errors, appPort)); test('support global layout', async () => supportGlobalLayout(page, errors, appPort)); test('support _layout', async () => supportLayout(page, errors, appPort)); }); describe('nested routes', () => { test('basic usage', async () => supportNestedRoutes(page, errors, appPort)); test('dynamic path', async () => supportDynamaicPaths(page, errors, appPort)); test('support catch all', async () => supportCatchAll(page, errors, appPort)); test('no layout dir', async () => supportNoLayoutDir(page, errors, appPort)); test('pathless layout', async () => supportPathLessLayout(page, errors, appPort)); test('path without layout', async () => supportPathWithoutLayout(page, errors, appPort)); test('support load chunks Parallelly', supportLoadChunksParallelly); test('support handle config', async () => supportHandleConfig(page, appPort)); test.skip('support handle loader error', async () => supportHandleLoaderError(page, errors, appPort)); }); describe('support both page route and nested route', () => { test('nested route has higher priority', async () => nestedRouteOverPage(page, errors, appPort)); test('support works together', async () => supportNestedRouteAndPage(page, errors, appPort)); }); describe('loader', () => { test('support loader', async () => supportLoader(page, errors, appPort)); test('support loader for ssr and csr', async () => supportLoaderForSSRAndCSR(page, errors, appPort)); test('support loader for csr', () => supportLoaderForCSR(page, errors, appPort)); test('support redirect for ssr', () => supportRedirectForSSR(page, errors, appPort)); test('support redirect for csr', () => supportRedirectForCSR(page, errors, appPort)); }); describe('global configuration', () => { test('support app init', async () => await supportDefineInit(page, errors, appPort)); }); describe('router plugin', () => { test('basic usage', async () => { await testRouterPlugin(appDir); }); }); describe('client data', () => { test('support client data', async () => { await supportClientLoader(page, errors, appPort); }); }); describe('support action', () => { test('support action in CSR', async () => { await supportActionInCSR(page, errors, appPort); }); test('support action in SSR', async () => { await supportActionInSSR(page, errors, appPort); }); }); describe('prefetch', () => { test('suppport prefetch', async () => { await supportPrefetchInIntentMode(page, errors, appPort); }); test('support prefetch with shouldRevalidate', async () => { await supportPrefetchWithShouldRevalidate(page, errors, appPort); }); }); describe('support shouldRevalidate', () => { test('support shouldRevalidate in ssr', async () => { await supportShouldRevalidateInSSR(page, errors, appPort); }); test('support shouldRevalidate in csr', async () => { await supportShouldRevalidateInCSR(page, errors, appPort); }); }); afterAll(async () => { await killApp(app); await page.close(); await browser.close(); await curSequence.done('dev-test'); }); }); describe('build', () => { let appPort: number; let app: unknown; let page: Page; let browser: Browser; const errors: string[] = []; beforeAll(async () => { await curSequence.waitUntil('dev-test'); appPort = await getPort(); const buildResult = await modernBuild(appDir); // log in case for test failed by build failed if (buildResult.code !== 0) { console.log('ut test build failed, err: ', buildResult.stderr); console.log('ut test build failed, output: ', buildResult.stdout); } app = await modernServe(appDir, appPort, { cwd: appDir, }); browser = await puppeteer.launch(launchOptions as any); page = await browser.newPage(); page.on('pageerror', error => { errors.push(error.message); }); }); describe('self control route', () => { test('should render correctly', async () => renderSelfRoute(page, errors, appPort)); }); describe('pages routes', () => { test('render pages route correctly', async () => renderPageRoute(page, errors, appPort)); test('render dynamic pages route correctly', async () => renderDynamicRoute(page, errors, appPort)); test('render options params pages route correctly', async () => renderOptionalParamsRoute(page, errors, appPort)); test('support global layout', async () => supportGlobalLayout(page, errors, appPort)); test('support _layout', async () => supportLayout(page, errors, appPort)); }); describe('nested routes', () => { test('basic usage', async () => supportNestedRoutes(page, errors, appPort)); test('dynamic path', async () => supportDynamaicPaths(page, errors, appPort)); test('support catch all', async () => supportCatchAll(page, errors, appPort)); test('no layout dir', async () => supportNoLayoutDir(page, errors, appPort)); test('pathless layout', async () => supportPathLessLayout(page, errors, appPort)); test('path without layout', async () => supportPathWithoutLayout(page, errors, appPort)); test.skip('support handle loader error', async () => supportHandleLoaderError(page, errors, appPort)); }); describe('suppot both page route and nested route', () => { test('nested route has higher priority', async () => nestedRouteOverPage(page, errors, appPort)); test('support works together', async () => supportNestedRouteAndPage(page, errors, appPort)); }); describe('loader', () => { test('support loader', async () => supportLoader(page, errors, appPort)); test('support loader for ssr and csr', async () => supportLoaderForSSRAndCSR(page, errors, appPort)); test('support loader for csr', () => supportLoaderForCSR(page, errors, appPort)); test('support redirect for ssr', () => supportRedirectForSSR(page, errors, appPort)); test('support redirect for csr', () => supportRedirectForCSR(page, errors, appPort)); }); describe('global configuration', () => { test('support app init', async () => await supportDefineInit(page, errors, appPort)); }); describe('router plugin', () => { test('basic usage', async () => { await testRouterPlugin(appDir); }); test('the correct hash should be included in the bundler-runtime chunk', async () => hasHashCorrectly(appDir)); }); describe('client data', () => { test('support client data', async () => { await supportClientLoader(page, errors, appPort); }); }); describe('support action', () => { test('support action in CSR', async () => { await supportActionInCSR(page, errors, appPort); }); test('support action in SSR', async () => { await supportActionInSSR(page, errors, appPort); }); }); describe('prefetch', () => { test('suppport prefetch', async () => { await supportPrefetchInIntentMode(page, errors, appPort); }); test('support prefetch with shouldRevalidate', async () => { await supportPrefetchWithShouldRevalidate(page, errors, appPort); }); }); describe('support shouldRevalidate', () => { test('support shouldRevalidate in ssr', async () => { await supportShouldRevalidateInSSR(page, errors, appPort); }); test('support shouldRevalidate in csr', async () => { await supportShouldRevalidateInCSR(page, errors, appPort); }); }); afterAll(async () => { await killApp(app); await page.close(); await browser.close(); await curSequence.done('build-test'); }); }); describe('dev with rspack', () => { let app: unknown; let appPort: number; let page: Page; let browser: Browser; const errors: string[] = []; beforeAll(async () => { await curSequence.waitUntil('build-test'); appPort = await getPort(); app = await launchApp( appDir, appPort, {}, { BUNDLER: 'rspack', }, ); browser = await puppeteer.launch(launchOptions as any); page = await browser.newPage(); page.on('pageerror', error => { errors.push(error.message); }); }); describe('self control route', () => { test('should render correctly', async () => renderSelfRoute(page, errors, appPort)); }); describe('pages routes', () => { test('render pages route correctly', async () => renderPageRoute(page, errors, appPort)); test('render dynamic pages route correctly', async () => renderDynamicRoute(page, errors, appPort)); test('support global layout', async () => supportGlobalLayout(page, errors, appPort)); test('support _layout', async () => supportLayout(page, errors, appPort)); }); describe('nested routes', () => { test('basic usage', async () => supportNestedRoutes(page, errors, appPort)); test('dynamic path', async () => supportDynamaicPaths(page, errors, appPort)); test('support catch all', async () => supportCatchAll(page, errors, appPort)); test('no layout dir', async () => supportNoLayoutDir(page, errors, appPort)); test('pathless layout', async () => supportPathLessLayout(page, errors, appPort)); test('path without layout', async () => supportPathWithoutLayout(page, errors, appPort)); test('support load chunks Parallelly', supportLoadChunksParallelly); test('support handle config', async () => supportHandleConfig(page, appPort)); // FIXME: skip the test test.skip('support handle loader error', async () => supportHandleLoaderError(page, errors, appPort)); }); describe('support both page route and nested route', () => { test('nested route has higher priority', async () => nestedRouteOverPage(page, errors, appPort)); test('support works together', async () => supportNestedRouteAndPage(page, errors, appPort)); }); describe('loader', () => { test('support loader', async () => supportLoader(page, errors, appPort)); test('support loader for ssr and csr', async () => supportLoaderForSSRAndCSR(page, errors, appPort)); test('support loader for csr', () => supportLoaderForCSR(page, errors, appPort)); test('support redirect for ssr', () => supportRedirectForSSR(page, errors, appPort)); test('support redirect for csr', () => supportRedirectForCSR(page, errors, appPort)); }); describe('global configuration', () => { test('support app init', async () => await supportDefineInit(page, errors, appPort)); }); describe('router plugin', () => { test('basic usage', async () => { await testRouterPlugin(appDir); }); }); describe('client data', () => { test('support client data', async () => { await supportClientLoader(page, errors, appPort); }); }); describe('support action', () => { test('support action in CSR', async () => { await supportActionInCSR(page, errors, appPort); }); test('support action in SSR', async () => { await supportActionInSSR(page, errors, appPort); }); }); describe('prefetch', () => { test('suppport prefetch', async () => { await supportPrefetchInIntentMode(page, errors, appPort); }); test('support prefetch with shouldRevalidate', async () => { await supportPrefetchWithShouldRevalidate(page, errors, appPort); }); }); describe('support shouldRevalidate', () => { test('support shouldRevalidate in ssr', async () => { await supportShouldRevalidateInSSR(page, errors, appPort); }); test('support shouldRevalidate in csr', async () => { await supportShouldRevalidateInCSR(page, errors, appPort); }); }); afterAll(async () => { await killApp(app); await page.close(); await browser.close(); }); }); /* eslint-enable max-lines */
1,587
0
petrpan-code/web-infra-dev/modern.js/tests/integration/select-entry
petrpan-code/web-infra-dev/modern.js/tests/integration/select-entry/tests/select-mul-entry.test.ts
import path from 'path'; import { existsSync } from 'fs'; import getPort from 'get-port'; import { runModernCommandDev, killApp } from '../../../utils/modernTestUtils'; describe('select entry', () => { test(`should allow to select multiple entry`, async () => { const appDir = path.resolve(__dirname, '..', 'fixtures/select-mul-entry'); const port = await getPort(); const app = await runModernCommandDev( ['dev', '--entry', 'foo,bar'], undefined, { cwd: appDir, env: { NODE_ENV: 'development', PORT: port, }, }, ); expect(existsSync(path.join(appDir, 'dist/html/foo/index.html'))).toBe( true, ); expect(existsSync(path.join(appDir, 'dist/html/bar/index.html'))).toBe( true, ); expect(existsSync(path.join(appDir, 'dist/html/baz/index.html'))).toBe( false, ); await killApp(app); }); });
1,588
0
petrpan-code/web-infra-dev/modern.js/tests/integration/select-entry
petrpan-code/web-infra-dev/modern.js/tests/integration/select-entry/tests/select-one-entry.test.ts
import path from 'path'; import { existsSync } from 'fs'; import getPort from 'get-port'; import { runModernCommandDev, killApp } from '../../../utils/modernTestUtils'; describe('select entry', () => { test(`should only compile selected entry`, async () => { const appDir = path.resolve(__dirname, '..', 'fixtures/select-one-entry'); const port = await getPort(); const app = await runModernCommandDev( ['dev', '--entry', 'foo'], undefined, { cwd: appDir, env: { NODE_ENV: 'development', PORT: port, }, }, ); expect(existsSync(path.join(appDir, 'dist/html/foo/index.html'))).toBe( true, ); expect(existsSync(path.join(appDir, 'dist/html/bar/index.html'))).toBe( false, ); expect(existsSync(path.join(appDir, 'dist/html/baz/index.html'))).toBe( false, ); await killApp(app); }); });
1,599
0
petrpan-code/web-infra-dev/modern.js/tests/integration/server-config
petrpan-code/web-infra-dev/modern.js/tests/integration/server-config/tests/index.test.ts
import dns from 'node:dns'; import path from 'path'; import { fs } from '@modern-js/utils'; import { getPort, launchApp, killApp, modernBuild, modernServe, } from '../../../utils/modernTestUtils'; import 'isomorphic-fetch'; dns.setDefaultResultOrder('ipv4first'); const supportServerConfig = async ({ host, port, prefix, }: { host: string; port: number; prefix: string; }) => { const res = await fetch(`${host}:${port}${prefix}/proxy`); expect(res.status).toBe(200); const text = await res.text(); expect(text).toBe('foo'); }; const supportServerPlugins = async ({ host, port, }: { host: string; port: number; }) => { const expectedText = 'Hello Modernjs'; const res = await fetch(`${host}:${port}/api`); expect(res.status).toBe(200); const text = await res.text(); expect(text).toBe(expectedText); }; const supportConfigHook = async ({ host, port, prefix, }: { host: string; port: number; prefix: string; }) => { const res = await fetch(`${host}:${port}${prefix}/bar`); expect(res.status).toBe(200); const text = await res.text(); expect(text).toBe('foo'); }; describe('server config in dev', () => { let port = 8080; const prefix = '/api'; const host = `http://localhost`; const appPath = path.resolve(__dirname, '../'); let app: any; beforeAll(async () => { jest.setTimeout(1000 * 60 * 2); port = await getPort(); app = await launchApp(appPath, port, { cwd: appPath, }); }); test('server config should works', () => supportServerConfig({ host, port, prefix, })); test('plugins should works', () => supportServerPlugins({ host, port, })); test('support config hooks', () => supportConfigHook({ host, port, prefix, })); afterAll(async () => { await killApp(app); }); }); describe('server config in prod', () => { let port = 8080; const prefix = '/api'; const host = `http://localhost`; const appPath = path.resolve(__dirname, '../'); let app: any; beforeAll(async () => { port = await getPort(); await modernBuild(appPath, [], { cwd: appPath, }); await fs.ensureDir(path.resolve(__dirname, '../dist/api')); app = await modernServe(appPath, port, { cwd: appPath, }); }); test('server config should works', () => supportServerConfig({ host, port, prefix, })); test('plugins should works', async () => { await supportServerPlugins({ host, port, }); }); test('support config hooks', () => supportConfigHook({ host, port, prefix, })); afterAll(async () => { await killApp(app); }); });
1,608
0
petrpan-code/web-infra-dev/modern.js/tests/integration/server-hook/middleware
petrpan-code/web-infra-dev/modern.js/tests/integration/server-hook/middleware/tests/index.test.ts
import path from 'path'; import puppeteer, { Browser, Page } from 'puppeteer'; import { launchApp, getPort, killApp, launchOptions, } from '../../../../utils/modernTestUtils'; const appPath = path.resolve(__dirname, '../'); describe('test status code page', () => { let app: any; let port: number; let page: Page; let browser: Browser; beforeAll(async () => { jest.setTimeout(1000 * 60 * 2); browser = await puppeteer.launch(launchOptions as any); page = await browser.newPage(); await page.deleteCookie(); port = await getPort(); app = await launchApp(appPath, port); }); afterAll(async () => { if (app) { await killApp(app); } await page.close(); await browser.close(); }); test('should get request info correctly', async () => { const response = await page.goto(`http://localhost:${port}`); const header = response!.headers(); const text = await response!.text(); expect(text).toBe('hello modern'); expect(header['x-index-middleware']).toMatch('true'); expect(header['x-unstable-middleware']).toMatch('true'); }); });
1,616
0
petrpan-code/web-infra-dev/modern.js/tests/integration/server-hook/request
petrpan-code/web-infra-dev/modern.js/tests/integration/server-hook/request/tests/index.test.ts
import path from 'path'; import puppeteer, { Browser, Page } from 'puppeteer'; import { launchApp, getPort, killApp, launchOptions, } from '../../../../utils/modernTestUtils'; const appPath = path.resolve(__dirname, '../'); describe('test status code page', () => { let app: any; let port: number; let page: Page; let browser: Browser; beforeAll(async () => { jest.setTimeout(1000 * 60 * 2); browser = await puppeteer.launch(launchOptions as any); page = await browser.newPage(); await page.deleteCookie(); port = await getPort(); app = await launchApp(appPath, port); }); afterAll(async () => { if (app) { await killApp(app); } await page.close(); await browser.close(); }); test('should get request info correctly', async () => { const pathname = '/testpathname'; await page.deleteCookie(); await page.setExtraHTTPHeaders({ 'x-test-header': 'modern-header', cookie: 'age=18;', }); await page.goto(`http://localhost:${port}${pathname}?name=modern-team`); const text = await page.$eval('#append', el => el?.textContent); expect(text).toMatch(pathname); expect(text).toMatch('modern-team'); expect(text).toMatch('modern-header'); expect(text).toMatch(`localhost:${port}`); // Todo puppeteer cookie mistake // expect(text).toMatch('18yearold'); }); });
1,624
0
petrpan-code/web-infra-dev/modern.js/tests/integration/server-hook/response
petrpan-code/web-infra-dev/modern.js/tests/integration/server-hook/response/tests/index.test.ts
import path from 'path'; import puppeteer, { Browser, Page } from 'puppeteer'; import { launchApp, getPort, killApp, launchOptions, } from '../../../../utils/modernTestUtils'; const appPath = path.resolve(__dirname, '../'); describe('test status code page', () => { let app: any; let port: number; let page: Page; let browser: Browser; beforeAll(async () => { jest.setTimeout(1000 * 60 * 2); port = await getPort(); app = await launchApp(appPath, port); browser = await puppeteer.launch(launchOptions as any); page = await browser.newPage(); }); afterAll(async () => { if (app) { await killApp(app); await page.deleteCookie(); } await page.close(); await browser.close(); }); test('should response header work correctly', async () => { const response = await page.goto(`http://localhost:${port}/header`); const headers = response!.headers(); const text = await response!.text(); expect(headers['x-modern-name']).toBe('hello-modern'); expect(text).toBe('18yearold'); }); test('should response status work correctly', async () => { const response = await page.goto(`http://localhost:${port}/status`); expect(response!.status()).toBe(201); }); test('should response cookies apply work correctly', async () => { const response = await page.goto(`http://localhost:${port}/cookies-apply`); const headers = response!.headers(); const cookie = headers['set-cookie']; expect(cookie).toMatch('x-test-language=zh-en'); expect(cookie).toMatch('x-test-city=zhejiang'); }); test('should response cookies clear work correctly', async () => { const response = await page.goto(`http://localhost:${port}/cookies-clear`); const headers = response!.headers(); const cookie = headers['set-cookie']; expect(cookie).toBeUndefined(); }); test('should response raw work correctly', async () => { const response = await page.goto(`http://localhost:${port}/raw`); const text = await response!.text(); expect(text).toBe('hello world'); const headers = response!.headers(); expect(headers['x-modern-name']).toBe('hello-modern'); expect(response!.status()).toBe(201); }); });
1,633
0
petrpan-code/web-infra-dev/modern.js/tests/integration/server-hook/router
petrpan-code/web-infra-dev/modern.js/tests/integration/server-hook/router/tests/index.test.ts
import path from 'path'; import puppeteer, { Browser, Page } from 'puppeteer'; import { launchApp, getPort, killApp, launchOptions, } from '../../../../utils/modernTestUtils'; const appPath = path.resolve(__dirname, '../'); describe('test status code page', () => { let app: any; let port: number; let page: Page; let browser: Browser; beforeAll(async () => { jest.setTimeout(1000 * 60 * 2); port = await getPort(); app = await launchApp(appPath, port); browser = await puppeteer.launch(launchOptions as any); page = await browser.newPage(); }); afterAll(async () => { if (app) { await killApp(app); } await page.close(); await browser.close(); }); test('should router rewrite correctly ', async () => { await page.goto(`http://localhost:${port}/rewrite`); const text = await page.$eval('#root', el => el?.textContent); expect(text).toMatch('Entry Page'); }); test.skip('should router redirect correctly ', async () => { const response = await page.goto(`http://localhost:${port}/redirect`); const text = await response!.text(); expect(text).toMatch('Modern Web Development'); }); });
1,641
0
petrpan-code/web-infra-dev/modern.js/tests/integration/server-hook/template
petrpan-code/web-infra-dev/modern.js/tests/integration/server-hook/template/tests/index.test.ts
import path from 'path'; import puppeteer, { Browser, Page } from 'puppeteer'; import { launchApp, getPort, killApp, launchOptions, } from '../../../../utils/modernTestUtils'; const appPath = path.resolve(__dirname, '../'); describe('test status code page', () => { let app: any; let port: number; let page: Page; let browser: Browser; beforeAll(async () => { jest.setTimeout(1000 * 60 * 2); port = await getPort(); app = await launchApp(appPath, port); browser = await puppeteer.launch(launchOptions as any); page = await browser.newPage(); }); afterAll(async () => { if (app) { await killApp(app); } await page.close(); await browser.close(); }); test('should template api work correctly ', async () => { const response = await page.goto(`http://localhost:${port}`); const text = await response!.text(); expect(text).toMatch('<meta name="text-append" content="hello modern">'); expect(text).toMatch('<meta name="text-prepend" content="hello modern">'); expect(text).toMatch('<div id="append">appendBody</div>'); expect(text).toMatch('<div id="prepend">prependBody</div>'); expect(text).toMatch('set-extra'); }); });
1,648
0
petrpan-code/web-infra-dev/modern.js/tests/integration/server-prod
petrpan-code/web-infra-dev/modern.js/tests/integration/server-prod/tests/index.test.ts
import path from 'path'; import fs from 'fs'; import axios from 'axios'; import { modernBuild, modernServe, getPort, killApp, } from '../../../utils/modernTestUtils'; const appPath = path.resolve(__dirname, '../'); const successStatus = 200; let app: any; let appPort: number; beforeAll(async () => { await modernBuild(appPath); appPort = await getPort(); }); afterAll(async () => { if (app) { await killApp(app); } }); describe('test basic usage', () => { test(`should have favicon and app icon in dist and html`, async () => { const favicon = path.resolve(appPath, './dist/favicon.ico'); const favicon1 = path.resolve(appPath, './dist/favicon1.ico'); const appIcon = path.resolve(appPath, './dist/static/image/icon.png'); expect(fs.existsSync(favicon)).toBe(true); expect(fs.existsSync(favicon1)).toBe(true); expect(fs.existsSync(appIcon)).toBe(true); const mainEntry = path.resolve(appPath, './dist/html/main/index.html'); const activityEntry = path.resolve( appPath, './dist/html/activity/index.html', ); expect(fs.readFileSync(mainEntry, 'utf-8')).toMatch( '<link rel="icon" href="/favicon.ico">', ); const mediaPath = path.join('static', 'image', 'icon.png'); expect(fs.readFileSync(mainEntry, 'utf-8')).toMatch( `<link rel="apple-touch-icon" sizes="180*180" href="/${mediaPath}">`, ); expect(fs.readFileSync(activityEntry, 'utf-8')).toMatch( '<link rel="icon" href="/favicon.ico">', ); expect(fs.readFileSync(activityEntry, 'utf-8')).toMatch( `<link rel="apple-touch-icon" sizes="180*180" href="/${mediaPath}">`, ); }); test(`should start successfully`, async () => { app = await modernServe(appPath, appPort); expect(app.pid).toBeDefined(); const { status } = await axios.get(`http://localhost:${appPort}`); expect(status).toBe(successStatus); const { status: aStatus } = await axios.get( `http://localhost:${appPort}/activity`, ); expect(aStatus).toBe(successStatus); }); test(`should serve favicon and app icon`, async () => { const { status } = await axios.get( `http://localhost:${appPort}/favicon1.ico`, ); expect(status).toBe(successStatus); // ignore // expect(headers['content-type']).toMatch(/image/); const { status: aStatus, headers: aHeaders } = await axios.get( `http://localhost:${appPort}/favicon.ico`, ); expect(aStatus).toBe(successStatus); expect(aHeaders['content-type']).toBe('image/x-icon'); }); test(`should serve app icon`, async () => { const { status, headers } = await axios.get( `http://localhost:${appPort}/static/image/icon.png`, ); expect(status).toBe(successStatus); expect(headers['content-type']).toBe('image/png'); }); });
1,650
0
petrpan-code/web-infra-dev/modern.js/tests/integration
petrpan-code/web-infra-dev/modern.js/tests/integration/source-code-build/enable-ts-loader.test.ts
import path from 'path'; import getPort from 'get-port'; import puppeteer, { Browser } from 'puppeteer'; import { fs } from '@modern-js/utils'; import { launchApp, launchOptions, killApp, sleep, } from '../../utils/modernTestUtils'; const appDir = path.resolve(__dirname, './app-ts-loader'); jest.setTimeout(1000 * 60 * 2); describe('source build', () => { let app: any; let browser: Browser; let port: number; let common: { codeDir: string; original: string; }; beforeEach(async () => { port = await getPort(); app = await launchApp(appDir, port, {}); browser = await puppeteer.launch(launchOptions as any); const commonIndexPath = path.join(__dirname, './common/src/index.ts'); common = { codeDir: commonIndexPath, original: await fs.readFile(commonIndexPath, 'utf8'), }; }); test('should run successfully', async () => { expect(app.exitCode).toBe(null); // browser = await puppeteer.launch(launchOptions as any); const page = await browser.newPage(); await page.goto(`http://localhost:${port}`); const root = await page.$('#root'); const targetText = await page.evaluate(el => el?.textContent, root); expect(targetText).toMatch('1.0.0'); }); test('update component project code', async () => { const newContent = common.original.replace(/1.0.0/g, '2.0.0'); await fs.writeFile(common.codeDir, newContent); await sleep(2000); const page = await browser.newPage(); await page.goto(`http://localhost:${port}`); const root = await page.$('#root'); const targetText = await page.evaluate(el => el?.textContent, root); expect(targetText).toMatch('2.0.0'); }); afterEach(async () => { browser.close(); await killApp(app); await fs.writeFile(common.codeDir, common.original); }); });
1,651
0
petrpan-code/web-infra-dev/modern.js/tests/integration
petrpan-code/web-infra-dev/modern.js/tests/integration/source-code-build/index.test.ts
import path from 'path'; import getPort from 'get-port'; import puppeteer, { Browser } from 'puppeteer'; import { fs } from '@modern-js/utils'; import { launchApp, launchOptions, killApp, sleep, } from '../../utils/modernTestUtils'; const appDir = path.resolve(__dirname, './app'); jest.setTimeout(1000 * 60 * 2); describe('source build', () => { let app: any; let browser: Browser; let port: number; let card: { codeDir: string; original: string; }; let utils: { codeDir: string; original: string; }; beforeEach(async () => { port = await getPort(); app = await launchApp(appDir, port, {}); browser = await puppeteer.launch(launchOptions as any); const cardCompDir = path.join(__dirname, './components/src/card/index.tsx'); card = { codeDir: cardCompDir, original: await fs.readFile(cardCompDir, 'utf8'), }; const utilsDir = path.join(__dirname, './utils/src/index.ts'); utils = { codeDir: utilsDir, original: await fs.readFile(utilsDir, 'utf8'), }; }); test('should run successfully', async () => { expect(app.exitCode).toBe(null); // browser = await puppeteer.launch(launchOptions as any); const page = await browser.newPage(); await page.goto(`http://localhost:${port}`); const root = await page.$('#root'); const targetText = await page.evaluate(el => el?.textContent, root); expect(targetText).toMatch('Card Comp Title: App'); expect(targetText).toMatch('CARD COMP CONTENT:hello world'); }); test('update component project code', async () => { const newContent = card.original.replace(/Card Comp/g, 'Card-Comp'); await fs.writeFile(card.codeDir, newContent); await sleep(2000); const page = await browser.newPage(); await page.goto(`http://localhost:${port}`); const root = await page.$('#root'); const targetText = await page.evaluate(el => el?.textContent, root); expect(targetText).toMatch('Card-Comp'); expect(targetText).toMatch('CARD-COMP'); }); test('update utils project code', async () => { const newContent = ` export const strAdd = (str1: string, str2: string) => { return 'this is utils' + str1 + str2; } `; await fs.writeFile(utils.codeDir, newContent); await sleep(2000); const page = await browser.newPage(); await page.goto(`http://localhost:${port}`); const root = await page.$('#root'); const targetText = await page.evaluate(el => el?.textContent, root); expect(targetText).toMatch('this is utils'); }); afterEach(async () => { browser.close(); await killApp(app); await fs.writeFile(card.codeDir, card.original); await fs.writeFile(utils.codeDir, utils.original); }); });
1,700
0
petrpan-code/web-infra-dev/modern.js/tests/integration/ssg
petrpan-code/web-infra-dev/modern.js/tests/integration/ssg/tests/nested-routes.test.ts
import path, { join } from 'path'; import puppeteer, { Browser, Page } from 'puppeteer'; import { fs } from '@modern-js/utils'; import { modernServe, launchOptions, modernBuild, getPort, killApp, } from '../../../utils/modernTestUtils'; const fixtureDir = path.resolve(__dirname, '../fixtures'); jest.setTimeout(1000 * 60 * 3); describe('ssg', () => { let app: any; let appDir: string; let page: Page; let browser: Browser; let distDir: string; beforeAll(async () => { appDir = join(fixtureDir, 'nested-routes'); distDir = join(appDir, './dist'); await modernBuild(appDir); app = await modernServe(appDir, await getPort(), { cwd: appDir, }); browser = await puppeteer.launch(launchOptions as any); page = await browser.newPage(); }); afterAll(async () => { await killApp(app); await page.close(); await browser.close(); }); test('should nested-routes ssg access / work correctly', async () => { const htmlPath = path.join(distDir, 'html/main/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 html = (await fs.readFile(htmlPath)).toString(); expect(html.includes('Hello, User')).toBe(true); }); });
1,701
0
petrpan-code/web-infra-dev/modern.js/tests/integration/ssg
petrpan-code/web-infra-dev/modern.js/tests/integration/ssg/tests/simple.test.ts
import path, { join } from 'path'; import { fs } from '@modern-js/utils'; import { modernBuild } from '../../../utils/modernTestUtils'; const fixtureDir = path.resolve(__dirname, '../fixtures'); jest.setTimeout(1000 * 60 * 2); describe('ssg', () => { test('should simple ssg work correctly', async () => { const appDir = join(fixtureDir, 'simple'); await modernBuild(appDir); const htmlPath = path.join(appDir, './dist/html/main/index.html'); const content = fs.readFileSync(htmlPath, 'utf-8'); expect(content).toMatch('Hello, Modern.js'); }); });
1,703
0
petrpan-code/web-infra-dev/modern.js/tests/integration/ssg
petrpan-code/web-infra-dev/modern.js/tests/integration/ssg/tests/web-server.test.ts
import path, { join } from 'path'; import { fs } from '@modern-js/utils'; import { modernBuild } from '../../../utils/modernTestUtils'; const fixtureDir = path.resolve(__dirname, '../fixtures'); jest.setTimeout(1000 * 60 * 2); describe('ssg', () => { test('should web-server ssg work correctly', async () => { const appDir = join(fixtureDir, 'web-server'); await modernBuild(appDir); const htmlPath = path.join(appDir, './dist/html/main/index.html'); const content = fs.readFileSync(htmlPath, 'utf-8'); expect(content).toMatch('Hello, Modern.js'); expect(content).toMatch('bytedance'); }); });
1,768
0
petrpan-code/web-infra-dev/modern.js/tests/integration/ssr
petrpan-code/web-infra-dev/modern.js/tests/integration/ssr/tests/base-fallback.test.ts
import dns from 'node:dns'; import path, { join } from 'path'; import puppeteer, { Page, Browser } from 'puppeteer'; import { launchApp, getPort, killApp, launchOptions, } from '../../../utils/modernTestUtils'; dns.setDefaultResultOrder('ipv4first'); const fixtureDir = path.resolve(__dirname, '../fixtures'); async function basicUsage(page: Page, appPort: number) { await page.setExtraHTTPHeaders({ 'x-modern-ssr-fallback': '1', }); const response = await page.goto(`http://localhost:${appPort}`, { waitUntil: ['networkidle0'], }); const text = await response!.text(); expect(text).toMatch('<!--<?- html ?>-->'); } describe('Traditional SSR', () => { let app: any; let appPort: number; let page: Page; let browser: Browser; beforeAll(async () => { const appDir = join(fixtureDir, 'fallback'); appPort = await getPort(); app = await launchApp(appDir, appPort, {}); browser = await puppeteer.launch(launchOptions as any); page = await browser.newPage(); }); afterAll(async () => { if (browser) { browser.close(); } if (app) { await killApp(app); } }); test(`basic usage`, async () => { await basicUsage(page, appPort); }); });
1,769
0
petrpan-code/web-infra-dev/modern.js/tests/integration/ssr
petrpan-code/web-infra-dev/modern.js/tests/integration/ssr/tests/base-json.test.ts
import path, { join } from 'path'; import puppeteer, { Page, Browser } from 'puppeteer'; import { launchApp, getPort, killApp, launchOptions, } from '../../../utils/modernTestUtils'; const fixtureDir = path.resolve(__dirname, '../fixtures'); async function basicUsage(page: Page, appPort: number) { await page.goto(`http://localhost:${appPort}/user/1`, { waitUntil: ['networkidle0'], }); await (expect(page) as any).toMatchTextContent('user1-18'); } async function errorThrown(page: Page, appPort: number) { await page.goto(`http://localhost:${appPort}/error`, { waitUntil: ['networkidle0'], }); await (expect(page) as any).toMatchTextContent(/error occurs/); } async function errorThrownInClientNavigation(page: Page, appPort: number) { await page.goto(`http://localhost:${appPort}`, { waitUntil: ['networkidle0'], }); await page.click('#error-btn'); await (expect(page) as any).toMatchTextContent( /{"status":500,"statusText":"Internal Server Error","internal":false,"data":"Error: error occurs"}/, ); } async function redirectInLoader(page: Page, appPort: number) { const res = await page.goto(`http://localhost:${appPort}/redirect`, { waitUntil: ['networkidle0'], }); const body = await res!.text(); expect(body).toMatch(/Root layout/); expect(body).not.toMatch(/Redirect page/); } describe('Traditional SSR in json data', () => { let app: any; let appPort: number; let page: Page; let browser: Browser; beforeAll(async () => { const appDir = join(fixtureDir, 'base-json'); appPort = await getPort(); app = await launchApp(appDir, appPort, {}); browser = await puppeteer.launch(launchOptions as any); page = await browser.newPage(); }); afterAll(async () => { if (browser) { browser.close(); } if (app) { await killApp(app); } }); test(`basic usage`, async () => { await basicUsage(page, appPort); }); test('error thrown in loader', async () => { await errorThrown(page, appPort); }); test('error thrown in client navigation', async () => { await errorThrownInClientNavigation(page, appPort); }); test('redirect in loader', async () => { await redirectInLoader(page, appPort); }); });
1,770
0
petrpan-code/web-infra-dev/modern.js/tests/integration/ssr
petrpan-code/web-infra-dev/modern.js/tests/integration/ssr/tests/base.test.ts
import dns from 'node:dns'; import path, { join } from 'path'; import puppeteer, { Browser, Page } from 'puppeteer'; import { fs } from '@modern-js/utils'; import { launchApp, getPort, killApp, launchOptions, } from '../../../utils/modernTestUtils'; dns.setDefaultResultOrder('ipv4first'); const fixtureDir = path.resolve(__dirname, '../fixtures'); async function basicUsage(page: Page, appPort: number) { await page.goto(`http://localhost:${appPort}/user/1`, { waitUntil: ['networkidle0'], }); await (expect(page) as any).toMatchTextContent('user1-18'); } async function errorThrown(page: Page, appPort: number) { await page.goto(`http://localhost:${appPort}/error`, { waitUntil: ['networkidle0'], }); await (expect(page) as any).toMatchTextContent(/error occurs/); } async function errorThrownInClientNavigation(page: Page, appPort: number) { await page.goto(`http://localhost:${appPort}`, { waitUntil: ['networkidle0'], }); await page.click('#error-btn'); await (expect(page) as any).toMatchTextContent( /{"status":500,"statusText":"Internal Server Error","internal":false,"data":"Error: error occurs"}/, ); } async function redirectInLoader(page: Page, appPort: number) { const res = await page.goto(`http://localhost:${appPort}/redirect`, { waitUntil: ['networkidle0'], }); const body = await res!.text(); expect(body).toMatch(/Root layout/); expect(body).not.toMatch(/Redirect page/); } async function checkIsPassChunkLoadingGlobal() { const modernJsDir = join(fixtureDir, 'base', 'node_modules', '.modern-js'); const entryFilePath = join(modernJsDir, 'main', 'index.jsx'); const content = await fs.readFile(entryFilePath, 'utf-8'); expect(content).toMatch(/chunkLoadingGlobal/); } describe('Traditional SSR', () => { let app: any; let appPort: number; let page: Page; let browser: Browser; beforeAll(async () => { const appDir = join(fixtureDir, 'base'); appPort = await getPort(); app = await launchApp(appDir, appPort); browser = await puppeteer.launch(launchOptions as any); page = await browser.newPage(); }); afterAll(async () => { if (browser) { browser.close(); } if (app) { await killApp(app); } }); test(`basic usage`, async () => { await basicUsage(page, appPort); }); test(`should pass chunkLoadingGlobal`, async () => { await checkIsPassChunkLoadingGlobal(); }); test.skip(`client navigation works`, async () => { await page.goto(`http://localhost:${appPort}`, { waitUntil: ['networkidle0'], }); await page.click('#user-btn'); await (expect(page) as any).toMatchTextContent('user1-18'); }); test('error thrown in loader', async () => { await errorThrown(page, appPort); }); test('error thrown in client navigation', async () => { await errorThrownInClientNavigation(page, appPort); }); test('redirect in loader', async () => { await redirectInLoader(page, appPort); }); });
1,771
0
petrpan-code/web-infra-dev/modern.js/tests/integration/ssr
petrpan-code/web-infra-dev/modern.js/tests/integration/ssr/tests/index.test.ts
import path, { join } from 'path'; import puppeteer, { Browser, Page } from 'puppeteer'; import { launchApp, getPort, killApp, launchOptions, } from '../../../utils/modernTestUtils'; const fixtureDir = path.resolve(__dirname, '../fixtures'); jest.setTimeout(1000 * 20); describe('init with SSR', () => { let app: any; let appPort: number; let page: Page; let browser: Browser; beforeAll(async () => { const appDir = join(fixtureDir, 'init'); appPort = await getPort(); app = await launchApp(appDir, appPort); browser = await puppeteer.launch(launchOptions as any); page = await browser.newPage(); }); afterAll(async () => { if (browser) { browser.close(); } if (app) { await killApp(app); } }); // FIXME: Skipped because this test often times out test.skip(`use ssr init data`, async () => { await page.goto(`http://localhost:${appPort}`, { waitUntil: ['networkidle0'], }); const element = await page.$('#data'); const targetText = await page.evaluate(el => el?.textContent, element); expect(targetText).toMatch('server'); }); // FIXME: Skipped because this test often times out test.skip(`use ssr init data`, async () => { await page.goto(`http://localhost:${appPort}?browser=true`, { waitUntil: ['networkidle0'], }); const element = await page.$('#data'); const targetText = await page.evaluate(el => el?.textContent, element); expect(targetText).toMatch('client'); }); });
1,772
0
petrpan-code/web-infra-dev/modern.js/tests/integration/ssr
petrpan-code/web-infra-dev/modern.js/tests/integration/ssr/tests/inline.test.ts
import dns from 'node:dns'; import path, { join } from 'path'; import puppeteer, { Browser, Page } from 'puppeteer'; import { getPort, killApp, launchOptions, modernBuild, modernServe, } from '../../../utils/modernTestUtils'; const fixtureDir = path.resolve(__dirname, '../fixtures'); dns.setDefaultResultOrder('ipv4first'); describe.skip('Inline SSR', () => { let app: any; let appPort: number; let page: Page; let browser: Browser; beforeAll(async () => { const appDir = join(fixtureDir, 'inline'); appPort = await getPort(); await modernBuild(appDir); app = await modernServe(appDir, appPort); browser = await puppeteer.launch(launchOptions as any); page = await browser.newPage(); }); test('should inline style & js', async () => { await page.goto(`http://localhost:${appPort}`); const content = await page.content(); expect(content).toMatch('.card:hover'); expect(content).toMatch('t.jsx)("code",'); }); afterAll(async () => { if (browser) { browser.close(); } if (app) { await killApp(app); } }); });
1,773
0
petrpan-code/web-infra-dev/modern.js/tests/integration/ssr
petrpan-code/web-infra-dev/modern.js/tests/integration/ssr/tests/preload.test.ts
import http, { OutgoingHttpHeaders } from 'http'; import path from 'path'; import { fs } from '@modern-js/utils'; import { launchApp, getPort, killApp } from '../../../utils/modernTestUtils'; const fixtureDir = path.resolve(__dirname, '../fixtures'); async function request( url: string, options?: { timeout?: number }, ): Promise<{ body: string; headers: OutgoingHttpHeaders; }> { return new Promise((resolve, reject) => { setTimeout(() => { // eslint-disable-next-line prefer-promise-reject-errors reject(`timeout: ${options?.timeout || 3000}`); }, options?.timeout || 3000); const req = http.request(url, res => { res.on('error', reject); let data = ''; res.on('data', chunk => { data += chunk.toString(); }); res.on('end', () => { resolve({ headers: res.headers, body: data, }); }); }); req.end(); }); } describe('SSR preload', () => { let app: any; let appPort: number; const appDir = path.join(fixtureDir, 'preload'); beforeAll(async () => { appPort = await getPort(); app = await launchApp(appDir, appPort); }); afterAll(async () => { if (app) { await killApp(app); } }); test(`should add Links to response headers`, async () => { const url = `http://127.0.0.1:${appPort}`; const { headers, body } = await request(url); const links = (headers.link as string).split(', '); // the vendors chunk include hash, would fail in CI // so filtration the vendors chunk, expect(links.filter(link => !link.includes('vendors'))).toMatchSnapshot(); expect(body).toMatch('"renderLevel":2'); }); test('should set routes.stream is true', async () => { const routePath = path.resolve(appDir, 'dist', 'route.json'); const content = JSON.parse(fs.readFileSync(routePath, 'utf-8')); expect(content.routes[0].isStream).toBeTruthy(); }); });
1,774
0
petrpan-code/web-infra-dev/modern.js/tests/integration/ssr
petrpan-code/web-infra-dev/modern.js/tests/integration/ssr/tests/streaming.test.ts
import path, { join } from 'path'; import puppeteer, { Browser, Page } from 'puppeteer'; import { launchApp, getPort, killApp, launchOptions, } from '../../../utils/modernTestUtils'; const fixtureDir = path.resolve(__dirname, '../fixtures'); async function basicUsage(page: Page, appPort: number) { const res = await page.goto(`http://localhost:${appPort}/about`, { waitUntil: ['networkidle0'], }); const body = await res!.text(); // css chunks inject correctly expect(body).toMatch( /<link href="\/static\/css\/async\/about\/page.css" rel="stylesheet" \/>/, ); expect(body).toMatch(/<div hidden id="S:0">[\s\S]*<div>About content<\/div>/); expect(body).toMatch('reporter'); } async function deferredData(page: Page, appPort: number) { await page.goto(`http://localhost:${appPort}/user/1`, { waitUntil: ['networkidle0'], }); await (expect(page) as any).toMatchTextContent(/user1-18/); } async function deferredDataInNavigation(page: Page, appPort: number) { await page.goto(`http://localhost:${appPort}`, { waitUntil: ['networkidle0'], }); await page.click('#user-btn'); await (expect(page) as any).toMatchTextContent(/user1-18/); } async function errorThrownInLoader(page: Page, appPort: number) { const res = await page.goto(`http://localhost:${appPort}/error`, { waitUntil: ['networkidle0'], }); const body = await res!.text(); expect(body).toMatch(/Something went wrong!.*error occurs/); } describe('Streaming SSR', () => { let app: any; let appPort: number; let page: Page; let browser: Browser; beforeAll(async () => { const appDir = join(fixtureDir, 'streaming'); appPort = await getPort(); app = await launchApp(appDir, appPort, {}); browser = await puppeteer.launch(launchOptions as any); page = await browser.newPage(); }); afterAll(async () => { if (browser) { browser.close(); } if (app) { await killApp(app); } }); test(`basic usage`, async () => { await basicUsage(page, appPort); }); test(`deferred data`, async () => { await deferredData(page, appPort); }); test(`deferred data in client navigation`, async () => { await deferredDataInNavigation(page, appPort); }); test('error thrown in loader', async () => { await errorThrownInLoader(page, appPort); }); });
1,776
0
petrpan-code/web-infra-dev/modern.js/tests/integration/ssr/tests
petrpan-code/web-infra-dev/modern.js/tests/integration/ssr/tests/__snapshots__/preload.test.ts.snap
// Jest Snapshot v1, https://goo.gl/fbAQLP exports[`SSR preload should add Links to response headers 1`] = ` [ "</static/css/async/page.css>; rel=preload; as=style", "</static/js/async/page.js>; rel=preload; as=script", "</static/js/main.js>; rel=preload; as=script", "<https://lf3-static.bytednsdoc.com/obj/eden-cn/nuvshpqnulg/eden-x-logo.png>; rel=preload; as=image", ] `;
1,818
0
petrpan-code/web-infra-dev/modern.js/tests/integration/swc
petrpan-code/web-infra-dev/modern.js/tests/integration/swc/tests/decorator.test.ts
import path from 'path'; import { readFileSync, readdirSync } from 'fs'; import { modernBuild } from '../../../utils/modernTestUtils'; const fixtures = path.resolve(__dirname, '../fixtures'); const getJsFiles = (appDir: string) => readdirSync(path.resolve(appDir, 'dist/static/js')) .filter(filepath => /\.js$/.test(filepath)) .map(filePath => readFileSync(path.join(appDir, 'dist/static/js', filePath)), ); describe('swc use new decorator', () => { test('should use new decorator', async () => { const appDir = path.resolve(fixtures, 'decorator/new'); await modernBuild(appDir); const jsFiles = getJsFiles(appDir); expect( jsFiles.some(item => item.includes('@swc/helpers/esm/_decorate.js')), ).toBeTruthy(); }); test('should use legacy decorator', async () => { const appDir = path.resolve(fixtures, 'decorator/legacy'); await modernBuild(appDir); const jsFiles = getJsFiles(appDir); expect(jsFiles.some(item => item.includes('_ts_decorate'))).toBeTruthy(); }); });
1,819
0
petrpan-code/web-infra-dev/modern.js/tests/integration/swc
petrpan-code/web-infra-dev/modern.js/tests/integration/swc/tests/minify-css.test.ts
import path from 'path'; import { readdirSync, readFileSync } from 'fs'; import { modernBuild } from '../../../utils/modernTestUtils'; const fixtures = path.resolve(__dirname, '../fixtures'); const getCssFiles = (appDir: string) => readdirSync(path.resolve(appDir, 'dist/static/css')).filter(filepath => /\.css$/.test(filepath), ); describe('swc css minify', () => { test('should minify css', async () => { const appDir = path.resolve(fixtures, 'minify-css'); await modernBuild(appDir); const cssFile = getCssFiles(appDir)[0]; const content = readFileSync( path.resolve(appDir, `dist/static/css/${cssFile}`), 'utf8', ); expect(content).toContain( '@charset "UTF-8";:root{--bs-blue:#0d6efd;--bs-indigo:#6610f2;', ); }); });