2022-11-21 17:58:15 +08:00
|
|
|
import * as path from 'path';
|
|
|
|
import * as fs from 'fs';
|
2022-08-10 20:03:28 +08:00
|
|
|
import { expect, test, describe, afterAll } from 'vitest';
|
|
|
|
import { buildFixture, setupBrowser } from '../utils/build';
|
|
|
|
import type { Page } from '../utils/browser';
|
|
|
|
import type Browser from '../utils/browser';
|
|
|
|
|
|
|
|
const example = 'with-store';
|
|
|
|
|
|
|
|
describe(`build ${example}`, () => {
|
|
|
|
let page: Page;
|
|
|
|
let browser: Browser;
|
|
|
|
|
|
|
|
test('open /', async () => {
|
|
|
|
await buildFixture(example);
|
|
|
|
const res = await setupBrowser({ example, disableJS: false });
|
|
|
|
page = res.page;
|
|
|
|
browser = res.browser;
|
2022-09-07 14:49:54 +08:00
|
|
|
await page.waitForFunction('document.getElementsByTagName(\'button\').length > 0');
|
2022-10-17 15:26:37 +08:00
|
|
|
expect(await page.$$text('#username')).toStrictEqual(['name: icejs']);
|
2022-08-10 20:03:28 +08:00
|
|
|
expect(await page.$$text('#count')).toStrictEqual(['0']);
|
2022-11-21 17:58:15 +08:00
|
|
|
|
|
|
|
const dataLoaderPath = path.join(__dirname, `../../examples/${example}/build/js/data-loader.js`);
|
|
|
|
|
|
|
|
// should not contain react
|
|
|
|
const dataLoaderContent = fs.readFileSync(dataLoaderPath, 'utf-8');
|
|
|
|
expect(dataLoaderContent.includes('createElement')).toBe(false);
|
|
|
|
|
|
|
|
// size of data loader should be less than 14kib
|
|
|
|
const stats = fs.statSync(dataLoaderPath);
|
|
|
|
expect(stats.size).toBeLessThan(1024 * 14);
|
2022-11-22 16:43:03 +08:00
|
|
|
});
|
2022-08-10 20:03:28 +08:00
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
await browser.close();
|
|
|
|
});
|
|
|
|
});
|