forked from module-federation/vite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.test.ts
More file actions
46 lines (39 loc) · 1.72 KB
/
build.test.ts
File metadata and controls
46 lines (39 loc) · 1.72 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
import { resolve } from 'path';
import { describe, expect, it } from 'vitest';
import { buildFixture, FIXTURES } from './helpers/build';
import { findAsset, findChunk, getAllChunkCode, getChunkNames } from './helpers/matchers';
const BASIC_REMOTE_MF_OPTIONS = {
exposes: {
'./exposed': resolve(FIXTURES, 'basic-remote', 'exposed-module.js'),
},
};
describe('build', () => {
describe('remote', () => {
it('produces a remoteEntry chunk', async () => {
const output = await buildFixture({ mfOptions: BASIC_REMOTE_MF_OPTIONS });
const chunks = getChunkNames(output);
expect(chunks.some((name) => name.includes('remoteEntry'))).toBe(true);
});
it('remoteEntry contains federation runtime init with correct name', async () => {
const output = await buildFixture({ mfOptions: BASIC_REMOTE_MF_OPTIONS });
const remoteEntry = findChunk(output, 'remoteEntry');
expect(remoteEntry).toBeDefined();
expect(remoteEntry!.code).toContain('basicRemote');
expect(remoteEntry!.code).toContain('moduleCache');
});
it('exposed module content is included in output', async () => {
const output = await buildFixture({ mfOptions: BASIC_REMOTE_MF_OPTIONS });
const allCode = getAllChunkCode(output);
expect(allCode).toContain('Hello');
});
it('generates mf-manifest.json when manifest is enabled', async () => {
const manifestOutput = await buildFixture({
mfOptions: { ...BASIC_REMOTE_MF_OPTIONS, manifest: true },
});
const manifest = findAsset(manifestOutput, 'mf-manifest.json');
expect(manifest).toBeDefined();
const parsed = JSON.parse(manifest!.source as string);
expect(parsed).toHaveProperty('exposes');
});
});
});