-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
build-storybook.impl.spec.ts
98 lines (91 loc) · 2.84 KB
/
build-storybook.impl.spec.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
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
import { ExecutorContext, logger } from '@nrwl/devkit';
import { join } from 'path';
jest.mock('@storybook/core/standalone', () =>
jest.fn().mockImplementation(() => Promise.resolve())
);
import * as storybook from '@storybook/core/standalone';
import storybookBuilder, {
StorybookBuilderOptions,
} from './build-storybook.impl';
describe('Build storybook', () => {
let context: ExecutorContext;
let options: StorybookBuilderOptions;
let uiFramework: StorybookBuilderOptions['uiFramework'];
let outputPath: StorybookBuilderOptions['outputPath'];
let config: StorybookBuilderOptions['config'];
beforeEach(async () => {
uiFramework = '@storybook/react';
outputPath = '/root/dist/storybook';
config = {
pluginPath: join(
__dirname,
`/../../generators/configuration/root-files/.storybook/main.js`
),
configFolder: join(
__dirname,
`/../../generators/configuration/root-files/.storybook`
),
srcRoot: join(
__dirname,
`/../../generators/configuration/root-files/.storybook/tsconfig.json`
),
};
options = {
uiFramework,
outputPath,
config,
};
context = {
root: '/root',
cwd: '/root',
projectName: 'proj',
targetName: 'storybook',
workspace: {
version: 2,
projects: {
proj: {
root: '',
sourceRoot: 'src',
targets: {
build: {
executor: '@nrwl/web:webpack',
options: {
compiler: 'babel',
outputPath: 'dist/apps/webre',
index: 'apps/webre/src/index.html',
baseHref: '/',
main: 'apps/webre/src/main.tsx',
polyfills: 'apps/webre/src/polyfills.ts',
tsConfig: 'apps/webre/tsconfig.app.json',
assets: [
'apps/webre/src/favicon.ico',
'apps/webre/src/assets',
],
styles: ['apps/webre/src/styles.css'],
scripts: [],
webpackConfig: '@nrwl/react/plugins/webpack',
},
},
storybook: {
executor: '@nrwl/storybook:build-storybook',
options,
},
},
},
},
npmScope: 'test',
},
isVerbose: false,
};
});
it('should call the storybook static standalone build', async () => {
jest.spyOn(logger, 'info');
const result = await storybookBuilder(options, context);
expect(storybook).toHaveBeenCalled();
expect(logger.info).toHaveBeenCalledWith(
`NX Storybook files available in ${outputPath}`
);
expect(logger.info).toHaveBeenCalledWith(`NX ui framework: ${uiFramework}`);
expect(result.success).toBeTruthy();
});
});