/
getStorybookInfo.test.js
81 lines (69 loc) · 3.11 KB
/
getStorybookInfo.test.js
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
import getStorybookInfo from './getStorybookInfo';
const log = { warn: jest.fn() };
const context = { env: {}, log, options: {}, packageJson: {} };
const REACT = { '@storybook/react': '1.2.3' };
const VUE = { '@storybook/vue': '1.2.3' };
describe('getStorybookInfo', () => {
it('returns viewLayer and version', async () => {
const ctx = { ...context, packageJson: { dependencies: REACT } };
await expect(getStorybookInfo(ctx)).resolves.toEqual(
// We're getting the result of tracing chromatic-cli's node_modules here.
expect.objectContaining({ viewLayer: 'react', version: expect.any(String) })
);
});
it('throws on missing dependency', async () => {
await expect(getStorybookInfo(context)).rejects.toThrow('Storybook dependency not found');
});
it('warns on duplicate devDependency', async () => {
const ctx = { ...context, packageJson: { dependencies: REACT, devDependencies: REACT } };
await getStorybookInfo(ctx);
expect(log.warn).toHaveBeenCalledWith(
expect.stringContaining('both "dependencies" and "devDependencies"')
);
});
it('warns on duplicate peerDependency', async () => {
const ctx = { ...context, packageJson: { dependencies: REACT, peerDependencies: REACT } };
await getStorybookInfo(ctx);
expect(log.warn).toHaveBeenCalledWith(
expect.stringContaining('both "dependencies" and "peerDependencies"')
);
});
it('throws on missing package', async () => {
const ctx = { ...context, packageJson: { dependencies: VUE } };
await expect(getStorybookInfo(ctx)).rejects.toThrow('Storybook package not installed');
});
describe('with CHROMATIC_STORYBOOK_VERSION', () => {
it('returns viewLayer and version from env', async () => {
const ctx = { ...context, env: { CHROMATIC_STORYBOOK_VERSION: '@storybook/react@3.2.1' } };
await expect(getStorybookInfo(ctx)).resolves.toEqual(
expect.objectContaining({ viewLayer: 'react', version: '3.2.1' })
);
});
it('supports unscoped package name', async () => {
const ctx = { ...context, env: { CHROMATIC_STORYBOOK_VERSION: 'react@3.2.1' } };
await expect(getStorybookInfo(ctx)).resolves.toEqual(
expect.objectContaining({ viewLayer: 'react', version: '3.2.1' })
);
});
it('throws on invalid value', async () => {
const ctx = { ...context, env: { CHROMATIC_STORYBOOK_VERSION: '3.2.1' } };
await expect(getStorybookInfo(ctx)).rejects.toThrow('Invalid');
});
it('throws on unsupported viewlayer', async () => {
const ctx = { ...context, env: { CHROMATIC_STORYBOOK_VERSION: '@storybook/native@3.2.1' } };
await expect(getStorybookInfo(ctx)).rejects.toThrow('Unsupported');
});
});
describe('with --storybook-build-dir', () => {
it('returns viewLayer and version from packageJson', async () => {
const ctx = {
...context,
options: { storybookBuildDir: 'storybook-static' },
packageJson: { dependencies: REACT },
};
await expect(getStorybookInfo(ctx)).resolves.toEqual(
expect.objectContaining({ viewLayer: 'react', version: '1.2.3' })
);
});
});
});