-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add storybook config fixture (#786)
- Loading branch information
Showing
12 changed files
with
188 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# managed by sku | ||
*.less.d.ts | ||
coverage/ | ||
dist-storybook/ | ||
dist/ | ||
report/ | ||
# end managed by sku |
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,12 @@ | ||
node_modules | ||
npm-debug.log | ||
|
||
# managed by sku | ||
.eslintrc | ||
.prettierrc | ||
coverage/ | ||
dist-storybook/ | ||
dist/ | ||
report/ | ||
tsconfig.json | ||
# end managed by sku |
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,7 @@ | ||
# managed by sku | ||
*.less.d.ts | ||
coverage/ | ||
dist-storybook/ | ||
dist/ | ||
report/ | ||
# end managed by sku |
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,14 @@ | ||
{ | ||
"name": "@sku-fixtures/storybook-config", | ||
"private": true, | ||
"dependencies": { | ||
"braid-design-system": "^31.0.0", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^17.0.2", | ||
"@types/react-dom": "^17.0.2", | ||
"sku": "workspace:*" | ||
} | ||
} |
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 @@ | ||
import type { SkuConfig } from 'sku'; | ||
|
||
const skuConfig: SkuConfig = { | ||
clientEntry: 'src/client.tsx', | ||
renderEntry: 'src/render.tsx', | ||
environments: ['development', 'production'], | ||
storybookPort: 8089, | ||
orderImports: true, | ||
}; | ||
|
||
export default skuConfig; |
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,10 @@ | ||
import 'braid-design-system/reset'; | ||
import { BraidProvider } from 'braid-design-system'; | ||
import apac from 'braid-design-system/themes/apac'; | ||
import React from 'react'; | ||
|
||
export const StorybookDecorator = ({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) => <BraidProvider theme={apac}>{children}</BraidProvider>; |
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,23 @@ | ||
import React from 'react'; | ||
import type { Meta, StoryObj } from 'sku/@storybook/react'; | ||
|
||
import { StorybookDecorator } from './StorybookDecorator'; | ||
import { TestComponent } from './TestComponent'; | ||
|
||
export default { | ||
title: 'TestComponent', | ||
component: TestComponent, | ||
decorators: [ | ||
(Story) => ( | ||
<StorybookDecorator> | ||
<Story /> | ||
</StorybookDecorator> | ||
), | ||
], | ||
} satisfies Meta; | ||
|
||
type Story = StoryObj<typeof TestComponent>; | ||
|
||
export const Default: Story = { | ||
render: () => <TestComponent tone="caution">Hello world</TestComponent>, | ||
}; |
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,15 @@ | ||
import { Card, Text } from 'braid-design-system'; | ||
import React from 'react'; | ||
|
||
type TestComponentProps = { | ||
tone: React.ComponentProps<typeof Text>['tone']; | ||
children: React.ReactNode; | ||
}; | ||
|
||
export const TestComponent = ({ children, tone }: TestComponentProps) => ( | ||
<Card> | ||
<Text tone={tone} data={{ 'automation-text': true }}> | ||
{children} | ||
</Text> | ||
</Card> | ||
); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,66 @@ | ||
const path = require('path'); | ||
const { | ||
runSkuScriptInDir, | ||
waitForUrls, | ||
startAssetServer, | ||
getStorybookContent, | ||
} = require('@sku-private/test-utils'); | ||
|
||
const appDir = path.dirname( | ||
require.resolve('@sku-fixtures/storybook-config/sku.config.ts'), | ||
); | ||
const storybookDistDir = path.resolve(appDir, 'dist-storybook'); | ||
|
||
describe('storybook-config', () => { | ||
describe('storybook', () => { | ||
const storybookUrl = 'http://localhost:8089'; | ||
let server; | ||
|
||
beforeAll(async () => { | ||
server = await runSkuScriptInDir('storybook', appDir, ['--ci']); | ||
await waitForUrls(storybookUrl); | ||
}, 200000); | ||
|
||
afterAll(async () => { | ||
await server.kill(); | ||
}); | ||
|
||
it('should start a storybook server', async () => { | ||
const { text, fontSize } = await getStorybookContent( | ||
storybookUrl, | ||
'[data-automation-text]', | ||
); | ||
expect(text).toEqual('Hello world'); | ||
expect(fontSize).toEqual('16px'); | ||
}); | ||
}); | ||
|
||
describe('build-storybook', () => { | ||
let closeStorybookServer; | ||
const assetServerPort = 4232; | ||
const assetServerUrl = `http://localhost:${assetServerPort}`; | ||
|
||
beforeAll(async () => { | ||
await runSkuScriptInDir('build-storybook', appDir); | ||
closeStorybookServer = await startAssetServer( | ||
assetServerPort, | ||
storybookDistDir, | ||
); | ||
await waitForUrls(assetServerUrl); | ||
}, 200000); | ||
|
||
afterAll(() => { | ||
closeStorybookServer(); | ||
}); | ||
|
||
it('should create valid storybook', async () => { | ||
const { text, fontSize } = await getStorybookContent( | ||
assetServerUrl, | ||
'[data-automation-text]', | ||
); | ||
|
||
expect(text).toEqual('Hello world'); | ||
expect(fontSize).toEqual('16px'); | ||
}); | ||
}); | ||
}); |