Skip to content

Commit

Permalink
Integrate for Chromatic & Codecov
Browse files Browse the repository at this point in the history
  • Loading branch information
NEKOYASAN committed Mar 28, 2024
1 parent 3c44984 commit b4eb6a9
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 18 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/chromatic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: 'Chromatic Deployment'

on:
pull_request:
push:
branches:
- master

jobs:
chromatic:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Node
uses: actions/setup-node@v3
with:
node-version-file: .tool-versions

- name: Enable corepack
run: corepack enable

- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile

- uses: chromaui/[email protected]
with:
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}
onlyChanged: true
exitOnceUploaded: true
autoAcceptChanges: 'master'
49 changes: 49 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Test

on:
pull_request:
push:

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Node
uses: actions/setup-node@v3
with:
node-version-file: .tool-versions

- name: Enable corepack
run: corepack enable

- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Run tests and collect coverage
run: pnpm run vitest --coverage --changed

- name: Upload coverage to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: Kartore/web
1 change: 0 additions & 1 deletion .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const config: StorybookConfig = {
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-interactions',
'@storybook/addon-coverage',
'@chromatic-com/storybook',
],
build: {
Expand Down
1 change: 1 addition & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Preview } from '@storybook/react';
import '../src/index.css';

const preview: Preview = {
parameters: {
Expand Down
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 20.10.0
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"vitest": "TZ=UTC vitest",
"test": "TZ=UTC pnpm run test:unit",
"test:unit": "TZ=UTC vitest run",
"test:changed": "TZ=UTC vitest run --changed"
"test:changed": "TZ=UTC vitest run --changed",
"chromatic": "npx chromatic"
},
"dependencies": {
"@ark-ui/react": "2.2.3",
Expand All @@ -39,6 +40,7 @@
"@vitest/coverage-v8": "1.4.0",
"@vitest/ui": "1.4.0",
"autoprefixer": "10.4.19",
"chromatic": "11.2.0",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-react-hooks": "4.6.0",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions src/components/common/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { Spinner } from '~/components/common/Spinner';

const buttonVariants = tv({
slots: {
base: 'bg-gray-100 px-4 py-2 text-sm text-gray-800 transition-colors hover:bg-gray-200 dark:bg-gray-800 dark:text-white dark:hover:bg-gray-900',
base: 'relative rounded-lg bg-gray-300 px-4 py-2 text-sm text-gray-800 transition-colors hover:bg-gray-200 dark:bg-gray-800 dark:text-white dark:hover:bg-gray-900',
text: '',
spinner: '',
spinner: 'absolute inset-0 flex items-center justify-center text-[1em]',
},
variants: {
isLoading: {
true: {
base: 'pointer-events-none opacity-90',
text: 'hidden',
text: 'opacity-0',
spinner: '',
},
false: {
Expand Down Expand Up @@ -40,7 +40,9 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
return (
<button type={'button'} {...props} className={base(props)} ref={ref}>
<p className={text()}>{children}</p>
<Spinner className={spinner()} />
<div className={spinner()}>
<Spinner />
</div>
</button>
);
}
Expand Down
32 changes: 22 additions & 10 deletions src/components/common/Button/__snapshots__/Button.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,61 @@
exports[`Component: Button > Snapshot > Default 1`] = `
<DocumentFragment>
<button
class="bg-gray-100 px-4 py-2 text-sm text-gray-800 transition-colors hover:bg-gray-200 dark:bg-gray-800 dark:text-white dark:hover:bg-gray-900"
class="relative rounded-lg bg-gray-300 px-4 py-2 text-sm text-gray-800 transition-colors hover:bg-gray-200 dark:bg-gray-800 dark:text-white dark:hover:bg-gray-900"
type="button"
>
<p>
Button
</p>
<div
class="h-10 w-10 animate-spin rounded-full border-4 border-current border-r-transparent border-t-transparent animation-duration-[600ms] hidden"
/>
class="absolute inset-0 items-center justify-center text-[1em] hidden"
>
<div
class="inline-block aspect-square h-[1em] w-[1em] animate-spin rounded-full border-[0.2em] border-current border-r-transparent border-t-transparent animation-duration-[600ms]"
/>
</div>
</button>
</DocumentFragment>
`;

exports[`Component: Button > Snapshot > Disabled 1`] = `
<DocumentFragment>
<button
class="bg-gray-100 px-4 py-2 text-sm text-gray-800 transition-colors hover:bg-gray-200 dark:bg-gray-800 dark:text-white dark:hover:bg-gray-900 pointer-events-none opacity-70"
class="relative rounded-lg bg-gray-300 px-4 py-2 text-sm text-gray-800 transition-colors hover:bg-gray-200 dark:bg-gray-800 dark:text-white dark:hover:bg-gray-900 pointer-events-none opacity-70"
type="button"
>
<p>
Button
</p>
<div
class="h-10 w-10 animate-spin rounded-full border-4 border-current border-r-transparent border-t-transparent animation-duration-[600ms] hidden"
/>
class="absolute inset-0 items-center justify-center text-[1em] hidden"
>
<div
class="inline-block aspect-square h-[1em] w-[1em] animate-spin rounded-full border-[0.2em] border-current border-r-transparent border-t-transparent animation-duration-[600ms]"
/>
</div>
</button>
</DocumentFragment>
`;

exports[`Component: Button > Snapshot > Loading 1`] = `
<DocumentFragment>
<button
class="bg-gray-100 px-4 py-2 text-sm text-gray-800 transition-colors hover:bg-gray-200 dark:bg-gray-800 dark:text-white dark:hover:bg-gray-900 pointer-events-none opacity-90"
class="relative rounded-lg bg-gray-300 px-4 py-2 text-sm text-gray-800 transition-colors hover:bg-gray-200 dark:bg-gray-800 dark:text-white dark:hover:bg-gray-900 pointer-events-none opacity-90"
type="button"
>
<p
class="hidden"
class="opacity-0"
>
Button
</p>
<div
class="inline-block h-10 w-10 animate-spin rounded-full border-4 border-current border-r-transparent border-t-transparent animation-duration-[600ms]"
/>
class="absolute inset-0 flex items-center justify-center text-[1em]"
>
<div
class="inline-block aspect-square h-[1em] w-[1em] animate-spin rounded-full border-[0.2em] border-current border-r-transparent border-t-transparent animation-duration-[600ms]"
/>
</div>
</button>
</DocumentFragment>
`;
2 changes: 1 addition & 1 deletion src/components/common/Spinner/Spinner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ComponentPropsWithoutRef, forwardRef } from 'react';
import { tv, VariantProps } from 'tailwind-variants';

const spinnerVariant = tv({
base: 'inline-block h-10 w-10 animate-spin rounded-full border-4 border-current border-r-transparent border-t-transparent animation-duration-[600ms]',
base: 'inline-block aspect-square h-[1em] w-[1em] animate-spin rounded-full border-[0.2em] border-current border-r-transparent border-t-transparent animation-duration-[600ms]',
variants: {},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`Component: Spinner > Snapshot > Default 1`] = `
<DocumentFragment>
<div
class="inline-block h-10 w-10 animate-spin rounded-full border-4 border-current border-r-transparent border-t-transparent animation-duration-[600ms]"
class="inline-block aspect-square h-[1em] w-[1em] animate-spin rounded-full border-[0.2em] border-current border-r-transparent border-t-transparent animation-duration-[600ms]"
/>
</DocumentFragment>
`;

0 comments on commit b4eb6a9

Please sign in to comment.