-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathis-manifest-available.test.ts
More file actions
118 lines (115 loc) · 3.97 KB
/
is-manifest-available.test.ts
File metadata and controls
118 lines (115 loc) · 3.97 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { describe, it, expect, vi } from 'vitest';
import { getManifestStatus } from './is-manifest-available.ts';
import type { Options } from 'storybook/internal/types';
function createMockOptions({
featureFlag = false,
featureFlagName = 'componentsManifest' as 'componentsManifest' | 'experimentalComponentsManifest',
hasManifests = false,
hasLegacyComponentManifestGenerator = false,
hasFeaturesObject = true,
}: {
featureFlag?: boolean;
featureFlagName?: 'componentsManifest' | 'experimentalComponentsManifest';
hasManifests?: boolean;
hasLegacyComponentManifestGenerator?: boolean;
hasFeaturesObject?: boolean;
} = {}): Options {
return {
presets: {
apply: vi.fn(async (key: string) => {
if (key === 'features') {
return hasFeaturesObject ? { [featureFlagName]: featureFlag } : {};
}
if (key === 'experimental_manifests') {
return hasManifests ? { components: { v: 1, components: {} } } : undefined;
}
if (key === 'experimental_componentManifestGenerator') {
return hasLegacyComponentManifestGenerator ? vi.fn() : undefined;
}
return undefined;
}),
},
} as unknown as Options;
}
describe('getManifestStatus', () => {
it.each([
{
description: 'both feature flag and manifests are present',
options: { featureFlag: true, hasManifests: true },
expected: { available: true, hasManifests: true, hasFeatureFlag: true },
},
{
description: 'both feature flag and legacy component manifest generator are present',
options: { featureFlag: true, hasLegacyComponentManifestGenerator: true },
expected: { available: true, hasManifests: true, hasFeatureFlag: true },
},
{
description: 'missing manifests (unsupported framework)',
options: { featureFlag: true, hasManifests: false },
expected: { available: false, hasManifests: false, hasFeatureFlag: true },
},
{
description: 'missing feature flag',
options: { featureFlag: false, hasManifests: true },
expected: { available: false, hasManifests: true, hasFeatureFlag: false },
},
{
description: 'both are missing',
options: { featureFlag: false, hasManifests: false },
expected: {
available: false,
hasManifests: false,
hasFeatureFlag: false,
},
},
{
description: 'features object is missing the flag',
options: { hasManifests: true, hasFeaturesObject: false },
expected: { available: false, hasManifests: true, hasFeatureFlag: false },
},
{
description: 'legacy experimentalComponentsManifest flag is true (backwards compat)',
options: {
featureFlag: true,
featureFlagName: 'experimentalComponentsManifest' as const,
hasManifests: true,
},
expected: { available: true, hasManifests: true, hasFeatureFlag: true },
},
{
description: 'legacy experimentalComponentsManifest flag is false (backwards compat)',
options: {
featureFlag: false,
featureFlagName: 'experimentalComponentsManifest' as const,
hasManifests: true,
},
expected: { available: false, hasManifests: true, hasFeatureFlag: false },
},
])('should return correct status when $description', async ({ options, expected }) => {
const mockOptions = createMockOptions(options);
const result = await getManifestStatus(mockOptions);
expect(result).toEqual(expected);
});
it('should correctly detect no manifests when components are not present in experimental_manifests', async () => {
// the `manifests` preset can be present but without manifests.components, because `addon-docs` sets manifests.docs
const result = await getManifestStatus({
presets: {
apply: vi.fn(async (key: string) => {
if (key === 'features') {
return { componentsManifest: true };
}
if (key === 'experimental_manifests') {
// addon-docs has set manifests.docs, but there are no actual component manifests
return { docs: { v: 1, docs: {} } };
}
return undefined;
}),
},
} as unknown as Options);
expect(result).toEqual({
available: false,
hasManifests: false,
hasFeatureFlag: true,
});
});
});