Skip to content

Commit c2047c3

Browse files
feat(qwik-nx): default export option for component generator (#123)
1 parent d3a3c8b commit c2047c3

File tree

16 files changed

+919
-102
lines changed

16 files changed

+919
-102
lines changed

e2e/qwik-nx-e2e/tests/storybook.spec.ts

Lines changed: 75 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
promisifiedTreeKill,
1111
killPort,
1212
killPorts,
13+
DEFAULT_E2E_TIMEOUT,
1314
} from '@qwikifiers/e2e/utils';
1415
import { normalize } from 'path';
1516

@@ -31,89 +32,102 @@ describe('qwikNxVite plugin e2e', () => {
3132
const appProject = uniq('qwik-nx');
3233
const libProject = uniq('qwik-nx');
3334
const secondLibProject = uniq('qwik-nx');
34-
beforeAll(async () => {
35-
await runNxCommandAsync(
36-
`generate qwik-nx:app ${appProject} --e2eTestRunner=none --no-interactive`
37-
);
38-
await runNxCommandAsync(
39-
`generate qwik-nx:library ${libProject} --no-interactive`
40-
);
41-
await runNxCommandAsync(
42-
`generate qwik-nx:storybook-configuration ${appProject} --no-interactive`
43-
);
44-
await runNxCommandAsync(
45-
`generate qwik-nx:storybook-configuration ${libProject} --no-interactive`
46-
);
47-
}, 200000);
4835

4936
describe('Applying storybook for existing application', () => {
50-
checkStorybookIsBuiltAndServed(appProject, 'apps', false);
37+
beforeAll(async () => {
38+
await runNxCommandAsync(
39+
`generate qwik-nx:app ${appProject} --e2eTestRunner=none --no-interactive`
40+
);
41+
await runNxCommandAsync(
42+
`generate qwik-nx:storybook-configuration ${appProject} --no-interactive`
43+
);
44+
await addAdditionalStories(appProject);
45+
}, DEFAULT_E2E_TIMEOUT);
46+
checkStorybookIsBuiltAndServed(appProject, 'apps');
5147
});
5248
describe('Applying storybook for existing library', () => {
53-
checkStorybookIsBuiltAndServed(libProject, 'libs', false);
49+
beforeAll(async () => {
50+
await runNxCommandAsync(
51+
`generate qwik-nx:library ${libProject} --no-interactive`
52+
);
53+
await runNxCommandAsync(
54+
`generate qwik-nx:storybook-configuration ${libProject} --no-interactive`
55+
);
56+
await addAdditionalStories(libProject);
57+
}, DEFAULT_E2E_TIMEOUT);
58+
checkStorybookIsBuiltAndServed(libProject, 'libs');
5459
});
5560

5661
describe('Generating a new library with storybook configuration', () => {
5762
beforeAll(async () => {
5863
await runNxCommandAsync(
5964
`generate qwik-nx:library ${secondLibProject} --storybookConfiguration=true --no-interactive`
6065
);
61-
}, 200000);
62-
checkStorybookIsBuiltAndServed(secondLibProject, 'libs', true);
66+
await addAdditionalStories(secondLibProject);
67+
}, DEFAULT_E2E_TIMEOUT);
68+
checkStorybookIsBuiltAndServed(secondLibProject, 'libs');
6369
});
6470
});
6571
});
6672

73+
async function addAdditionalStories(projectName: string): Promise<void> {
74+
await runNxCommandAsync(
75+
`generate qwik-nx:component mycomponent --project=${projectName} --generateStories --no-interactive`
76+
);
77+
await runNxCommandAsync(
78+
`generate qwik-nx:component mydefaultcomponent --project=${projectName} --generateStories --exportDefault --no-interactive`
79+
);
80+
}
81+
6782
function checkStorybookIsBuiltAndServed(
6883
projectName: string,
69-
type: 'apps' | 'libs',
70-
hasTsStories: boolean
84+
type: 'apps' | 'libs'
7185
) {
72-
it(`should be able to build storybook for the "${projectName}"`, async () => {
73-
const result = await runNxCommandAsync(`build-storybook ${projectName}`);
74-
expect(result.stdout).toContain(
75-
`Successfully ran target build-storybook for project ${projectName}`
76-
);
77-
expect(() =>
78-
checkFilesExist(`dist/storybook/${projectName}/index.html`)
79-
).not.toThrow();
80-
}, 200000);
86+
it(
87+
`should be able to build storybook for the "${projectName}"`,
88+
async () => {
89+
const result = await runNxCommandAsync(`build-storybook ${projectName}`);
90+
expect(result.stdout).toContain(
91+
`Successfully ran target build-storybook for project ${projectName}`
92+
);
93+
expect(() =>
94+
checkFilesExist(`dist/storybook/${projectName}/index.html`)
95+
).not.toThrow();
96+
},
97+
DEFAULT_E2E_TIMEOUT
98+
);
8199

82-
it(`should serve storybook for the "${projectName}"`, async () => {
83-
let resultOutput: string | undefined;
84-
const p = await runCommandUntil(
85-
`run ${projectName}:storybook`,
86-
(output) => {
87-
if (
88-
output.includes('Local:') &&
89-
output.includes(`:${STORYBOOK_PORT}`)
90-
) {
91-
resultOutput = output;
92-
return true;
100+
it(
101+
`should serve storybook for the "${projectName}"`,
102+
async () => {
103+
let resultOutput: string | undefined;
104+
const p = await runCommandUntil(
105+
`run ${projectName}:storybook`,
106+
(output) => {
107+
if (
108+
output.includes('Local:') &&
109+
output.includes(`:${STORYBOOK_PORT}`)
110+
) {
111+
resultOutput = output;
112+
return true;
113+
}
114+
return false;
93115
}
94-
return false;
95-
}
96-
);
116+
);
97117

98-
const mdxPattern = normalize(`${type}/${projectName}/**/*.stories.mdx`);
99-
const storiesPattern = normalize(
100-
`${type}/${projectName}/**/*.stories.@(js|jsx|ts|tsx)`
101-
);
118+
const mdxPattern = normalize(`${type}/${projectName}/**/*.stories.mdx`);
102119

103-
// it is expected that projects won't have stories by default and storybook should recognize it.
104-
expect(resultOutput).toContain(
105-
`No story files found for the specified pattern: ${mdxPattern}`
106-
);
107-
if (!hasTsStories) {
120+
// it is expected that projects won't have stories by default and storybook should recognize it.
108121
expect(resultOutput).toContain(
109-
`No story files found for the specified pattern: ${storiesPattern}`
122+
`No story files found for the specified pattern: ${mdxPattern}`
110123
);
111-
}
112-
try {
113-
await promisifiedTreeKill(p.pid!, 'SIGKILL');
114-
await killPort(STORYBOOK_PORT);
115-
} catch {
116-
// ignore
117-
}
118-
}, 200000);
124+
try {
125+
await promisifiedTreeKill(p.pid!, 'SIGKILL');
126+
await killPort(STORYBOOK_PORT);
127+
} catch {
128+
// ignore
129+
}
130+
},
131+
DEFAULT_E2E_TIMEOUT
132+
);
119133
}

packages/qwik-nx/src/generators/application/generator.spec.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Tree, readProjectConfiguration } from '@nrwl/devkit';
44
import generator from './generator';
55
import { QwikAppGeneratorSchema } from './schema';
66
import { Linter } from '@nrwl/linter';
7+
import { getFormattedListChanges } from './../../utils/testing-generators';
78

89
// eslint-disable-next-line @typescript-eslint/no-var-requires
910
const devkit = require('@nrwl/devkit');
@@ -38,11 +39,7 @@ describe('qwik-nx generator', () => {
3839
appTree.read('apps/myapp/vite.config.ts', 'utf-8')
3940
).toMatchSnapshot();
4041
expect(appTree.read('apps/myapp/project.json', 'utf-8')).toMatchSnapshot();
41-
expect(
42-
[...appTree.listChanges()]
43-
.sort((a, b) => a.path.localeCompare(b.path))
44-
.map((c) => ({ path: c.path, type: c.type }))
45-
).toMatchSnapshot();
42+
expect(getFormattedListChanges(appTree)).toMatchSnapshot();
4643
});
4744

4845
describe('e2e project', () => {

0 commit comments

Comments
 (0)