/
index.test.ts
53 lines (39 loc) · 1.45 KB
/
index.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import path from 'path';
import { readFileSync } from 'fs';
import { Page } from 'puppeteer';
import { launchApp, killApp } from '../../../utils/modernTestUtils';
const DEFAULT_DEV_HOST = '127.0.0.1';
declare const page: Page;
const fixtures = path.resolve(__dirname, '../fixtures');
describe('asset prefix', () => {
it(`should generate assetPrefix correctly when dev.assetPrefix is true`, async () => {
const appDir = path.resolve(fixtures, 'dev-asset-prefix');
const app = await launchApp(appDir);
const HTML = readFileSync(
path.join(appDir, 'dist/html/main/index.html'),
'utf-8',
);
expect(HTML.includes(`//${DEFAULT_DEV_HOST}:3333/static/js/`)).toBeTruthy();
await killApp(app);
});
it(`should inject window.__assetPrefix__ global variable`, async () => {
const appDir = path.resolve(fixtures, 'dev-asset-prefix');
const app = await launchApp(appDir);
const expected = `//${DEFAULT_DEV_HOST}:3333`;
const mainJs = readFileSync(
path.join(appDir, 'dist/static/js/main.js'),
'utf-8',
);
expect(
mainJs.includes(`window.__assetPrefix__ = '${expected}';`),
).toBeTruthy();
await page.goto(`http:${expected}`);
const assetPrefix = await page.evaluate(() => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
return window.__assetPrefix__;
});
expect(assetPrefix).toEqual(expected);
await killApp(app);
});
});