Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit 48c7dee

Browse files
Merge pull request #7 from chakra-ui/chore/testing-setup
chore: testing setup
2 parents 12c6c5c + 968945d commit 48c7dee

File tree

35 files changed

+2948
-231
lines changed

35 files changed

+2948
-231
lines changed

.commitlintrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": [
3+
"@commitlint/config-conventional"
4+
]
5+
}

.github/pr.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: PR Workflow
5+
6+
on:
7+
pull_request:
8+
branches:
9+
- master
10+
- develop
11+
push:
12+
branches:
13+
- develop
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
strategy:
19+
matrix:
20+
node-version: [12.x]
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v2
24+
25+
- name: Use Node.js ${{ matrix.node-version }}
26+
uses: actions/setup-node@v1
27+
with:
28+
node-version: ${{ matrix.node-version }}
29+
30+
- name: Install dependencies
31+
run: yarn install --frozen-lockfile && yarn bootstrap
32+
33+
- name: Lint types and code
34+
run: yarn lint
35+
36+
- name: Build packages
37+
run: yarn build
38+
39+
- name: Run tests
40+
run: yarn test
41+
env:
42+
CI: true

.huskyrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"hooks": {
3+
"pre-commit": "lint-staged",
4+
"pre-push": "yarn test",
5+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
6+
}
7+
}

.lintstagedrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"*.{js,vue}": "eslint --fix"
3+
}

_templates/generator/module/package.json.ejs.t

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ to: packages/<%=h.changeCase.paramCase(name)%>/package.json
1919
"scripts": {
2020
"build": "concurrently yarn:build:*",
2121
"build:esm": "cross-env BABEL_ENV=esm babel src --root-mode upward --extensions .ts -d dist/esm --source-maps",
22-
"build:cjs": "cross-env BABEL_ENV=cjs babel src --root-mode upward --extensions .ts -d dist/cjs --source-maps"
22+
"build:cjs": "cross-env BABEL_ENV=cjs babel src --root-mode upward --extensions .ts -d dist/cjs --source-maps",
23+
"watch": "concurrently yarn:watch:*",
24+
"watch:esm": "cross-env BABEL_ENV=esm babel src --root-mode upward --extensions .ts -d dist/esm --source-maps --watch",
25+
"watch:cjs": "cross-env BABEL_ENV=cjs babel src --root-mode upward --extensions .ts -d dist/cjs --source-maps --watch",
26+
"watch:types": "tsc --emitDeclarationOnly --declaration --declarationDir dist/types --watch"
2327
}
2428
}

jest.config.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'vue'],
4+
transform: {
5+
'^.+\\.vue$': 'vue-jest',
6+
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$':
7+
'jest-transform-stub',
8+
'^.+\\.(ts|jsx)?$': 'ts-jest',
9+
},
10+
transformIgnorePatterns: ['/node_modules/(?!lodash.)'],
11+
moduleNameMapper: {
12+
'^@/(.*)$': '<rootDir>/$1',
13+
},
14+
snapshotSerializers: [
15+
'@chakra-ui/vue-test-utils/dist/cjs/snapshot-serializer.js',
16+
],
17+
testMatch: ['**/**/*.test.(js|jsx|ts|tsx)'],
18+
testURL: 'http://localhost/',
19+
testEnvironmentOptions: { resources: 'usable' },
20+
globals: {
21+
'ts-jest': {
22+
tsconfig: {
23+
target: 'ES2019',
24+
},
25+
},
26+
},
27+
}

package.json

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@
1010
],
1111
"scripts": {
1212
"postinstall": "yarn run lerna bootstrap",
13-
"build": "lerna run build --no-private --stream",
14-
"lint": "eslint '*/**/*.{js,ts,tsx}' --quiet --fix",
1513
"scaffold": "hygen",
16-
"playground:routes": "ts-node ./scripts/parse-routes.ts",
14+
"build": "lerna run build --no-private --stream",
1715
"dev": "yarn playground:routes && NODE_ENV=development vite serve playground --config ./vite.config.ts",
16+
"playground:routes": "ts-node ./scripts/parse-routes.ts",
1817
"playground:build": "yarn install && yarn build && yarn playground:routes && NODE_ENV=production vite build playground --config ./vite.config.ts",
18+
"test": "jest",
19+
"lint": "eslint '*/**/*.{js,ts,tsx}' --quiet --fix",
1920
"core": "yarn workspace @chakra-ui/vue-next",
2021
"c-alert": "yarn workspace @chakra-ui/c-alert",
2122
"c-theme-provider": "yarn workspace @chakra-ui/c-theme-provider",
2223
"c-box": "yarn workspace @chakra-ui/c-box",
2324
"c-button": "yarn workspace @chakra-ui/c-button",
2425
"system": "yarn workspace @chakra-ui/system-vue",
2526
"theme": "yarn workspace @chakra-ui/vue-theme",
26-
"nuxt": "yarn workspace @chakra-ui/nuxt-next"
27+
"nuxt": "yarn workspace @chakra-ui/nuxt-next",
28+
"test-utils": "yarn workspace @chakra-ui/vue-test-utils"
2729
},
2830
"license": "MIT",
2931
"private": true,
@@ -32,7 +34,12 @@
3234
"@babel/core": "^7.12.9",
3335
"@babel/preset-env": "^7.12.7",
3436
"@babel/preset-typescript": "^7.12.7",
35-
"@types/jest": "^26.0.14",
37+
"@commitlint/cli": "^11.0.0",
38+
"@commitlint/config-conventional": "^11.0.0",
39+
"@testing-library/jest-dom": "^5.11.9",
40+
"@testing-library/user-event": "^12.6.2",
41+
"@testing-library/vue": "^6.3.4",
42+
"@types/jest": "^26.0.20",
3643
"@types/recursive-readdir": "^2.2.0",
3744
"@typescript-eslint/eslint-plugin": "^2.34.0",
3845
"@typescript-eslint/parser": "4.0.1",
@@ -41,6 +48,7 @@
4148
"@vue/eslint-config-typescript": "^5.1.0",
4249
"@vuedx/typecheck": "^0.4.1",
4350
"@vuedx/typescript-plugin-vue": "^0.4.1",
51+
"babel-jest": "^26.6.3",
4452
"concurrently": "^5.3.0",
4553
"consola": "^2.15.0",
4654
"cross-env": "^7.0.2",
@@ -54,14 +62,21 @@
5462
"eslint-plugin-standard": "^4.0.1",
5563
"eslint-plugin-vue": "^7.0.0",
5664
"fs-extra": "^9.0.1",
65+
"husky": "^4.3.8",
5766
"hygen": "^6.0.4",
67+
"jest": "^26.6.3",
68+
"jest-transform-stub": "^2.0.0",
5869
"lerna": "^3.22.1",
70+
"lint-staged": "^10.5.3",
5971
"prettier": "^2.1.2",
72+
"pretty": "^2.0.0",
6073
"recursive-readdir": "^2.2.2",
74+
"ts-jest": "^26.5.0",
6175
"ts-node": "^9.0.0",
6276
"typescript": "^4.1.2",
6377
"vite": "^2.0.0-beta.44",
6478
"vue": "^3.0.5",
79+
"vue-jest": "^5.0.0-alpha.7",
6580
"vue-router": "4.0.0-beta.10"
6681
},
6782
"dependencies": {

packages/c-accordion/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@
1717
"build:esm": "cross-env BABEL_ENV=esm babel src --root-mode upward --extensions .ts -d dist/esm --source-maps",
1818
"build:cjs": "cross-env BABEL_ENV=cjs babel src --root-mode upward --extensions .ts -d dist/cjs --source-maps",
1919
"build:types": "tsc --emitDeclarationOnly --declaration --declarationDir dist/types"
20+
},
21+
"dependencies": {
22+
"@chakra-ui/system-vue": "1.0.0"
2023
}
2124
}

packages/c-accordion/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { h, defineComponent, PropType } from 'vue'
2+
import { chakra, DOMElements } from '@chakra-ui/system-vue'
23

34
const CAccordion = defineComponent({
45
props: {
56
as: {
6-
type: Object as PropType<string>,
7+
type: [String] as PropType<DOMElements>,
78
default: 'div',
89
},
910
},
1011
setup(props, { slots, attrs }) {
11-
return h(props?.as, { ...attrs }, slots.default?.())
12+
return () => h(chakra(props.as), { ...attrs }, slots)
1213
},
1314
})
1415

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`should render properly 1`] = `
4+
<DocumentFragment>
5+
<div
6+
class="css-0"
7+
/>
8+
</DocumentFragment>
9+
`;

0 commit comments

Comments
 (0)