Skip to content

Commit 15ebdc4

Browse files
committed
fix: storybook
1 parent 49811a2 commit 15ebdc4

File tree

11 files changed

+469
-43
lines changed

11 files changed

+469
-43
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ jobs:
1212
run: yarn
1313
- name: Build
1414
run: yarn build
15+
- name: Build storybook
16+
run: yarn storybook:build

.github/workflows/storybook.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Storybook
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
concurrency:
8+
cancel-in-progress: true
9+
group: storybook-${{ github.ref }}
10+
11+
jobs:
12+
storybook:
13+
name: Deployment storybook on gh-pages
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v3
18+
- name: Get yarn cache directory path
19+
id: yarn-cache-dir-path
20+
run: echo "::set-output name=dir::$(yarn cache dir)"
21+
- name: Restore cache
22+
uses: actions/cache@v3
23+
with:
24+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
25+
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
26+
restore-keys: |
27+
${{ runner.os }}-yarn-
28+
- name: Install dependencies
29+
run: |
30+
yarn install --prefer-offline --frozen-lockfile
31+
- name: Deploy
32+
run: |
33+
git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
34+
yarn storybook:deploy:action
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"trailingComma": "all",
44
"overrides": [
55
{
6-
"files": "*.ts",
6+
"files": "*.{ts,tsx}",
77
"options": {
88
"parser": "typescript"
99
}

.swcrc

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
{
2+
"sourceMaps": true,
23
"jsc": {
34
"parser": {
45
"syntax": "typescript",
56
"tsx": true
67
},
7-
"target": "es2021"
8-
},
9-
"module": {
10-
"type": "commonjs"
11-
},
12-
"transform": {
13-
"react": {
14-
"runtime": "automatic"
8+
"transform": {
9+
"react": {
10+
"runtime": "automatic"
11+
}
1512
}
16-
},
17-
"sourceMaps": true
13+
}
1814
}

jest.config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
22
module.exports = {
3+
testMatch: [
4+
'<rootDir>/**/*.test.{ts,tsx,js,jsx}',
5+
'<rootDir>/*.test.{ts,tsx,js,jsx}',
6+
],
7+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
38
transform: {
4-
'^.+\\.(t|j)s$': '@swc/jest',
9+
'^.+\\.(t|j)sx?$': ['@swc/jest'],
510
},
11+
testEnvironment: 'jsdom',
612
testPathIgnorePatterns: ['/node_modules/', '/build/'],
713
setupFilesAfterEnv: ['<rootDir>/jest-setup.js'],
814
};

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434
"build:swc:watch": "swc ./src -d build -w",
3535
"lint": "eslint ./src --ext .ts",
3636
"prettier": "prettier --write './src/**/*.{ts,js,json}'",
37-
"storybook": "start-storybook -p 6006",
38-
"build-storybook": "build-storybook"
37+
"storybook:start": "start-storybook -p 6006",
38+
"storybook:build": "build-storybook",
39+
"storybook:deploy": "npm run storybook:build && gh-pages -d .out",
40+
"storybook:deploy:action": "npm run storybook:build && gh-pages -d .out -u \"github-actions-bot <support+actions@github.com>\""
3941
},
4042
"dependencies": {
4143
"react": "^18.2.0",
@@ -55,6 +57,7 @@
5557
"@swc/cli": "0.1.57",
5658
"@swc/core": "1.3.14",
5759
"@swc/jest": "0.2.23",
60+
"@swc/plugin-styled-jsx": "^1.5.20",
5861
"@testing-library/jest-dom": "^5.16.5",
5962
"@testing-library/react": "^13.4.0",
6063
"@testing-library/user-event": "^14.4.3",
@@ -71,7 +74,9 @@
7174
"eslint-plugin-jsx-a11y": "^6.6.1",
7275
"eslint-plugin-react": "^7.31.10",
7376
"eslint-plugin-storybook": "^0.6.7",
77+
"gh-pages": "^4.0.0",
7478
"jest": "29.3.0",
79+
"jest-environment-jsdom": "^29.3.0",
7580
"nodemon": "2.0.20",
7681
"prettier": "2.7.1",
7782
"rimraf": "3.0.2",

src/Input.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ export function Input() {
55
return (
66
<div>
77
<h1 data-testid="input-result">Input result : {name}!</h1>
8+
<label htmlFor="input-type">Enter a value</label>
89
<input
9-
data-testid="input"
10+
id="input-type"
1011
type="text"
1112
value={name}
1213
onChange={(e) => setName(e.target.value)}

src/__tests__/Input.test.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ describe('<Input />', () => {
1010

1111
test('Input writing', () => {
1212
render(<Input />);
13-
14-
userEvent.type(screen.getByTestId('input'), 'résultat');
15-
expect(screen.getAllByTestId('input-result')).toBe(
16-
'Input result : résultat!',
17-
);
13+
const input = screen.getByLabelText(/enter a value/i);
14+
userEvent.type(input, 'résultat');
15+
console.log(input);
16+
expect(input).toHaveValue('résultat');
17+
const result = screen.getByTestId('input-result');
18+
expect(result).toBe('Input result : résultat!');
1819
});
1920
});

tsconfig.build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"extends": "./tsconfig.json",
3-
"exclude": ["src/**/*.spec.{ts,tsx}", "src/**/*.test.{ts,tsx}"]
3+
"exclude": ["src/**/*.spec.tsx", "src/**/*.test.tsx"]
44
}

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
1111

1212
/* Language and Environment */
13-
"target": "ES5" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
13+
"target": "ESNext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
1414
"lib": [
1515
"dom",
1616
"dom.iterable",
@@ -27,7 +27,7 @@
2727
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
2828

2929
/* Modules */
30-
"module": "ESNext" /* Specify what module code is generated. */,
30+
"module": "CommonJS" /* Specify what module code is generated. */,
3131
"rootDir": "./src" /* Specify the root folder within your source files. */,
3232
"moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
3333
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */

0 commit comments

Comments
 (0)