-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(docz-core) handle props on windows (#1151)
* fix(docz-core): test for setting props on * fix(docz-core): use unix path for keys and fast glob * fix(docz-core): normalize and use unix path on keys in props parser * chore(docz-core): move test helpers out of test folder * chore(e2e-tests): add test for checking props * fix(docz-core): use regular path in filesmap and update e2e test
- Loading branch information
1 parent
6348cb9
commit ee71ef8
Showing
14 changed files
with
266 additions
and
24 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,28 @@ | ||
--- | ||
name: Alert | ||
menu: Components | ||
--- | ||
|
||
import { Playground, Props } from 'docz' | ||
import { Alert } from './Alert' | ||
|
||
# Alert | ||
|
||
## Properties | ||
|
||
<Props of={Alert} /> | ||
|
||
## Basic usage | ||
|
||
<Playground> | ||
<Alert>Some message</Alert> | ||
</Playground> | ||
|
||
## Using different kinds | ||
|
||
<Playground> | ||
<Alert kind="info">Some message</Alert> | ||
<Alert kind="positive">Some message</Alert> | ||
<Alert kind="negative">Some message</Alert> | ||
<Alert kind="warning">Some message</Alert> | ||
</Playground> |
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,32 @@ | ||
import React, { SFC } from 'react' | ||
import styled from '@emotion/styled' | ||
|
||
export type Kind = 'info' | 'positive' | 'negative' | 'warning' | ||
export type KindMap = Record<Kind, string> | ||
|
||
const kinds: KindMap = { | ||
info: '#5352ED', | ||
positive: '#2ED573', | ||
negative: '#FF4757', | ||
warning: '#FFA502', | ||
} | ||
|
||
export interface AlertProps { | ||
/** | ||
* Set this to change alert kind | ||
* @default info | ||
*/ | ||
kind: 'info' | 'positive' | 'negative' | 'warning' | ||
} | ||
|
||
const AlertStyled = styled('div')<AlertProps>` | ||
padding: 15px 20px; | ||
background: white; | ||
border-radius: 3px; | ||
color: white; | ||
background: ${({ kind = 'info' }) => kinds[kind]}; | ||
` | ||
|
||
export const Alert: SFC<AlertProps> = ({ kind, ...props }) => ( | ||
<AlertStyled {...props} kind={kind} /> | ||
) |
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 React from 'react' | ||
import t from 'prop-types' | ||
|
||
const Label = ({ text, ...props }) => ( | ||
<div className="label" {...props}> | ||
{text} | ||
</div> | ||
) | ||
|
||
Label.propTypes = { | ||
/** A nice string */ | ||
text: t.string, | ||
} | ||
|
||
export default Label |
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,17 @@ | ||
import React, { SFC } from 'react' | ||
|
||
export interface LabelProps { | ||
/** | ||
* Set this to do the thing | ||
* @default info | ||
*/ | ||
text: string | ||
} | ||
|
||
const Label: SFC<LabelProps> = ({ text, ...props }) => ( | ||
<div className="label" {...props}> | ||
{text} | ||
</div> | ||
) | ||
|
||
export default Label |
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 { Entries } from '../src/lib/Entries' | ||
import { getTestConfig } from '../src/test-utils' | ||
|
||
describe('Entries', () => { | ||
test('get entries', async () => { | ||
const config = getTestConfig() | ||
const entries = new Entries(config) | ||
expect(entries).toBeTruthy() | ||
}) | ||
}) |
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,86 @@ | ||
import * as fs from 'fs-extra' | ||
import { getPattern, initial } from '../src/states/props' | ||
import { readCacheFile } from '../src/utils/docgen/typescript' | ||
import { getTestConfig, mockedParams } from '../src/test-utils' | ||
|
||
describe('props', () => { | ||
beforeEach(() => { | ||
if (fs.existsSync('./.docz/.cache/propsParser.json')) { | ||
fs.unlinkSync('./.docz/.cache/propsParser.json') | ||
} | ||
}) | ||
|
||
describe('typescript', () => { | ||
test('should set props from typescript files', async () => { | ||
const config = getTestConfig() | ||
const pattern = getPattern(config) | ||
const data = initial(config, pattern) | ||
const params = mockedParams() | ||
await data(params) | ||
expect(params.getState().props.length).toBeGreaterThan(0) | ||
}) | ||
|
||
test('should set correct key on parsed typescript files', async () => { | ||
const config = getTestConfig() | ||
const pattern = getPattern(config) | ||
const data = initial(config, pattern) | ||
const params = mockedParams() | ||
await data(params) | ||
const expectedFirstPropName = '__fixtures__/Label.tsx' | ||
const firstProp = params.getState().props[0] | ||
expect(firstProp.key).toEqual(expectedFirstPropName) | ||
expect(firstProp.value).toBeTruthy() | ||
}) | ||
}) | ||
|
||
describe('javascript', () => { | ||
test('should set correct key on parsed javascript files', async () => { | ||
const config = getTestConfig({ typescript: undefined }) | ||
const pattern = getPattern(config) | ||
const data = initial(config, pattern) | ||
const params = mockedParams() | ||
await data(params) | ||
const expectedFirstPropName = '__fixtures__/Label.jsx' | ||
const firstProp = params.getState().props[0] | ||
expect(firstProp.key).toEqual(expectedFirstPropName) | ||
expect(firstProp.value).toBeTruthy() | ||
}) | ||
|
||
test('should set props from javascript files', async () => { | ||
const config = getTestConfig({ typescript: undefined }) | ||
const pattern = getPattern(config) | ||
const data = initial(config, pattern) | ||
const params = mockedParams() | ||
await data(params) | ||
expect(params.getState().props.length).toBeGreaterThan(0) | ||
}) | ||
|
||
test('should have props on javascript files', async () => { | ||
const config = getTestConfig({ typescript: undefined }) | ||
const pattern = getPattern(config) | ||
const data = initial(config, pattern) | ||
const params = mockedParams() | ||
await data(params) | ||
const firstProp = params.getState().props[0] | ||
expect(firstProp.value[0].props).toBeTruthy() | ||
}) | ||
}) | ||
|
||
describe('cache', () => { | ||
test('should have empty cache on start', async () => { | ||
const cache = readCacheFile() | ||
expect(cache).toBeNull() | ||
}) | ||
|
||
test('should set cache on loading props', async () => { | ||
const cache = readCacheFile() | ||
expect(cache).toBeNull() | ||
const config = getTestConfig() | ||
const pattern = getPattern(config) | ||
const data = initial(config, pattern) | ||
const params = mockedParams() | ||
await data(params) | ||
expect(readCacheFile()).not.toBeNull() | ||
}) | ||
}) | ||
}) |
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,38 @@ | ||
import * as paths from '../config/paths' | ||
import yargs from 'yargs' | ||
import { setArgs, Config } from '../config/argv' | ||
import { Params } from '../lib/DataServer' | ||
import { getBaseConfig } from '../config/docz' | ||
|
||
export const mockedParams = (): Params => { | ||
let data: any = {} | ||
return { | ||
getState: () => data, | ||
setState: (key: string, value: string) => (data[key] = value), | ||
} | ||
} | ||
|
||
export const mockedArgv = () => { | ||
const yargsArgs: any = { | ||
argv: {}, | ||
//@ts-ignore | ||
option: jest.fn().mockImplementation((key, value) => { | ||
yargs.argv[value.alias ? value.alias : key] = value.default | ||
return yargs | ||
}), | ||
} | ||
const { argv } = setArgs(yargsArgs) | ||
return argv | ||
} | ||
|
||
export const getTestConfig = (overrides?: Partial<Config>): Config => { | ||
const argv = mockedArgv() | ||
return { | ||
//@ts-ignore | ||
...getBaseConfig(argv), | ||
paths, | ||
typescript: true, | ||
src: './__fixtures__', | ||
...overrides, | ||
} | ||
} |
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
Oops, something went wrong.