From c673749ebcbdf792709db599db56d3cb009ff645 Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Tue, 26 Sep 2023 11:12:36 +0200 Subject: [PATCH] Re-enable component testing Signed-off-by: Louis Chemineau --- cypress.config.ts | 35 ++++++++++++++++++++++++- cypress/support/component-index.html | 12 +++++++++ cypress/support/component.ts | 39 ++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 cypress/support/component-index.html create mode 100644 cypress/support/component.ts diff --git a/cypress.config.ts b/cypress.config.ts index 3dd3c7515..d580dde2d 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -1,4 +1,3 @@ - import { configureNextcloud, startNextcloud, @@ -86,4 +85,38 @@ export default defineConfig({ }) }, }, + + component: { + devServer: { + framework: 'vue', + bundler: 'webpack', + webpackConfig: async () => { + process.env.npm_package_name = 'NcCypress' + process.env.npm_package_version = '1.0.0' + process.env.NODE_ENV = 'development' + + /** + * Needed for cypress stubbing + * + * @see https://github.com/sinonjs/sinon/issues/1121 + * @see https://github.com/cypress-io/cypress/issues/18662 + */ + const babel = require('./babel.config.js') + babel.plugins.push([ + '@babel/plugin-transform-modules-commonjs', + { + loose: true, + }, + ]) + + const config = require('./webpack.js') + config.module.rules.push({ + test: /\.svg$/, + type: 'asset/source', + }) + + return config + }, + }, + }, }) diff --git a/cypress/support/component-index.html b/cypress/support/component-index.html new file mode 100644 index 000000000..ac6e79fd8 --- /dev/null +++ b/cypress/support/component-index.html @@ -0,0 +1,12 @@ + + + + + + + Components App + + +
+ + \ No newline at end of file diff --git a/cypress/support/component.ts b/cypress/support/component.ts new file mode 100644 index 000000000..28d462cdc --- /dev/null +++ b/cypress/support/component.ts @@ -0,0 +1,39 @@ +// *********************************************************** +// This example support/component.ts is processed and +// loaded automatically before your test files. +// +// This is a great place to put global configuration and +// behavior that modifies Cypress. +// +// You can change the location of this file or turn off +// automatically serving support files with the +// 'supportFile' configuration option. +// +// You can read more here: +// https://on.cypress.io/configuration +// *********************************************************** + +// Import commands.js using ES2015 syntax: +import './commands' + +// Alternatively you can use CommonJS syntax: +// require('./commands') + +import { mount } from 'cypress/vue2' + +// Augment the Cypress namespace to include type definitions for +// your custom command. +// Alternatively, can be defined in cypress/support/component.d.ts +// with a at the top of your spec. +declare global { + namespace Cypress { + interface Chainable { + mount: typeof mount + } + } +} + +Cypress.Commands.add('mount', mount) + +// Example use: +// cy.mount(MyComponent) \ No newline at end of file