From fcba294463c1cc35f6452b214f995c38d1a307a6 Mon Sep 17 00:00:00 2001 From: Herrington Darkholme <2883231+HerringtonDarkholme@users.noreply.github.com> Date: Sat, 25 Jul 2020 13:54:19 +0800 Subject: [PATCH 1/6] fix: update test cases --- packages/badge/__tests__/badge.spec.ts | 36 +++++++++++++++++++++----- typings/vue-shim.d.ts | 2 +- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/packages/badge/__tests__/badge.spec.ts b/packages/badge/__tests__/badge.spec.ts index 9795d6c7f6..3e3efb0c69 100644 --- a/packages/badge/__tests__/badge.spec.ts +++ b/packages/badge/__tests__/badge.spec.ts @@ -3,13 +3,35 @@ import Badge from '../src/index.vue' const AXIOM = 'Rem is the best girl' -describe('Badge.vue', () => { - test('render test', () => { - const instance = mount(Badge, { - slots: { - default: AXIOM - }, +describe('Badge', () => { + test('has value', () => { + const wrapper = mount(Badge, { + props: {value: 80} }) - expect(instance.text()).toEqual(AXIOM) + expect(wrapper.vm.content).toEqual(80) + }) + + test('is fixed', () => { + const wrapper = mount(Badge, { + slots: {default: AXIOM} + }) + expect(wrapper.find('.el-badge__content.is-fixed')).toBeDefined() + }) + + test('is dot', () => { + const wrapper = mount(Badge, { + props: {isDot: true}, + slots: {default: AXIOM} + }) + expect(wrapper.find('.el-badge__content.is-fixed')).toBeDefined() + }) + + test('max', async () => { + const wrapper = mount(Badge, { + props: {max: 100, value: 200}, + }) + expect(wrapper.vm.content).toEqual('100+') + await wrapper.setProps({value: 80}) + expect(wrapper.vm.content).toEqual(80) }) }) diff --git a/typings/vue-shim.d.ts b/typings/vue-shim.d.ts index 42c297747f..e1bfc1d369 100644 --- a/typings/vue-shim.d.ts +++ b/typings/vue-shim.d.ts @@ -1,7 +1,7 @@ declare module '*.vue' { import { Component, ComponentPublicInstance } from 'vue' const _default: Component & { - new (): ComponentPublicInstance + new (): ComponentPublicInstance } export default _default } From cb0b012fac426c58024ded3c27fa915a77c451b4 Mon Sep 17 00:00:00 2001 From: Herrington Darkholme <2883231+HerringtonDarkholme@users.noreply.github.com> Date: Sat, 25 Jul 2020 17:26:21 +0800 Subject: [PATCH 2/6] feat: support re-export story from vue --- .storybook/custom-presets.js | 14 ++++++++++++++ .storybook/export-loader.js | 7 +++++++ packages/badge/doc/index.stories.ts | 4 +--- 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 .storybook/export-loader.js diff --git a/.storybook/custom-presets.js b/.storybook/custom-presets.js index 6627cc8630..493c312faa 100644 --- a/.storybook/custom-presets.js +++ b/.storybook/custom-presets.js @@ -13,6 +13,20 @@ function webpack(config) { loader: require.resolve('vue-loader'), options: {}, }, + { + test: /\.stories\.ts$/, + use: [ + { + loader: require.resolve('./export-loader') + }, + { + loader: require.resolve('ts-loader'), + options: { + transpileOnly: true, + }, + }, + ] + }, { test: /\.(ts|tsx)$/, use: [ diff --git a/.storybook/export-loader.js b/.storybook/export-loader.js new file mode 100644 index 0000000000..381c8e1f16 --- /dev/null +++ b/.storybook/export-loader.js @@ -0,0 +1,7 @@ +module.exports = function (content) { + return content.replace( + /export ?{\s* default as (.+?)}(.+)/g,` +import _$1 $2 +export const $1 = () => _$1 +`) +} diff --git a/packages/badge/doc/index.stories.ts b/packages/badge/doc/index.stories.ts index a2cdcf529b..3e258d91ff 100644 --- a/packages/badge/doc/index.stories.ts +++ b/packages/badge/doc/index.stories.ts @@ -1,7 +1,5 @@ -import Basic from './basic.vue' +export { default as BasicUsage} from './basic.vue' export default { title: "Badge", } - -export const BasicUsage = () => Basic From 7f82633322407ba8d9801d2cf83d3de0ed3fb96b Mon Sep 17 00:00:00 2001 From: Herrington Darkholme <2883231+HerringtonDarkholme@users.noreply.github.com> Date: Sat, 25 Jul 2020 18:33:49 +0800 Subject: [PATCH 3/6] feat: add story source --- .storybook/export-loader.js | 11 +++++--- .storybook/main.js | 1 + package.json | 9 ++++--- packages/badge/doc/index.stories.ts | 6 +++++ yarn.lock | 40 +++++++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 8 deletions(-) diff --git a/.storybook/export-loader.js b/.storybook/export-loader.js index 381c8e1f16..b02043ebbc 100644 --- a/.storybook/export-loader.js +++ b/.storybook/export-loader.js @@ -1,7 +1,10 @@ -module.exports = function (content) { - return content.replace( - /export ?{\s* default as (.+?)}(.+)/g,` +module.exports = function (content, map, meta) { + content = content.replace( + /^export\s*{\s*default as (.+?)}(.+)/mg,` import _$1 $2 export const $1 = () => _$1 -`) +`.trim()) + this.callback(null, content, map, meta) + return } + diff --git a/.storybook/main.js b/.storybook/main.js index b34ed30683..88d025f5c7 100644 --- a/.storybook/main.js +++ b/.storybook/main.js @@ -3,4 +3,5 @@ const path = require('path'); module.exports = { stories: ['../packages/**/doc/*.stories.[tj]s'], presets: [path.resolve(__dirname, './custom-presets')], + addons: ['@storybook/addon-storysource'], }; diff --git a/package.json b/package.json index 3775b2511e..421f9c87dc 100644 --- a/package.json +++ b/package.json @@ -16,20 +16,21 @@ "vue-router": "^4.0.0-beta.2" }, "devDependencies": { - "@types/jest": "^26.0.7", "@babel/core": "^7.10.5", + "@storybook/addon-storysource": "^5.3.19", "@storybook/html": "^5.3.19", + "@types/jest": "^26.0.7", "@vue/compiler-sfc": "^3.0.0-rc.1", "babel-loader": "^8.1.0", "babel-preset-vue": "^2.0.2", "cz-conventional-changelog": "^3.2.0", - "lerna": "^3.22.1", "jest": "^24.1.0", + "lerna": "^3.22.1", "ts-jest": "^26.1.3", - "vue-jest": "5.0.0-alpha.1", - "vite": "^1.0.0-rc.1", "ts-loader": "^8.0.1", "typescript": "^3.9.7", + "vite": "^1.0.0-rc.1", + "vue-jest": "5.0.0-alpha.1", "vue-loader": "^v16.0.0-beta.4" }, "config": { diff --git a/packages/badge/doc/index.stories.ts b/packages/badge/doc/index.stories.ts index 3e258d91ff..18ee89874a 100644 --- a/packages/badge/doc/index.stories.ts +++ b/packages/badge/doc/index.stories.ts @@ -3,3 +3,9 @@ export { default as BasicUsage} from './basic.vue' export default { title: "Badge", } + +export const AAA = () => ` + + eee + +` diff --git a/yarn.lock b/yarn.lock index 259b825294..9627e23f0b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2066,6 +2066,25 @@ estree-walker "^1.0.1" picomatch "^2.2.2" +"@storybook/addon-storysource@^5.3.19": + version "5.3.19" + resolved "https://registry.yarnpkg.com/@storybook/addon-storysource/-/addon-storysource-5.3.19.tgz#ae693e88db5d220cb256a9ef4a2366c300e8d88c" + integrity sha512-W7mIAHuxYT+b1huaHCHLkBAh2MbeWmF8CxeBCFiOgZaYYQUTDEh018HJF8u2AqiWSouRhcfzhTnGxOo0hNRBgw== + dependencies: + "@storybook/addons" "5.3.19" + "@storybook/components" "5.3.19" + "@storybook/router" "5.3.19" + "@storybook/source-loader" "5.3.19" + "@storybook/theming" "5.3.19" + core-js "^3.0.1" + estraverse "^4.2.0" + loader-utils "^1.2.3" + prettier "^1.16.4" + prop-types "^15.7.2" + react-syntax-highlighter "^11.0.2" + regenerator-runtime "^0.13.3" + util-deprecate "^1.0.2" + "@storybook/addons@5.3.19": version "5.3.19" resolved "https://registry.npm.taobao.org/@storybook/addons/download/@storybook/addons-5.3.19.tgz?cache=0&sync_timestamp=1595435252424&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40storybook%2Faddons%2Fdownload%2F%40storybook%2Faddons-5.3.19.tgz#3a7010697afd6df9a41b8c8a7351d9a06ff490a4" @@ -2314,6 +2333,22 @@ qs "^6.6.0" util-deprecate "^1.0.2" +"@storybook/source-loader@5.3.19": + version "5.3.19" + resolved "https://registry.yarnpkg.com/@storybook/source-loader/-/source-loader-5.3.19.tgz#ff0a00731c24c61721d8b9d84152f8542913a3b7" + integrity sha512-srSZRPgEOUse8nRVnlazweB2QGp63mPqM0uofg8zYARyaYSOzkC155ymdeiHsmiBTS3X3I0FQE4+KnwiH7iLtw== + dependencies: + "@storybook/addons" "5.3.19" + "@storybook/client-logger" "5.3.19" + "@storybook/csf" "0.0.1" + core-js "^3.0.1" + estraverse "^4.2.0" + global "^4.3.2" + loader-utils "^1.2.3" + prettier "^1.16.4" + prop-types "^15.7.2" + regenerator-runtime "^0.13.3" + "@storybook/theming@5.3.19": version "5.3.19" resolved "https://registry.npm.taobao.org/@storybook/theming/download/@storybook/theming-5.3.19.tgz#177d9819bd64f7a1a6ea2f1920ffa5baf9a5f467" @@ -10311,6 +10346,11 @@ prelude-ls@~1.1.2: resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54" integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ= +prettier@^1.16.4: + version "1.19.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb" + integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew== + pretty-error@^2.1.1: version "2.1.1" resolved "https://registry.npm.taobao.org/pretty-error/download/pretty-error-2.1.1.tgz#5f4f87c8f91e5ae3f3ba87ab4cf5e03b1a17f1a3" From 09e0a05c19b1b93fd7786f96ca1a086b44a8aea8 Mon Sep 17 00:00:00 2001 From: HerringtonDarkholme <2883231+HerringtonDarkholme@users.noreply.github.com> Date: Sun, 26 Jul 2020 09:51:16 +0800 Subject: [PATCH 4/6] fix(core): remove test code in test --- packages/badge/doc/index.stories.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/badge/doc/index.stories.ts b/packages/badge/doc/index.stories.ts index 18ee89874a..3e258d91ff 100644 --- a/packages/badge/doc/index.stories.ts +++ b/packages/badge/doc/index.stories.ts @@ -3,9 +3,3 @@ export { default as BasicUsage} from './basic.vue' export default { title: "Badge", } - -export const AAA = () => ` - - eee - -` From b7386b2e152e3c5fc4ec001d4be2a29066dd1180 Mon Sep 17 00:00:00 2001 From: Bradley Zhou Date: Sat, 25 Jul 2020 23:38:24 +0800 Subject: [PATCH 5/6] add yarn ci github actions for tests --- .github/workflows/yarn.js.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/yarn.js.yml diff --git a/.github/workflows/yarn.js.yml b/.github/workflows/yarn.js.yml new file mode 100644 index 0000000000..557379bf36 --- /dev/null +++ b/.github/workflows/yarn.js.yml @@ -0,0 +1,25 @@ +name: CI + +on: + push: + branches: + - dev + - 'feat/**' + pull_request: + branches: + - dev + - 'feat/**' + +jobs: + build: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: borales/actions-yarn@v2.0.0 + with: + cmd: install --frozen-lockfile + - run: npx lerna bootstrap + - uses: borales/actions-yarn@v2.0.0 + with: + cmd: test From e5e7e39e5172faae31aae819a03df6ba5cb50480 Mon Sep 17 00:00:00 2001 From: Bradley Zhou Date: Sat, 25 Jul 2020 23:56:02 +0800 Subject: [PATCH 6/6] remove lerna from Test step in github actions --- .github/workflows/yarn.js.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/yarn.js.yml b/.github/workflows/yarn.js.yml index 557379bf36..6d0256cc94 100644 --- a/.github/workflows/yarn.js.yml +++ b/.github/workflows/yarn.js.yml @@ -19,7 +19,6 @@ jobs: - uses: borales/actions-yarn@v2.0.0 with: cmd: install --frozen-lockfile - - run: npx lerna bootstrap - uses: borales/actions-yarn@v2.0.0 with: cmd: test