-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(storybook): added storybook 7 testing suite
- Loading branch information
Showing
9 changed files
with
434 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* eslint-disable */ | ||
export default { | ||
transform: { | ||
'^.+\\.[tj]sx?$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }], | ||
}, | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'], | ||
maxWorkers: 1, | ||
globals: {}, | ||
displayName: 'e2e-storybook-7', | ||
preset: '../../jest.preset.js', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "e2e-storybook-7", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "e2e/storybook-7", | ||
"projectType": "application", | ||
"targets": { | ||
"e2e": {}, | ||
"run-e2e-tests": {} | ||
}, | ||
"implicitDependencies": ["storybook"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import { | ||
checkFilesExist, | ||
cleanupProject, | ||
killPorts, | ||
readJson, | ||
runCLI, | ||
runCommandUntil, | ||
runCreateWorkspace, | ||
tmpProjPath, | ||
uniq, | ||
} from '@nrwl/e2e/utils'; | ||
import { writeFileSync } from 'fs'; | ||
|
||
describe('Storybook generators and executors for standalone workspaces - using React + Vite', () => { | ||
const wsName = uniq('react'); | ||
const appName = uniq('app'); | ||
|
||
beforeAll(() => { | ||
// create a workspace with a single react app at the root | ||
runCreateWorkspace(wsName, { | ||
preset: 'react-standalone', | ||
appName, | ||
style: 'css', | ||
bundler: 'vite', | ||
}); | ||
|
||
runCLI( | ||
`generate @nrwl/react:storybook-configuration ${appName} --storybook7Configuration --generateStories --no-interactive` | ||
); | ||
|
||
runCLI(`report`); | ||
}); | ||
|
||
afterAll(() => { | ||
cleanupProject(); | ||
}); | ||
|
||
describe('Storybook generated files', () => { | ||
it('should generate storybook files', () => { | ||
checkFilesExist( | ||
'.storybook/main.js', | ||
'.storybook/preview.js', | ||
'.storybook/tsconfig.json' | ||
); | ||
}); | ||
|
||
it('should edit root tsconfig.json', () => { | ||
const tsconfig = readJson(`tsconfig.json`); | ||
expect(tsconfig['ts-node']?.compilerOptions?.module).toEqual('commonjs'); | ||
}); | ||
|
||
it('should generate correct files for nested app', () => { | ||
const nestedAppName = uniq('other-app'); | ||
runCLI(`generate @nrwl/react:app ${nestedAppName} --no-interactive`); | ||
runCLI( | ||
`generate @nrwl/react:storybook-configuration ${nestedAppName} --storybook7Configuration --generateStories --no-interactive` | ||
); | ||
checkFilesExist( | ||
`apps/${nestedAppName}/.storybook/main.js`, | ||
`apps/${nestedAppName}/.storybook/tsconfig.json` | ||
); | ||
}); | ||
}); | ||
|
||
describe('serve storybook', () => { | ||
afterEach(() => killPorts()); | ||
|
||
it('should serve a React based Storybook setup that uses Vite', async () => { | ||
const p = await runCommandUntil(`run ${appName}:storybook`, (output) => { | ||
return /Storybook.*started/gi.test(output); | ||
}); | ||
p.kill(); | ||
}, 1000000); | ||
}); | ||
|
||
describe('build storybook', () => { | ||
it('should build a React based storybook that uses Vite', () => { | ||
runCLI(`run ${appName}:build-storybook --verbose`); | ||
checkFilesExist(`dist/storybook/${appName}/index.html`); | ||
}, 1000000); | ||
|
||
// This test makes sure path resolution works | ||
it('should build a React based storybook that references another lib and uses Vite', () => { | ||
const reactLib = uniq('test-lib-react'); | ||
runCLI(`generate @nrwl/react:lib ${reactLib} --no-interactive`); | ||
// create a React component we can reference | ||
writeFileSync( | ||
tmpProjPath(`${reactLib}/src/lib/mytestcmp.tsx`), | ||
` | ||
import React from 'react'; | ||
/* eslint-disable-next-line */ | ||
export interface MyTestCmpProps {} | ||
export const MyTestCmp = (props: MyTestCmpProps) => { | ||
return ( | ||
<div> | ||
<h1>Welcome to test cmp!</h1> | ||
</div> | ||
); | ||
}; | ||
export default MyTestCmp; | ||
` | ||
); | ||
// update index.ts and export it | ||
writeFileSync( | ||
tmpProjPath(`${reactLib}/src/index.ts`), | ||
` | ||
export * from './lib/mytestcmp'; | ||
` | ||
); | ||
|
||
// create a story in the first lib to reference the cmp from the 2nd lib | ||
writeFileSync( | ||
tmpProjPath(`${reactLib}/src/lib/myteststory.stories.tsx`), | ||
` | ||
import React from 'react'; | ||
import { MyTestCmp, MyTestCmpProps } from '@${wsName}/${reactLib}'; | ||
export default { | ||
component: MyTestCmp, | ||
title: 'MyTestCmp', | ||
}; | ||
export const primary = () => { | ||
/* eslint-disable-next-line */ | ||
const props: MyTestCmpProps = {}; | ||
return <MyTestCmp />; | ||
}; | ||
` | ||
); | ||
|
||
// build React lib | ||
runCLI(`run ${reactLib}:build-storybook --verbose`); | ||
checkFilesExist(`dist/storybook/${reactLib}/index.html`); | ||
}, 1000000); | ||
}); | ||
}); |
Oops, something went wrong.