/
build-storybook.impl.spec.ts
102 lines (94 loc) · 2.91 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
99
100
101
102
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';
import * as fileUtils from '@nrwl/workspace/src/core/file-utils';
describe('Build storybook', () => {
let context: ExecutorContext;
let options: StorybookBuilderOptions;
let uiFramework: StorybookBuilderOptions['uiFramework'];
let outputPath: StorybookBuilderOptions['outputPath'];
let config: StorybookBuilderOptions['config'];
beforeEach(async () => {
jest.spyOn(fileUtils, 'readPackageJson').mockReturnValue({
devDependencies: {
'@storybook/addon-essentials': '~6.2.9',
'@storybook/angular': '~6.2.9',
},
});
uiFramework = '@storybook/angular';
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,
projectBuildConfig: 'proj',
stylePreprocessorOptions: {
includePaths: ['my-path/my-style-options'],
},
styles: ['my-other-path/my-other-styles.scss'],
config,
};
context = {
root: '/root',
cwd: '/root',
projectName: 'proj',
targetName: 'storybook',
workspace: {
version: 2,
projects: {
proj: {
root: '',
sourceRoot: 'src',
targets: {
build: {
executor: '@angular-devkit/build-angular:browser',
options: {
main: 'apps/proj/src/main.ts',
outputPath: 'dist/apps/proj',
tsConfig: 'apps/proj/tsconfig.app.json',
index: 'apps/proj/src/index.html',
},
},
storybook: {
executor: '@nrwl/storybook:build-storybook',
options,
},
},
},
},
defaultProject: 'proj',
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();
});
});