-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding ui component tests (#590)
* docs: additional cypress + vitest comparison content * feat: ui testing * fix: seperate cypress tests * feat: adding cypress component testing for ui * chore: share the common deps for global app setup * spacing * Update package.json Co-authored-by: Michel EDIGHOFFER <edimitchel@gmail.com> * chore: adding OptimizationPersist + PkgConfig to reduce flake * chore: workaround for unocss hmr * chore: adding ts-ignore comments * chore: reordering data-testid * chore: ts-expect-error * --allow-empty * bug: reproduction of failing vite + cypress setup * chore: adding Vite 2.9.0-beta.3 to cold-start stability issues for UI component tests * chore: fixing types * chore: fixing types * reenabling tests * adding faker seed back in * bumping faker version Co-authored-by: Michel EDIGHOFFER <edimitchel@gmail.com> Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
- Loading branch information
1 parent
5010439
commit 7952647
Showing
23 changed files
with
822 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/ui/client/components/dashboard/DashboardEntry.cy.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import faker from '@faker-js/faker' | ||
import DashboardEntry from './DashboardEntry.vue' | ||
|
||
const body = () => (<div data-testid="body-content">{ faker.lorem.words(2) }</div>) | ||
const header = () => (<div data-testid="header-content">{ faker.hacker.phrase() }</div>) | ||
const bodySelector = '[data-testid=body-content]' | ||
const headerSelector = '[data-testid=header-content]' | ||
const tailSelector = '[data-testid=tail]' | ||
|
||
describe('DashboardEntry', () => { | ||
it('tail is rendered by default', () => { | ||
cy.mount(<DashboardEntry v-slots={{ body, header }}/>) | ||
.get(tailSelector) | ||
.should('exist') | ||
}) | ||
|
||
it('tail is not shown when true', () => { | ||
cy.mount(<DashboardEntry tail v-slots={{ body, header }}/>) | ||
.get(tailSelector) | ||
.should('not.exist') | ||
}) | ||
|
||
it('renders the body and header slots', () => { | ||
cy.mount(<DashboardEntry v-slots={{ body, header }}/>) | ||
.get(bodySelector) | ||
.should('be.visible') | ||
.get(headerSelector) | ||
.should('be.visible') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/// <reference types="vite-plugin-pages/client" /> | ||
|
||
import { createRouter as _createRouter, createWebHistory } from 'vue-router' | ||
import FloatingVue, { VTooltip } from 'floating-vue' | ||
import routes from 'virtual:generated-pages' | ||
import 'd3-graph-controller/default.css' | ||
import 'splitpanes/dist/splitpanes.css' | ||
import '@unocss/reset/tailwind.css' | ||
import 'codemirror/lib/codemirror.css' | ||
import 'codemirror-theme-vars/base.css' | ||
import './styles/main.css' | ||
import 'floating-vue/dist/style.css' | ||
import 'uno.css' | ||
|
||
export const directives = { | ||
tooltip: VTooltip, | ||
} | ||
|
||
FloatingVue.options.instantMove = true | ||
FloatingVue.options.distance = 10 | ||
|
||
export const createRouter = () => _createRouter({ | ||
history: createWebHistory(import.meta.env.BASE_URL), | ||
routes, | ||
}) | ||
|
||
export const plugins = [createRouter] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,15 @@ | ||
import { createApp } from 'vue' | ||
import { createRouter, createWebHistory } from 'vue-router' | ||
import routes from 'virtual:generated-pages' | ||
import FloatingVue, { VTooltip } from 'floating-vue' | ||
import { directives, plugins } from './global-setup' | ||
import App from './App.vue' | ||
|
||
import 'd3-graph-controller/default.css' | ||
import 'splitpanes/dist/splitpanes.css' | ||
import '@unocss/reset/tailwind.css' | ||
import 'codemirror/lib/codemirror.css' | ||
import 'codemirror-theme-vars/base.css' | ||
import 'floating-vue/dist/style.css' | ||
import './styles/main.css' | ||
import 'uno.css' | ||
|
||
const app = createApp(App) | ||
const router = createRouter({ | ||
history: createWebHistory(import.meta.env.BASE_URL), | ||
routes, | ||
|
||
plugins.forEach((plugin) => { | ||
app.use(plugin) | ||
}) | ||
app.use(router) | ||
|
||
app.directive('tooltip', VTooltip) | ||
FloatingVue.options.instantMove = true | ||
FloatingVue.options.distance = 10 | ||
Object.entries(directives).forEach(([name, directive]) => { | ||
app.directive(name, directive) | ||
}) | ||
|
||
app.mount('#app') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"testFiles": "**/*.cy.{js,ts,jsx,tsx}", | ||
"componentFolder": "client", | ||
"supportFile": "cypress/support/index.ts", | ||
"pluginsFile": "cypress/plugins/index.ts", | ||
"fixturesFolder": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import path from 'path' | ||
import { startDevServer } from '@cypress/vite-dev-server' | ||
|
||
const plugin: Cypress.PluginConfig = (on, config) => { | ||
on('dev-server:start', options => startDevServer({ | ||
options, | ||
viteConfig: { | ||
configFile: path.resolve(__dirname, './vite.config.ts'), | ||
}, | ||
})) | ||
|
||
return config | ||
} | ||
|
||
export default plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { defineConfig } from 'vite' | ||
import vueJsx from '@vitejs/plugin-vue-jsx' | ||
import { config } from '../../vite.config' | ||
|
||
config.plugins?.push(vueJsx()) | ||
|
||
export default defineConfig(config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import faker from '@faker-js/faker' | ||
import '../../client/global-setup' | ||
|
||
import { registerMount } from './mount' | ||
|
||
before(() => { | ||
faker.seed(0) | ||
}) | ||
|
||
registerMount() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { mount } from '@cypress/vue' | ||
import type { Component } from 'vue' | ||
import { directives, plugins } from '../../client/global-setup' | ||
|
||
export const registerMount = () => Cypress.Commands.add( | ||
'mount', | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
<C extends Parameters<typeof mount>[0]>(comp: any, options: any = {}) => { | ||
options.global = options.global || {} | ||
options.global.stubs = options.global.stubs || {} | ||
options.global.stubs.transition = false | ||
options.global.plugins = options.global.plugins || [] | ||
options.global.directives = directives | ||
plugins?.forEach((pluginFn: () => any) => { | ||
options?.global?.plugins?.push(pluginFn()) | ||
}) | ||
|
||
return mount(comp, options) | ||
}, | ||
) | ||
|
||
declare global { | ||
namespace Cypress { | ||
interface Chainable { | ||
/** | ||
* Install all vue plugins and globals then mount | ||
*/ | ||
mount<Props = any>(comp: Component<Props>, options?: unknown): Cypress.Chainable<any> | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
{ | ||
"compilerOptions": { | ||
"jsx": "preserve" | ||
}, | ||
"extends": "../../tsconfig.json", | ||
"exclude": ["dist", "node_modules"] | ||
} |
Oops, something went wrong.