/
storybook.impl.spec.ts
86 lines (80 loc) · 2.46 KB
/
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
import { fs as fsMock, vol } from 'memfs';
import * as fs from 'fs';
import { ExecutorContext } from '@nrwl/devkit';
jest.mock('@storybook/core-server', () => ({
buildDevStandalone: jest.fn().mockImplementation(() => Promise.resolve()),
}));
import { buildDevStandalone } from '@storybook/core-server';
import storybookExecutor, { StorybookExecutorOptions } from './storybook.impl';
import { join } from 'path';
import { readFileSync } from 'fs-extra';
describe('@nrwl/storybook:storybook', () => {
let context: ExecutorContext;
let options: StorybookExecutorOptions;
beforeEach(() => {
// preserve original package.json file to memory
const rootPath = join(__dirname, `../../../../../`);
const packageJsonPath = join(
rootPath,
`node_modules/@storybook/angular/package.json`
);
const storybookPath = join(rootPath, '.storybook');
options = {
uiFramework: '@storybook/angular',
port: 4400,
projectBuildConfig: 'proj',
config: {
configFolder: storybookPath,
},
};
vol.fromJSON({
[packageJsonPath]: readFileSync(packageJsonPath).toString(),
});
vol.mkdirSync(storybookPath, {
recursive: true,
});
context = {
root: rootPath,
cwd: rootPath,
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:storybook',
options,
},
},
},
},
defaultProject: 'proj',
npmScope: 'test',
},
isVerbose: false,
};
jest.mock('fs', () => fsMock);
jest.spyOn(fs, 'statSync').mockReturnValue({
isDirectory: () => true,
} as fs.Stats);
});
it('should provide options to storybook', async () => {
const iterator = storybookExecutor(options, context);
const { value } = await iterator.next();
expect(value).toEqual({ success: true });
expect(buildDevStandalone).toHaveBeenCalled();
});
});