Skip to content

Commit c4cba1c

Browse files
isaacplmannFrozenPandaz
authored andcommitted
fix(nx): update storybook configuration (#2104)
1 parent 093e693 commit c4cba1c

File tree

7 files changed

+235
-21
lines changed

7 files changed

+235
-21
lines changed

e2e/storybook.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ forEachCli(() => {
129129
`
130130
);
131131

132-
expect(
133-
runCLI(`run ${mylib}-e2e:e2e --configuration=headless --no-watch`)
134-
).toContain('All specs passed!');
132+
expect(runCLI(`run ${mylib}-e2e:e2e --no-watch`)).toContain(
133+
'All specs passed!'
134+
);
135135
}, 1000000);
136136
});
137137
}

packages/storybook/migrations.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
{
2-
"schematics": {}
2+
"schematics": {
3+
"update-builder-8.8.2": {
4+
"version": "8.8.2",
5+
"description": "Update storybook builder and tsconfig",
6+
"factory": "./src/migrations/update-8-8-2/update-builder-8-8-2"
7+
}
8+
}
39
}
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
import { Tree } from '@angular-devkit/schematics';
2+
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
3+
import {
4+
updateJsonInTree,
5+
readJsonInTree,
6+
updateWorkspaceInTree,
7+
readWorkspace,
8+
getWorkspacePath
9+
} from '@nrwl/workspace';
10+
11+
import * as path from 'path';
12+
13+
describe('Update 8-8-2', () => {
14+
let tree: Tree;
15+
let schematicRunner: SchematicTestRunner;
16+
17+
beforeEach(async () => {
18+
tree = Tree.empty();
19+
schematicRunner = new SchematicTestRunner(
20+
'@nrwl/storybook',
21+
path.join(__dirname, '../../../migrations.json')
22+
);
23+
});
24+
25+
it(`should remove headless/watch as options for e2e builder`, async () => {
26+
tree.create(
27+
'workspace.json',
28+
JSON.stringify({
29+
projects: {
30+
['home-ui']: {
31+
projectType: 'library',
32+
root: 'libs/home/ui',
33+
sourceRoot: 'libs/home/ui/src',
34+
prefix: 'app',
35+
architect: {
36+
storybook: {
37+
builder: '@nrwl/storybook:storybook',
38+
options: {
39+
uiFramework: '@storybook/angular',
40+
port: 4400,
41+
config: {
42+
configFolder: 'libs/home/ui/.storybook'
43+
}
44+
}
45+
}
46+
}
47+
},
48+
['home-ui-e2e']: {
49+
root: 'apps/home-ui-e2e',
50+
sourceRoot: 'apps/home-ui-e2e/src',
51+
architect: {
52+
e2e: {
53+
builder: '@nrwl/cypress:cypress',
54+
options: {
55+
cypressConfig: 'apps/home-ui-e2e/cypress.json',
56+
tsConfig: 'apps/home-ui-e2e/tsconfig.e2e.json',
57+
devServerTarget: 'home-ui:storybook',
58+
headless: false,
59+
watch: true
60+
},
61+
configurations: {
62+
headless: {
63+
devServerTarget: 'home-ui:storybook:ci',
64+
headless: true
65+
}
66+
}
67+
}
68+
}
69+
}
70+
}
71+
})
72+
);
73+
74+
tree = await schematicRunner
75+
.runSchematicAsync('update-builder-8.8.2', {}, tree)
76+
.toPromise();
77+
78+
const config = readWorkspace(tree);
79+
expect(
80+
config.projects['home-ui-e2e'].architect.e2e.options.headless
81+
).toBeUndefined();
82+
expect(
83+
config.projects['home-ui-e2e'].architect.e2e.options.watch
84+
).toBeUndefined();
85+
expect(
86+
config.projects['home-ui-e2e'].architect.e2e.configurations
87+
).toBeUndefined();
88+
});
89+
90+
it(`should add emitDecoratorMetadata to storybook tsconfig.json`, async () => {
91+
tree.create(
92+
'libs/home/ui/.storybook/tsconfig.json',
93+
JSON.stringify({
94+
extends: '../tsconfig.json',
95+
exclude: ['../src/test.ts', '../**/*.spec.ts'],
96+
include: ['../src/**/*']
97+
})
98+
);
99+
tree.create(
100+
'workspace.json',
101+
JSON.stringify({
102+
projects: {
103+
['home-ui']: {
104+
projectType: 'library',
105+
root: 'libs/home/ui',
106+
sourceRoot: 'libs/home/ui/src',
107+
prefix: 'app',
108+
architect: {
109+
storybook: {
110+
builder: '@nrwl/storybook:storybook',
111+
options: {
112+
uiFramework: '@storybook/angular',
113+
port: 4400,
114+
config: {
115+
configFolder: 'libs/home/ui/.storybook'
116+
}
117+
}
118+
}
119+
}
120+
},
121+
['home-ui-e2e']: {
122+
root: 'apps/home-ui-e2e',
123+
sourceRoot: 'apps/home-ui-e2e/src',
124+
architect: {
125+
e2e: {
126+
builder: '@nrwl/cypress:cypress',
127+
options: {
128+
cypressConfig: 'apps/home-ui-e2e/cypress.json',
129+
tsConfig: 'apps/home-ui-e2e/tsconfig.e2e.json',
130+
devServerTarget: 'home-ui:storybook',
131+
headless: false,
132+
watch: true
133+
},
134+
configurations: {
135+
headless: {
136+
devServerTarget: 'home-ui:storybook:ci',
137+
headless: true
138+
}
139+
}
140+
}
141+
}
142+
}
143+
}
144+
})
145+
);
146+
147+
tree = await schematicRunner
148+
.runSchematicAsync('update-builder-8.8.2', {}, tree)
149+
.toPromise();
150+
151+
const tsconfig = readJsonInTree(
152+
tree,
153+
'libs/home/ui/.storybook/tsconfig.json'
154+
);
155+
expect(tsconfig.compilerOptions.emitDecoratorMetadata).toBe(true);
156+
});
157+
});
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { Rule, chain } from '@angular-devkit/schematics';
2+
import {
3+
updateWorkspaceInTree,
4+
readWorkspaceJson,
5+
readWorkspace,
6+
updateJsonInTree
7+
} from '@nrwl/workspace';
8+
9+
export default function update(): Rule {
10+
return chain([
11+
updateWorkspaceInTree(config => {
12+
const filteredProjects = [];
13+
Object.keys(config.projects).forEach(name => {
14+
if (
15+
config.projects[name].architect &&
16+
config.projects[name].architect.e2e &&
17+
config.projects[name].architect.e2e.builder ===
18+
'@nrwl/cypress:cypress' &&
19+
config.projects[name].architect.e2e.options.devServerTarget.endsWith(
20+
':storybook'
21+
)
22+
) {
23+
filteredProjects.push(config.projects[name]);
24+
}
25+
});
26+
filteredProjects.forEach(p => {
27+
delete p.architect.e2e.options.headless;
28+
delete p.architect.e2e.options.watch;
29+
delete p.architect.e2e.configurations;
30+
});
31+
return config;
32+
}),
33+
(tree, context) => {
34+
const workspace = readWorkspace(tree);
35+
const tsconfigUpdateRules = [];
36+
Object.keys(workspace.projects).forEach(name => {
37+
if (
38+
workspace.projects[name].architect &&
39+
workspace.projects[name].architect.storybook &&
40+
workspace.projects[name].architect.storybook.builder ===
41+
'@nrwl/storybook:storybook' &&
42+
workspace.projects[name].architect.storybook.options.config
43+
.configFolder
44+
) {
45+
const storybookFolderPath =
46+
workspace.projects[name].architect.storybook.options.config
47+
.configFolder;
48+
tsconfigUpdateRules.push(
49+
updateJsonInTree(`${storybookFolderPath}/tsconfig.json`, json => ({
50+
...json,
51+
compilerOptions: {
52+
emitDecoratorMetadata: true
53+
}
54+
}))
55+
);
56+
}
57+
});
58+
return chain(tsconfigUpdateRules);
59+
}
60+
]);
61+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"emitDecoratorMetadata": true
5+
},
36
"exclude": ["../src/test.ts", "../**/*.spec.ts"],
47
"include": ["../src/**/*"]
58
}

packages/storybook/src/schematics/cypress-project/cypress-project.spec.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,8 @@ describe('schematic:cypress-project', () => {
3535
expect(project.architect.e2e.options.devServerTarget).toEqual(
3636
'test-ui-lib:storybook'
3737
);
38-
expect(project.architect.e2e.options.headless).toEqual(false);
39-
expect(project.architect.e2e.options.watch).toEqual(true);
40-
expect(
41-
project.architect.e2e.configurations.headless.devServerTarget
42-
).toEqual('test-ui-lib:storybook:ci');
43-
expect(project.architect.e2e.configurations.headless.headless).toEqual(
44-
true
45-
);
38+
expect(project.architect.e2e.options.headless).toBeUndefined();
39+
expect(project.architect.e2e.options.watch).toBeUndefined();
40+
expect(project.architect.e2e.configurations.headless).toBeUndefined();
4641
});
4742
});

packages/storybook/src/schematics/cypress-project/cypress-project.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,7 @@ function updateAngularJsonBuilder(
7575
...e2eTarget,
7676
options: <any>{
7777
...e2eTarget.options,
78-
devServerTarget: `${targetProjectName}:storybook`,
79-
headless: false,
80-
watch: true
81-
},
82-
configurations: <any>{
83-
headless: {
84-
devServerTarget: `${targetProjectName}:storybook:ci`,
85-
headless: true
86-
}
78+
devServerTarget: `${targetProjectName}:storybook`
8779
}
8880
};
8981
return workspace;

0 commit comments

Comments
 (0)