Skip to content

Commit bf022e3

Browse files
feat: add tests dir to template
1 parent 1ae9f46 commit bf022e3

File tree

3 files changed

+61
-38
lines changed

3 files changed

+61
-38
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"build": "vite build",
88
"cz": "npx git-cz",
99
"test": "jest",
10-
"gc": "sh ./scripts/gc.sh"
10+
"gc": "bash ./scripts/gc.sh"
1111
},
1212
"peerDependencies": {
1313
"vue": "^3.0.0-rc.1",

packages/button/__tests__/button.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {mount, config} from '@vue/test-utils'
1+
import {mount} from '@vue/test-utils'
22
import Button from '../src/index.vue'
33

44
const AXIOM = 'Rem is the best girl'

scripts/gc.sh

Lines changed: 59 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,42 +25,65 @@ for i in $(echo $NAME | sed 's/[_|-]\([a-z]\)/\ \1/;s/^\([a-z]\)/\ \1/'); do
2525
done
2626
NAME=$NORMALIZED_NAME
2727

28-
TEMPLATE_INDEX_VUE="<template>\n
29-
<div>\n
30-
</div>\n
31-
</template>\n
32-
<script lang='ts'>\n
33-
export default {\n
34-
NAME: 'El${NAME}',\n
35-
props: {\n
36-
},\n
37-
setup(props,ctx) { }\n
38-
};\n
39-
</script>\n
40-
<style>\n
41-
</style>\n
42-
"
28+
mkdir -p "$DIRNAME"
29+
mkdir -p "$DIRNAME/src"
30+
mkdir -p "$DIRNAME/__tests__"
31+
32+
cat > $DIRNAME/src/index.vue <<EOF
33+
<template>
34+
<div>
35+
<slot/>
36+
</div>
37+
</template>
38+
<script lang='ts'>
39+
export default {
40+
NAME: 'El${NAME}',
41+
props: {
42+
},
43+
setup(props,ctx) { }
44+
};
45+
</script>
46+
<style scoped>
47+
</style>
48+
EOF
4349

44-
TEMPLATE_INDEX_TS="\n
45-
import { App } from 'vue'\n
46-
import ${NAME} from './src/index.vue'\n
47-
export default (app: App) => {\n
48-
app.component(${NAME}.name, ${NAME})\n
50+
cat > $DIRNAME/index.ts <<EOF
51+
import { App } from 'vue'
52+
import ${NAME} from './src/index.vue'
53+
export default (app: App) => {
54+
app.component(${NAME}.name, ${NAME})
4955
}
50-
"
51-
TEMPLATE_PKG_JSON="\n
52-
{\n
53-
\"name\": \"@element-plus/${INPUT_NAME}\",\n
54-
\"description\": \"\",\n
55-
\"version\": \"0.1.0\",\n
56-
\"main\": \"./index.ts\",\n
57-
\"license\": \"MIT\",\n
58-
\"dependencies\": {}\n
59-
}\n
60-
"
56+
EOF
6157

62-
mkdir -p "$DIRNAME"
63-
mkdir -p "$DIRNAME/src"
64-
echo $TEMPLATE_INDEX_VUE >>"$DIRNAME/src/index.vue"
65-
echo $TEMPLATE_INDEX_TS >>"$DIRNAME/index.ts"
66-
echo $TEMPLATE_PKG_JSON >>"$DIRNAME/package.json"
58+
cat > $DIRNAME/package.json <<EOF
59+
{
60+
"name": "@element-plus/$INPUT_NAME",
61+
"version": "0.0.0",
62+
"main": "dist/index.js",
63+
"license": "MIT",
64+
"peerDependencies": {
65+
"vue": "^3.0.0-rc.1"
66+
},
67+
"devDependencies": {
68+
"@vue/test-utils": "^2.0.0-beta.0"
69+
}
70+
}
71+
EOF
72+
73+
cat > $DIRNAME/__tests__/$INPUT_NAME.spec.ts <<EOF
74+
import {mount} from '@vue/test-utils'
75+
import $NAME from '../src/index.vue'
76+
77+
const AXIOM = 'Rem is the best girl'
78+
79+
describe('$NAME.vue', () => {
80+
test('render test', () => {
81+
const instance = mount($NAME, {
82+
slots: {
83+
default: AXIOM
84+
},
85+
})
86+
expect(instance.text()).toEqual(AXIOM)
87+
})
88+
})
89+
EOF

0 commit comments

Comments
 (0)