forked from module-federation/vite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcss-manifest.test.ts
More file actions
73 lines (64 loc) · 2.35 KB
/
css-manifest.test.ts
File metadata and controls
73 lines (64 loc) · 2.35 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { resolve } from 'path';
import { describe, expect, it } from 'vitest';
import type { ModuleFederationOptions } from '../src/utils/normalizeModuleFederationOptions';
import { buildFixture, FIXTURES } from './helpers/build';
import { parseManifest } from './helpers/matchers';
const CSS_BASE_MF_OPTIONS = {
name: 'cssRemote',
filename: 'remoteEntry.js',
exposes: {
'./widget': resolve(FIXTURES, 'css-remote', 'exposed-module.js'),
},
manifest: true,
dts: false,
} satisfies Partial<ModuleFederationOptions>;
interface ManifestExpose {
id: string;
name: string;
path: string;
assets: {
js: { sync: string[]; async: string[] };
css: { sync: string[]; async: string[] };
};
}
describe('css manifest', () => {
it('tracks CSS and JS assets under the correct expose', async () => {
const output = await buildFixture({
fixture: 'css-remote',
mfOptions: CSS_BASE_MF_OPTIONS,
});
const manifest = parseManifest(output) as Record<string, unknown>;
expect(manifest).toBeDefined();
expect(manifest).toHaveProperty('exposes');
const exposes = manifest.exposes as ManifestExpose[];
const widget = exposes.find((e) => e.name === 'widget');
expect(widget).toBeDefined();
const allCssFiles = [...widget!.assets.css.sync, ...widget!.assets.css.async];
expect(allCssFiles.length).toBeGreaterThanOrEqual(1);
for (const file of allCssFiles) {
expect(file).toMatch(/\.css$/);
}
const allJsFiles = [...widget!.assets.js.sync, ...widget!.assets.js.async];
expect(allJsFiles.length).toBeGreaterThanOrEqual(1);
for (const file of allJsFiles) {
expect(file).toMatch(/\.js$/);
}
});
it('adds CSS to all exposes when bundleAllCSS is enabled', async () => {
const output = await buildFixture({
fixture: 'css-remote',
mfOptions: { ...CSS_BASE_MF_OPTIONS, bundleAllCSS: true },
});
const manifest = parseManifest(output) as Record<string, unknown>;
expect(manifest).toBeDefined();
const exposes = manifest.exposes as ManifestExpose[];
expect(exposes.length).toBeGreaterThanOrEqual(1);
for (const expose of exposes) {
const cssCount = expose.assets.css.sync.length + expose.assets.css.async.length;
expect(
cssCount,
`expose "${expose.name}" should have at least one CSS asset`
).toBeGreaterThanOrEqual(1);
}
});
});