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

Commit 5680017

Browse files
committed
test: setup tsx environment
1 parent 5fe5ea6 commit 5680017

File tree

9 files changed

+96
-60
lines changed

9 files changed

+96
-60
lines changed

babel.config.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ const BABEL_ENV = process.env.BABEL_ENV
22
const isCommonJS = BABEL_ENV !== undefined && BABEL_ENV === 'cjs'
33
const isESM = BABEL_ENV !== undefined && BABEL_ENV === 'esm'
44

5-
module.exports = function (api) {
5+
const __TEST__ = process.env.NODE_ENV === 'test'
6+
7+
const baseConfig = function (api) {
68
api.cache(true)
79

810
const presets = [
@@ -18,8 +20,28 @@ module.exports = function (api) {
1820
],
1921
'@babel/preset-typescript',
2022
]
23+
const plugins = ['@vue/babel-plugin-jsx']
2124

2225
return {
2326
presets,
27+
plugins,
2428
}
2529
}
30+
31+
const testConfig = {
32+
env: {
33+
test: {
34+
presets: [
35+
[
36+
'@babel/preset-env',
37+
{
38+
targets: { node: true },
39+
},
40+
],
41+
],
42+
plugins: ['@vue/babel-plugin-jsx'],
43+
},
44+
},
45+
}
46+
47+
module.exports = __TEST__ ? testConfig : baseConfig

jest.config.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
module.exports = {
2-
preset: 'ts-jest',
3-
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'vue'],
42
transform: {
5-
'^.+\\.vue$': 'vue-jest',
6-
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$':
7-
'jest-transform-stub',
8-
'^.+\\.(ts|tsx)?$': 'ts-jest',
3+
'^.+\\.(ts|tsx)$': 'ts-jest',
94
},
105
transformIgnorePatterns: ['/node_modules/(?!lodash.)'],
116
moduleNameMapper: {
@@ -16,13 +11,10 @@ module.exports = {
1611
'@chakra-ui/vue-test-utils/dist/cjs/snapshot-serializer.js',
1712
],
1813
testMatch: ['**/**/*.test.(js|jsx|ts|tsx)'],
19-
testURL: 'http://localhost/',
2014
testEnvironmentOptions: { resources: 'usable' },
2115
globals: {
2216
'ts-jest': {
23-
tsconfig: {
24-
target: 'ES2018',
25-
},
17+
babelConfig: 'babel.config.js',
2618
},
2719
},
2820
}

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"build": "lerna run build --no-private --stream",
1616
"dev": "NODE_ENV=development vite serve playground --config ./vite.config.ts",
1717
"playground:build": "yarn install && yarn build && NODE_ENV=production vite build playground --config ./vite.config.ts",
18-
"test": "jest",
18+
"test": "cross-env NODE_ENV=test jest --config jest.config.js",
1919
"lint": "eslint '*/**/*.{js,ts,tsx}' --quiet --fix",
2020
"core": "yarn workspace @chakra-ui/vue-next",
2121
"c-alert": "yarn workspace @chakra-ui/c-alert",
@@ -48,6 +48,7 @@
4848
"@typescript-eslint/eslint-plugin": "^2.34.0",
4949
"@typescript-eslint/parser": "4.0.1",
5050
"@vitejs/plugin-vue": "^1.0.6",
51+
"@vue/babel-plugin-jsx": "^1.0.3",
5152
"@vue/compiler-sfc": "^3.0.5",
5253
"@vue/eslint-config-typescript": "^5.1.0",
5354
"@vuedx/typecheck": "^0.4.1",
@@ -57,6 +58,7 @@
5758
"concurrently": "^5.3.0",
5859
"consola": "^2.15.0",
5960
"cross-env": "^7.0.2",
61+
"esbuild-jest": "^0.4.0",
6062
"eslint": "^7.0.0",
6163
"eslint-config-prettier": "^6.12.0",
6264
"eslint-config-standard": "^14.1.1",

packages/c-button/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
"license": "MIT",
1515
"scripts": {
1616
"build": "concurrently yarn:build:*",
17-
"build:esm": "cross-env BABEL_ENV=esm babel src --root-mode upward --extensions .ts -d dist/esm --source-maps",
18-
"build:cjs": "cross-env BABEL_ENV=cjs babel src --root-mode upward --extensions .ts -d dist/cjs --source-maps",
17+
"build:esm": "cross-env BABEL_ENV=esm babel src --root-mode upward --extensions .tsx -d dist/esm --source-maps",
18+
"build:cjs": "cross-env BABEL_ENV=cjs babel src --root-mode upward --extensions .tsx -d dist/cjs --source-maps",
1919
"build:types": "tsc --emitDeclarationOnly --declaration --declarationDir dist/types",
2020
"watch": "concurrently yarn:watch:*",
21-
"watch:esm": "cross-env BABEL_ENV=esm babel src --root-mode upward --extensions .ts -d dist/esm --source-maps --watch",
22-
"watch:cjs": "cross-env BABEL_ENV=cjs babel src --root-mode upward --extensions .ts -d dist/cjs --source-maps --watch",
21+
"watch:esm": "cross-env BABEL_ENV=esm babel src --root-mode upward --extensions .tsx -d dist/esm --source-maps --watch",
22+
"watch:cjs": "cross-env BABEL_ENV=cjs babel src --root-mode upward --extensions .tsx -d dist/cjs --source-maps --watch",
2323
"watch:types": "tsc --emitDeclarationOnly --declaration --declarationDir dist/types --watch"
2424
},
2525
"dependencies": {

packages/c-button/tests/__snapshots__/c-button-group.test.ts.snap

Lines changed: 0 additions & 21 deletions
This file was deleted.

packages/c-button/tests/__snapshots__/c-button.test.ts.snap renamed to packages/c-button/tests/__snapshots__/c-button.test.tsx.snap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
exports[`should render properly 1`] = `
44
<DocumentFragment>
55
<button
6-
class="chakra-button css-myeq6i"
6+
as="button"
7+
class="css-myeq6i"
8+
label="button"
79
>
810
Happy button
911
</button>

packages/c-button/tests/c-button.test.skip.tsx renamed to packages/c-button/tests/c-button.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { render, userEvent } from '../../test-utils/src'
21
import { CButton } from '../src'
2+
import { render, userEvent } from '../../test-utils/src'
33

44
const renderComponent = (props?: any) => {
55
const base = {

playground/src/components/Home.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
</template>
44

55
<script>
6-
import { defineComponent, h } from 'vue'
7-
import { RouterLink } from 'vue-router'
8-
import { routes } from '../router'
9-
6+
import { defineComponent } from 'vue'
107
118
export default defineComponent({
129
mounted() {

yarn.lock

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -221,20 +221,20 @@
221221
dependencies:
222222
"@babel/types" "^7.12.13"
223223

224+
"@babel/helper-module-imports@^7.0.0", "@babel/helper-module-imports@^7.12.13":
225+
version "7.12.13"
226+
resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.12.13.tgz#ec67e4404f41750463e455cc3203f6a32e93fcb0"
227+
integrity sha512-NGmfvRp9Rqxy0uHSSVP+SRIW1q31a7Ji10cLBcqSDUngGentY4FRiHOFZFE1CLU5eiL0oE8reH7Tg1y99TDM/g==
228+
dependencies:
229+
"@babel/types" "^7.12.13"
230+
224231
"@babel/helper-module-imports@^7.12.1", "@babel/helper-module-imports@^7.12.5", "@babel/helper-module-imports@^7.7.0":
225232
version "7.12.5"
226233
resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.12.5.tgz#1bfc0229f794988f76ed0a4d4e90860850b54dfb"
227234
integrity sha512-SR713Ogqg6++uexFRORf/+nPXMmWIn80TALu0uaFb+iQIUoR7bOC7zBWyzBs5b3tBBJXuyD0cRu1F15GyzjOWA==
228235
dependencies:
229236
"@babel/types" "^7.12.5"
230237

231-
"@babel/helper-module-imports@^7.12.13":
232-
version "7.12.13"
233-
resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.12.13.tgz#ec67e4404f41750463e455cc3203f6a32e93fcb0"
234-
integrity sha512-NGmfvRp9Rqxy0uHSSVP+SRIW1q31a7Ji10cLBcqSDUngGentY4FRiHOFZFE1CLU5eiL0oE8reH7Tg1y99TDM/g==
235-
dependencies:
236-
"@babel/types" "^7.12.13"
237-
238238
"@babel/helper-module-transforms@^7.12.1":
239239
version "7.12.1"
240240
resolved "https://registry.yarnpkg.com/@babel/helper-module-transforms/-/helper-module-transforms-7.12.1.tgz#7954fec71f5b32c48e4b303b437c34453fd7247c"
@@ -597,6 +597,13 @@
597597
dependencies:
598598
"@babel/helper-plugin-utils" "^7.8.0"
599599

600+
"@babel/plugin-syntax-jsx@^7.0.0":
601+
version "7.12.13"
602+
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.12.13.tgz#044fb81ebad6698fe62c478875575bcbb9b70f15"
603+
integrity sha512-d4HM23Q1K7oq/SLNmG6mRt85l2csmQ0cHRaxRXjKW0YFdEXqlZ5kzFQKH5Uc3rDJECgu+yCRgPkG04Mm98R/1g==
604+
dependencies:
605+
"@babel/helper-plugin-utils" "^7.12.13"
606+
600607
"@babel/plugin-syntax-jsx@^7.12.1":
601608
version "7.12.1"
602609
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.12.1.tgz#9d9d357cc818aa7ae7935917c1257f67677a0926"
@@ -1049,6 +1056,15 @@
10491056
dependencies:
10501057
regenerator-runtime "^0.13.4"
10511058

1059+
"@babel/template@^7.0.0", "@babel/template@^7.12.13", "@babel/template@^7.3.3":
1060+
version "7.12.13"
1061+
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.12.13.tgz#530265be8a2589dbb37523844c5bcb55947fb327"
1062+
integrity sha512-/7xxiGA57xMo/P2GVvdEumr8ONhFOhfgq2ihK3h1e6THqzTAkHbkXgB0xI9yeTfIUoH3+oAeHhqm/I43OTbbjA==
1063+
dependencies:
1064+
"@babel/code-frame" "^7.12.13"
1065+
"@babel/parser" "^7.12.13"
1066+
"@babel/types" "^7.12.13"
1067+
10521068
"@babel/template@^7.10.4", "@babel/template@^7.12.7":
10531069
version "7.12.7"
10541070
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.12.7.tgz#c817233696018e39fbb6c491d2fb684e05ed43bc"
@@ -1058,15 +1074,6 @@
10581074
"@babel/parser" "^7.12.7"
10591075
"@babel/types" "^7.12.7"
10601076

1061-
"@babel/template@^7.12.13", "@babel/template@^7.3.3":
1062-
version "7.12.13"
1063-
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.12.13.tgz#530265be8a2589dbb37523844c5bcb55947fb327"
1064-
integrity sha512-/7xxiGA57xMo/P2GVvdEumr8ONhFOhfgq2ihK3h1e6THqzTAkHbkXgB0xI9yeTfIUoH3+oAeHhqm/I43OTbbjA==
1065-
dependencies:
1066-
"@babel/code-frame" "^7.12.13"
1067-
"@babel/parser" "^7.12.13"
1068-
"@babel/types" "^7.12.13"
1069-
10701077
10711078
version "7.12.1"
10721079
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.12.1.tgz#941395e0c5cc86d5d3e75caa095d3924526f0c1e"
@@ -1082,7 +1089,7 @@
10821089
globals "^11.1.0"
10831090
lodash "^4.17.19"
10841091

1085-
"@babel/traverse@^7.1.0", "@babel/traverse@^7.12.13":
1092+
"@babel/traverse@^7.0.0", "@babel/traverse@^7.1.0", "@babel/traverse@^7.12.13":
10861093
version "7.12.13"
10871094
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.12.13.tgz#689f0e4b4c08587ad26622832632735fb8c4e0c0"
10881095
integrity sha512-3Zb4w7eE/OslI0fTp8c7b286/cQps3+vdLW3UcwC8VSJC6GbKn55aeVVu2QJNuCDoeKyptLOFrPq8WqZZBodyA==
@@ -2925,6 +2932,26 @@
29252932
resolved "https://registry.yarnpkg.com/@vitejs/plugin-vue/-/plugin-vue-1.0.6.tgz#698afa5a77a6dcd22cf7757801f46a6f01cdbb53"
29262933
integrity sha512-cWJewtxnVVpjlhq6DoZ7VP7sF1jTZYVg66ehslZ0tJANWk1uRiCXdqD8yQ4npZ4XewDICQzK+c+9i3Xsubx59w==
29272934

2935+
"@vue/babel-helper-vue-transform-on@^1.0.2":
2936+
version "1.0.2"
2937+
resolved "https://registry.yarnpkg.com/@vue/babel-helper-vue-transform-on/-/babel-helper-vue-transform-on-1.0.2.tgz#9b9c691cd06fc855221a2475c3cc831d774bc7dc"
2938+
integrity sha512-hz4R8tS5jMn8lDq6iD+yWL6XNB699pGIVLk7WSJnn1dbpjaazsjZQkieJoRX6gW5zpYSCFqQ7jUquPNY65tQYA==
2939+
2940+
"@vue/babel-plugin-jsx@^1.0.3":
2941+
version "1.0.3"
2942+
resolved "https://registry.yarnpkg.com/@vue/babel-plugin-jsx/-/babel-plugin-jsx-1.0.3.tgz#ad5ee86ebc9fc40900add9914534e223c719eace"
2943+
integrity sha512-+52ZQFmrM0yh61dQlgwQlfHZXmYbswbQEL25SOSt9QkjegAdfIGu87oELw0l8H6cuJYazZCiNjPR9eU++ZIbxg==
2944+
dependencies:
2945+
"@babel/helper-module-imports" "^7.0.0"
2946+
"@babel/plugin-syntax-jsx" "^7.0.0"
2947+
"@babel/template" "^7.0.0"
2948+
"@babel/traverse" "^7.0.0"
2949+
"@babel/types" "^7.0.0"
2950+
"@vue/babel-helper-vue-transform-on" "^1.0.2"
2951+
camelcase "^6.0.0"
2952+
html-tags "^3.1.0"
2953+
svg-tags "^1.0.0"
2954+
29282955
"@vue/[email protected]", "@vue/compiler-core@^3.0.0", "@vue/compiler-core@^3.0.1", "@vue/compiler-core@^3.0.2":
29292956
version "3.0.5"
29302957
resolved "https://registry.yarnpkg.com/@vue/compiler-core/-/compiler-core-3.0.5.tgz#a6e54cabe9536e74c6513acd2649f311af1d43ac"
@@ -5083,6 +5110,11 @@ es6-promisify@^5.0.0:
50835110
dependencies:
50845111
es6-promise "^4.0.3"
50855112

5113+
esbuild-jest@^0.4.0:
5114+
version "0.4.0"
5115+
resolved "https://registry.yarnpkg.com/esbuild-jest/-/esbuild-jest-0.4.0.tgz#d1187d3aa98d458d72467ded77d543943cff6f66"
5116+
integrity sha512-KpL7u1SyVRme2uBVenAbM4yipDqiy1kjx43EiQQnxz4cEXI4Q6UBRIldaQkBNr3GrqNGDz8xYwb0heUvznxtHA==
5117+
50865118
esbuild@^0.8.34:
50875119
version "0.8.34"
50885120
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.8.34.tgz#16b4ac58f74c821d2c5a8c2f0585ca96a38ab4e6"
@@ -6208,6 +6240,11 @@ html-escaper@^2.0.0:
62086240
resolved "https://registry.yarnpkg.com/html-escaper/-/html-escaper-2.0.2.tgz#dfd60027da36a36dfcbe236262c00a5822681453"
62096241
integrity sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==
62106242

6243+
html-tags@^3.1.0:
6244+
version "3.1.0"
6245+
resolved "https://registry.yarnpkg.com/html-tags/-/html-tags-3.1.0.tgz#7b5e6f7e665e9fb41f30007ed9e0d41e97fb2140"
6246+
integrity sha512-1qYz89hW3lFDEazhjW0yVAV87lw8lVkrJocr72XmBkMKsoSVJCQx3W8BXsC7hO2qAt8BoVjYjtAcZ9perqGnNg==
6247+
62116248
html-tokenize@^2.0.0:
62126249
version "2.0.1"
62136250
resolved "https://registry.yarnpkg.com/html-tokenize/-/html-tokenize-2.0.1.tgz#c3b2ea6e2837d4f8c06693393e9d2a12c960be5f"
@@ -10455,6 +10492,11 @@ supports-hyperlinks@^2.0.0:
1045510492
has-flag "^4.0.0"
1045610493
supports-color "^7.0.0"
1045710494

10495+
svg-tags@^1.0.0:
10496+
version "1.0.0"
10497+
resolved "https://registry.yarnpkg.com/svg-tags/-/svg-tags-1.0.0.tgz#58f71cee3bd519b59d4b2a843b6c7de64ac04764"
10498+
integrity sha1-WPcc7jvVGbWdSyqEO2x95krAR2Q=
10499+
1045810500
swap-case@^1.1.0:
1045910501
version "1.1.2"
1046010502
resolved "https://registry.yarnpkg.com/swap-case/-/swap-case-1.1.2.tgz#c39203a4587385fad3c850a0bd1bcafa081974e3"

0 commit comments

Comments
 (0)