@@ -10,6 +10,7 @@ import {
10
10
promisifiedTreeKill ,
11
11
killPort ,
12
12
killPorts ,
13
+ DEFAULT_E2E_TIMEOUT ,
13
14
} from '@qwikifiers/e2e/utils' ;
14
15
import { normalize } from 'path' ;
15
16
@@ -31,89 +32,102 @@ describe('qwikNxVite plugin e2e', () => {
31
32
const appProject = uniq ( 'qwik-nx' ) ;
32
33
const libProject = uniq ( 'qwik-nx' ) ;
33
34
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 ) ;
48
35
49
36
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' ) ;
51
47
} ) ;
52
48
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' ) ;
54
59
} ) ;
55
60
56
61
describe ( 'Generating a new library with storybook configuration' , ( ) => {
57
62
beforeAll ( async ( ) => {
58
63
await runNxCommandAsync (
59
64
`generate qwik-nx:library ${ secondLibProject } --storybookConfiguration=true --no-interactive`
60
65
) ;
61
- } , 200000 ) ;
62
- checkStorybookIsBuiltAndServed ( secondLibProject , 'libs' , true ) ;
66
+ await addAdditionalStories ( secondLibProject ) ;
67
+ } , DEFAULT_E2E_TIMEOUT ) ;
68
+ checkStorybookIsBuiltAndServed ( secondLibProject , 'libs' ) ;
63
69
} ) ;
64
70
} ) ;
65
71
} ) ;
66
72
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
+
67
82
function checkStorybookIsBuiltAndServed (
68
83
projectName : string ,
69
- type : 'apps' | 'libs' ,
70
- hasTsStories : boolean
84
+ type : 'apps' | 'libs'
71
85
) {
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
+ ) ;
81
99
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 ;
93
115
}
94
- return false ;
95
- }
96
- ) ;
116
+ ) ;
97
117
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` ) ;
102
119
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.
108
121
expect ( resultOutput ) . toContain (
109
- `No story files found for the specified pattern: ${ storiesPattern } `
122
+ `No story files found for the specified pattern: ${ mdxPattern } `
110
123
) ;
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
+ ) ;
119
133
}
0 commit comments