|
| 1 | +import { |
| 2 | + checkFilesExist, |
| 3 | + ensureNxProject, |
| 4 | + runNxCommandAsync, |
| 5 | + uniq, |
| 6 | +} from '@nrwl/nx-plugin/testing'; |
| 7 | + |
| 8 | +import { |
| 9 | + runCommandUntil, |
| 10 | + promisifiedTreeKill, |
| 11 | + killPort, |
| 12 | + killPorts, |
| 13 | +} from '@qwikifiers/e2e/utils'; |
| 14 | + |
| 15 | +const STORYBOOK_PORT = 4400; |
| 16 | + |
| 17 | +describe('qwikNxVite plugin e2e', () => { |
| 18 | + beforeAll(async () => { |
| 19 | + await killPorts(STORYBOOK_PORT); |
| 20 | + ensureNxProject('qwik-nx', 'dist/packages/qwik-nx'); |
| 21 | + }, 10000); |
| 22 | + |
| 23 | + afterAll(async () => { |
| 24 | + // `nx reset` kills the daemon, and performs |
| 25 | + // some work which can help clean up e2e leftovers |
| 26 | + await runNxCommandAsync('reset'); |
| 27 | + }); |
| 28 | + |
| 29 | + describe('should be able to import components from libraries', () => { |
| 30 | + const appProject = uniq('qwik-nx'); |
| 31 | + const libProject = uniq('qwik-nx'); |
| 32 | + const secondLibProject = uniq('qwik-nx'); |
| 33 | + beforeAll(async () => { |
| 34 | + await runNxCommandAsync( |
| 35 | + `generate qwik-nx:app ${appProject} --e2eTestRunner=none --no-interactive` |
| 36 | + ); |
| 37 | + await runNxCommandAsync( |
| 38 | + `generate qwik-nx:library ${libProject} --no-interactive` |
| 39 | + ); |
| 40 | + await runNxCommandAsync( |
| 41 | + `generate qwik-nx:storybook-configuration ${appProject} --no-interactive` |
| 42 | + ); |
| 43 | + await runNxCommandAsync( |
| 44 | + `generate qwik-nx:storybook-configuration ${libProject} --no-interactive` |
| 45 | + ); |
| 46 | + }, 200000); |
| 47 | + |
| 48 | + describe('Applying storybook for existing application', () => { |
| 49 | + checkStorybookIsBuiltAndServed(appProject, 'apps', false); |
| 50 | + }); |
| 51 | + describe('Applying storybook for existing library', () => { |
| 52 | + checkStorybookIsBuiltAndServed(libProject, 'libs', false); |
| 53 | + }); |
| 54 | + |
| 55 | + describe('Generating a new library with storybook configuration', () => { |
| 56 | + beforeAll(async () => { |
| 57 | + await runNxCommandAsync( |
| 58 | + `generate qwik-nx:library ${secondLibProject} --storybookConfiguration=true --no-interactive` |
| 59 | + ); |
| 60 | + }, 200000); |
| 61 | + checkStorybookIsBuiltAndServed(secondLibProject, 'libs', true); |
| 62 | + }); |
| 63 | + }); |
| 64 | +}); |
| 65 | + |
| 66 | +function checkStorybookIsBuiltAndServed( |
| 67 | + projectName: string, |
| 68 | + type: 'apps' | 'libs', |
| 69 | + hasTsStories: boolean |
| 70 | +) { |
| 71 | + it(`should be able to build storybook for the "${projectName}"`, async () => { |
| 72 | + const result = await runNxCommandAsync(`build-storybook ${projectName}`); |
| 73 | + expect(result.stdout).toContain( |
| 74 | + `Successfully ran target build-storybook for project ${projectName}` |
| 75 | + ); |
| 76 | + expect(() => |
| 77 | + checkFilesExist(`dist/storybook/${projectName}/index.html`) |
| 78 | + ).not.toThrow(); |
| 79 | + }, 200000); |
| 80 | + |
| 81 | + it(`should serve storybook for the "${projectName}"`, async () => { |
| 82 | + let resultOutput: string | undefined; |
| 83 | + const p = await runCommandUntil( |
| 84 | + `run ${projectName}:storybook`, |
| 85 | + (output) => { |
| 86 | + if ( |
| 87 | + output.includes('Local:') && |
| 88 | + output.includes(`:${STORYBOOK_PORT}`) |
| 89 | + ) { |
| 90 | + resultOutput = output; |
| 91 | + return true; |
| 92 | + } |
| 93 | + return false; |
| 94 | + } |
| 95 | + ); |
| 96 | + |
| 97 | + // it is expected that projects won't have stories by default and storybook should recognize it. |
| 98 | + expect(resultOutput).toContain( |
| 99 | + `No story files found for the specified pattern: ${type}/${projectName}/**/*.stories.mdx` |
| 100 | + ); |
| 101 | + if (!hasTsStories) { |
| 102 | + expect(resultOutput).toContain( |
| 103 | + `No story files found for the specified pattern: ${type}/${projectName}/**/*.stories.@(js|jsx|ts|tsx)` |
| 104 | + ); |
| 105 | + } |
| 106 | + try { |
| 107 | + await promisifiedTreeKill(p.pid!, 'SIGKILL'); |
| 108 | + await killPort(STORYBOOK_PORT); |
| 109 | + } catch { |
| 110 | + // ignore |
| 111 | + } |
| 112 | + }, 200000); |
| 113 | +} |
0 commit comments