Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError when launching cypress open-ct #17373

Closed
ewagoner opened this issue Jul 16, 2021 · 7 comments · Fixed by #17624
Closed

TypeError when launching cypress open-ct #17373

ewagoner opened this issue Jul 16, 2021 · 7 comments · Fixed by #17624
Labels
npm: @cypress/vite-dev-server @cypress/vite-dev-server package issues

Comments

@ewagoner
Copy link

ewagoner commented Jul 16, 2021

Current behavior

I'm trying to launch the UI in component test mode, using @cypress/vite-dev-server. It crashes before it can start with this error:

  cypress:server:plugins call event dev-server:start for invocation id inv1 +3ms
  cypress:server:plugins:child execute plugin event: dev-server:start ({ eventId: 2, invocationId: 'inv1' }) +105ms
  cypress:vite-dev-server:start starting vite dev server +0ms
  cypress:vite-dev-server:start the resolved server config is {
  cypress:vite-dev-server:start   "base": "/__cypress/src/",
  cypress:vite-dev-server:start   "root": "/Users/ericwagoner/iinteractive/neochromosome/rf/packages/int-app",
  cypress:vite-dev-server:start   "plugins": [
  cypress:vite-dev-server:start     {
  cypress:vite-dev-server:start       "name": "cypress-transform-html",
  cypress:vite-dev-server:start       "enforce": "pre"
  cypress:vite-dev-server:start     }
  cypress:vite-dev-server:start   ],
  cypress:vite-dev-server:start   "resolve": {},
  cypress:vite-dev-server:start   "server": {
  cypress:vite-dev-server:start     "port": 3000
  cypress:vite-dev-server:start   },
  cypress:vite-dev-server:start   "optimizeDeps": {
  cypress:vite-dev-server:start     "entries": [
  cypress:vite-dev-server:start       false
  cypress:vite-dev-server:start     ]
  cypress:vite-dev-server:start   }
  cypress:vite-dev-server:start } +12ms
  cypress:vite-dev-server:plugin transformIndexHtml with base /__cypress/src/ +0ms
  cypress:server:plugins promise rejected for id inv1 ':' TypeError: Patterns must be a string (non empty) or an array of strings
    at assertPatternsInput (/Users/ericwagoner/iinteractive/neochromosome/rf/packages/int-app/node_modules/fast-glob/out/index.js:64:15)
    at glob (/Users/ericwagoner/iinteractive/neochromosome/rf/packages/int-app/node_modules/fast-glob/out/index.js:9:5)
    at globEntries (/Users/ericwagoner/iinteractive/neochromosome/rf/packages/int-app/node_modules/vite/src/node/optimizer/scan.ts:118:10)
    at scanImports (/Users/ericwagoner/iinteractive/neochromosome/rf/packages/int-app/node_modules/vite/src/node/optimizer/scan.ts:55:21)
    at optimizeDeps (/Users/ericwagoner/iinteractive/neochromosome/rf/packages/int-app/node_modules/vite/src/node/optimizer/index.ts:156:33)
    at runOptimize (/Users/ericwagoner/iinteractive/neochromosome/rf/packages/int-app/node_modules/vite/src/node/server/index.ts:541:46)
    at Server.httpServer.listen (/Users/ericwagoner/iinteractive/neochromosome/rf/packages/int-app/node_modules/vite/src/node/server/index.ts:555:15) +0ms

Desired behavior

I'm just trying to start the UI in Component Testing mode

Test code to reproduce

My plugins index.ts is very bare-bones:

import { startDevServer } from "@cypress/vite-dev-server";

module.exports = (on, config) => {
  on("dev-server:start", (options) =>
    startDevServer({
      options,
      viteConfig: {},
    })
  );

  return config;
};

Cypress Version

7.7.0

Other

No response

@jennifer-shehane
Copy link
Member

I don't believe you need to return config here anymore, but I don't see why that would cause the issue you're seeing.

@ewagoner
Copy link
Author

I've removed the config bit and verified I'm still seeing the same error.

index.ts

import { startDevServer } from "@cypress/vite-dev-server";

module.exports = (on) => {
  on("dev-server:start", (options) =>
    startDevServer({
      options,
      viteConfig: {},
    })
  );
};

@ewagoner
Copy link
Author

ewagoner commented Jul 28, 2021

I've upgraded cypress to v8.0.0, @cypress/vite-dev-server to v2.0.2, and vite to v2.4.4. I've removed all config for svelte, vite, postcss, and cypress, so all are using default settings. I'm still getting the error. fast-glob is used by vite to import multiple files at once, and I'm not using that feature. Interacting directly with vite has been fine -- this only occurs when going through @cypress/vite-dev-server

@elevatebart elevatebart added the npm: @cypress/vite-dev-server @cypress/vite-dev-server package issues label Jul 28, 2021
@elevatebart
Copy link
Contributor

Hello @ewagoner I am investigating the issue,

Can you share your vite.config.ts, and your package.json please, this would help a lot?
Also, if you have time, I hope you can try to make a repository where I can reproduce?

It seems like you are using SvelteJs which cypress does not support officially yet (though we plan to).
Would you be interested in helping us test it?

@ewagoner
Copy link
Author

ewagoner commented Jul 28, 2021

I'd love to help, @elevatebart ! I had no idea svelte was not supported by Cypress. I've used in on a number of svelte projects (though not the new component testing, obvs.) and there are countless blog posts and tutorials out there about using cypress with svelte.

I get this error even with a completely blank vite.config.js so I'm confident nothing in there is causing it. Here it is, though:

import { optimizeCss } from "carbon-preprocess-svelte";
import dotenv from "dotenv";
import replace from "@rollup/plugin-replace";
import { svelte } from "@sveltejs/vite-plugin-svelte";
import { defineConfig } from "vite";

dotenv.config({ path: new URL("./config/local.env", import.meta.url) });

// https://vitejs.dev/config/
export default defineConfig({
  envDir: "config",
  optimizeDeps: {
    exclude: ["svelte-navigator"],
    include: ["flatpickr/dist/plugins/rangePlugin"],
  },
  plugins: [
    optimizeCss(),
    replace({
      preventAssignment: true,
      API_URL: JSON.stringify(process.env.API_URL),
    }),
    svelte(),
  ],
  server: {
    port: 5002,
  },
});

And here is my package.json:

{
  "name": "our_name",
  "description": "our_description",
  "version": "1.0.0",
  "private": true,
  "engines": {
    "node": ">=14.17",
    "npm": ">=6.14"
  },
  "scripts": {
    "build": "npm-run-all -s gitVersion:update server:prod",
    "clean": "rm -f src/gitVersion.json",
    "cypress": "NODE_APP_INSTANCE=local-development cypress open",
    "cypress:all": "NODE_APP_INSTANCE=local-development npm-run-all -p cypress dev",
    "dev": "npm-run-all -s gitVersion:update server:dev",
    "gitVersion:update": "../../utils/get-git-version > src/gitVersion.json",
    "lint": "npm-run-all gitVersion:update --parallel lint:eslint lint:prettier lint:validate",
    "lint:eslint": "eslint .",
    "lint:prettier": "prettier -c .",
    "lint:validate": "svelte-check --tsconfig ./tsconfig.json",
    "pre-commit": "lint-staged",
    "server:dev": "vite",
    "server:prod": "vite build",
    "start": "vite preview --port 5002"
  },
  "type": "module",
  "eslintConfig": {
    "plugins": [
      "cypress",
      "import",
      "svelte3"
    ],
    "extends": [
      "plugin:cypress/recommended"
    ],
    "env": {
      "browser": true,
      "es6": true,
      "mocha": true,
      "node": true
    },
    "globals": {
      "Atomics": "readonly",
      "SharedArrayBuffer": "readonly"
    },
    "ignorePatterns": [
      "/dist/*",
      "bundle.js",
      "**/*.svelte"
    ],
    "overrides": [
      {
        "files": [
          "**/*.svelte"
        ],
        "processor": "svelte3/svelte3",
        "rules": {
          "import/prefer-default-export": "off",
          "import/no-mutable-exports": "off",
          "import/first": "off"
        }
      }
    ]
  },
  "lint-staged": {
    "*.css": [
      "prettier --list-different"
    ],
    "*.[jt]s": [
      "prettier --list-different",
      "eslint"
    ],
    "*.json": [
      "prettier --list-different"
    ],
    "*.svelte": [
      "prettier --list-different",
      "eslint",
      "svelte-check"
    ],
    "*.ya?ml": [
      "prettier --list-different"
    ]
  },
  "devDependencies": {
    "@cypress/vite-dev-server": "^2.0.2",
    "@rollup/plugin-replace": "^2.4.2",
    "@sveltejs/vite-plugin-svelte": "1.0.0-next.14",
    "@tsconfig/svelte": "^2.0.1",
    "@types/node": "^16.3.0",
    "carbon-components-svelte": "^0.40.0",
    "carbon-icons-svelte": "^10.35.0",
    "carbon-preprocess-svelte": "^0.6.0",
    "cypress": "^8.0.0",
    "dotenv": "^10.0.0",
    "eslint": "^7.30.0",
    "eslint-plugin-cypress": "^2.11.3",
    "eslint-plugin-import": "^2.23.4",
    "eslint-plugin-svelte3": "^3.2.0",
    "lint-staged": "^11.0.0",
    "npm-run-all": "^4.1.5",
    "postcss": "^8.3.5",
    "postcss-cli": "^8.3.1",
    "prettier": "^2.3.2",
    "prettier-plugin-svelte": "^2.3.1",
    "sass": "^1.35.2",
    "svelte-check": "^2.2.2",
    "svelte-preprocess": "^4.7.4",
    "svelte-waypoint": "^0.1.4",
    "tailwindcss": "^2.2.4",
    "tslib": "^2.3.0",
    "typescript": "^4.3.5",
    "vite": "^2.4.4"
  },
  "dependencies": {
    "axios": "^0.21.1",
    "svelte": "^3.38.3",
    "svelte-navigator": "^3.1.5"
  }
}

@elevatebart
Copy link
Contributor

@ewagoner

I misspoke, and I apologize. Svelte is absolutely supported with the e2e runner. And yo u are right to make it clearer. What is unsupported is the svelte component testing part.

It is not official and we are working towards making it so.

Sorry for the confusion.

Regarding the bug you are seeing it seems to be in the scanning that vite does for dependencies.
Let me track that down.

elevatebart added a commit that referenced this issue Aug 5, 2021
When there is no values, in the optimization array,
supportFile can be a boolean. the final optimized entry passed to
fast-glog is then `[false]` whic crashes cypress.

This protects against the no-spec issue

closes #17373
elevatebart pushed a commit that referenced this issue Aug 6, 2021
…pecs found (#17624)

* fix: no supportfile + no specs, vite don't crash

When there is no values, in the optimization array,
supportFile can be a boolean. the final optimized entry passed to
fast-glog is then `[false]` whic crashes cypress.

This protects against the no-spec issue

closes #17373

* fix: protect startServer from undefined specs
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Aug 6, 2021

The code for this is done in cypress-io/cypress#17624, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

elevatebart pushed a commit that referenced this issue Aug 6, 2021
…pecs found (#17624)

* fix: no supportfile + no specs, vite don't crash

When there is no values, in the optimization array,
supportFile can be a boolean. the final optimized entry passed to
fast-glog is then `[false]` whic crashes cypress.

This protects against the no-spec issue

closes #17373

* fix: protect startServer from undefined specs
elevatebart pushed a commit that referenced this issue Aug 10, 2021
#17641)

* fix: prevent vite from crashing where there are no support files or specs found (#17624)

* fix: no supportfile + no specs, vite don't crash

When there is no values, in the optimization array,
supportFile can be a boolean. the final optimized entry passed to
fast-glog is then `[false]` whic crashes cypress.

This protects against the no-spec issue

closes #17373

* fix: protect startServer from undefined specs

* fix: when there are specs but the supportFile is undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
npm: @cypress/vite-dev-server @cypress/vite-dev-server package issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants