Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Add Storybook smoketest to GitHub CI (#520)
Browse files Browse the repository at this point in the history
* Add Storybook smoketest to GitHub CI

* Reorganize files to accomodate Nuxt component discovery and exclude `.types` files from it

* Fix linting issues
  • Loading branch information
sarayourfriend authored Dec 22, 2021
1 parent 19a5072 commit 01561ca
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 49 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ jobs:

- name: Run tests
run: pnpm i18n:get-translations && pnpm test:unit

- name: Run Storybook smoke-test
run: pnpm storybook -- --ci --smoke-test
3 changes: 1 addition & 2 deletions nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default {
},
components: {
dirs: [
'~/components',
{ path: '~/components', ignore: '**/*.types.js' },
'~/components/ContentReport',
'~/components/Filters',
'~/components/ImageDetails',
Expand All @@ -136,7 +136,6 @@ export default {
'~/components/VMetaSearch',
'~/components/MediaTag',
'~/components/Skeleton',
'~/components/VPopover',
],
},
plugins: [
Expand Down
2 changes: 1 addition & 1 deletion src/components/VModal/VModalContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<script>
import { defineComponent, toRefs, ref } from '@nuxtjs/composition-api'
import { FocusTrap } from 'focus-trap-vue'
import { VTeleport } from '~/components/VTeleport'
import VTeleport from '~/components/VTeleport/VTeleport'
import { useDialogContent } from '~/composables/use-dialog-content'
import { warn } from '~/utils/warn'
import VButton from '~/components/VButton.vue'
Expand Down
2 changes: 1 addition & 1 deletion src/components/VModal/VModalTarget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<script>
import { defineComponent } from '@nuxtjs/composition-api'
import { VTeleportTarget } from '~/components/VTeleport'
import VTeleportTarget from '~/components/VTeleport/VTeleportTarget'
export default defineComponent({
name: 'VModalTarget',
Expand Down
45 changes: 0 additions & 45 deletions src/components/VTeleport.js

This file was deleted.

3 changes: 3 additions & 0 deletions src/components/VTeleport/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# VTeleport and VTeleportTarget

Directly based on code from https://gist.github.com/Alan-Liang/a847559433919ecb53dff217ed9708bb
23 changes: 23 additions & 0 deletions src/components/VTeleport/VTeleport.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<script>
import { defineComponent } from '@nuxtjs/composition-api'
import { targets } from './meta/targets'
export default defineComponent({
name: 'VTeleport',
props: {
to: { type: String, required: true },
},
mounted() {
if (!(this.to in targets))
throw new Error(`VTeleport: non-existent target ${this.to}`)
targets[this.to].children.push(this)
},
beforeDestroy() {
if (!(this.to in targets))
throw new Error(`VTeleport: non-existent target ${this.to} on unmount`)
const children = targets[this.to].children
children.splice(children.indexOf(this), 1)
},
render: (h) => h('span'),
})
</script>
27 changes: 27 additions & 0 deletions src/components/VTeleport/VTeleportTarget.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<script>
import { defineComponent } from '@nuxtjs/composition-api'
import { targets } from './meta/targets'
export default defineComponent({
name: 'VTeleportTarget',
props: {
name: { type: String, required: true },
},
data: () => ({ children: [] }),
created() {
if (this.name in targets)
throw new Error(`VTeleportTarget: duplicate name ${this.name}`)
targets[this.name] = this
},
beforeDestroy() {
delete targets[this.name]
if (this.children.length > 0)
throw new Error(
`VTeleportTarget: ${this.name} beforeDestroy but still has children mounted`
)
},
render(h) {
return h('div', this.children.map((vm) => vm.$slots.default || []).flat())
},
})
</script>
11 changes: 11 additions & 0 deletions src/components/VTeleport/meta/targets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable unicorn/filename-case */
/**
* Disable this rule for this file until there's a way to disable it more generally
* for everything inside of the `meta` folders.
*
* @see https://github.com/sindresorhus/eslint-plugin-unicorn/issues/686
*/
/**
* @type {Record<string, import('vue').Component>}
*/
export const targets = {}

0 comments on commit 01561ca

Please sign in to comment.