bahmutov / cypress-svelte-unit-test

Unit testing Svelte components in Cypress E2E test runner
162 stars 21 forks source link

Please place the spec in component folder #300

Open pleymor opened 2 years ago

pleymor commented 2 years ago

Hi! I follow the guidelines but am unable to run cypress unit tests on vite + svelte.

I get the error:

In order to use mount or unmount functions please place the spec in component folder

I simply created a new project with:

npm create vite@latest

Then installed cypress to finally get:

package.json

  "devDependencies": {
    "@cypress/vite-dev-server": "^2.2.2",
    "@tsconfig/svelte": "^2.0.1",
    "cypress": "^9.6.0",
    "cypress-svelte-unit-test": "^3.3.4",
    "svelte": "^3.44.0",
    "svelte-check": "^2.2.7",
    "svelte-preprocess": "^4.9.8",
    "tslib": "^2.3.1",
    "typescript": "^4.5.4",
    "vite": "^2.9.7"
  },
  "dependencies": {
    "svelte-navigator": "^3.1.5"
  }

cypress/plugins/index.ts

const path = require('path')
import { startDevServer } from '@cypress/vite-dev-server';

/**
 * @type {Cypress.PluginConfig}
 */
export default (on, config) => {
    on('dev-server:start', (options) => {
        return startDevServer({
            options,
            viteConfig: {
                configFile: path.resolve(__dirname, '..', '..', 'vite.config.js'),
            },
        })
    })
}

cypress.json

{
  "projectId": "q8zv52",
  "video": false,
  "testFiles": "**/*.cy-spec.ts",
  "componentFolder": "src"
}

vite.config.js

import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [svelte()]
})

src/App.cy-spec.ts

import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [svelte()]
})

Using node 16 on ubuntu 22.04.

Actual behavior

npm run cy:run-ct

1) App renders App with correct heading: Error: In order to use mount or unmount functions please place the spec in component folder

Thank you!