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

Cypress runs failing in Github Actions. Threw 'TypeError: patterns.reduce is not a function error' under cypressSplit(on, config) #78

Closed
fatinfarzanaazizan opened this issue Jul 5, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@fatinfarzanaazizan
Copy link

Hi, thank you so much for creating cypress-split. It's a very helpful tool.

It seems that a few days ago, my cypress job runs in Github Actions are failing with the error below. No changes were done from my side. I've tried increasing cypress version and such but no luck. Could you help to determine what might've caused this issue? I've also included my cypress.config.js file below for reference. thank you.

The error was thrown while executing your e2e.setupNodeEvents() function:

TypeError: patterns.reduce is not a function
    at Object.expandPatternsWithBraceExpansion (/home/runner/work/AutomationCypress/node_modules/fast-glob/out/utils/pattern.js:131:21)
    at processPatterns (/home/runner/work/AutomationCypress/node_modules/fast-glob/out/managers/tasks.js:27:34)
    at Object.generate (/home/runner/work/AutomationCypress/node_modules/fast-glob/out/managers/tasks.js:7:20)
    at getWorks (/home/runner/work/AutomationCypress/node_modules/fast-glob/out/index.js:91:31)
    at AsyncFunction.sync (/home/runner/work/AutomationCypress/node_modules/fast-glob/out/index.js:23:23)
    at AsyncFunction.module.exports.sync (/home/runner/work/AutomationCypress/node_modules/globby/index.js:151:42)
    at findCypressSpecsV10 (/home/runner/work/AutomationCypress/node_modules/find-cypress-specs/src/index.js:150:24)
    at findCypressSpecs (/home/runner/work/AutomationCypress/node_modules/find-cypress-specs/src/index.js:233:21)
    at getSpecs (/home/runner/work/AutomationCypress/node_modules/find-cypress-specs/src/index.js:210:10)
    at cypressSplit (/home/runner/work/AutomationCypress/node_modules/cypress-split/src/index.js:94:15)
    at setupNodeEvents (/home/runner/work/AutomationCypress/cypress.config.js:11:3)

cypress.config.js file:

const { defineConfig } = require("cypress")
const createBundler = require("@bahmutov/cypress-esbuild-preprocessor")
const cucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor")
const createEsbuildPlugin = require("@badeball/cypress-cucumber-preprocessor/esbuild")
const cypressSplit = require('cypress-split')

async function setupNodeEvents(cypressOn, config) {
  const on = require('cypress-on-fix')(cypressOn)
  // This is required for the preprocessor to be able to generate JSON reports after each run, and more,
  await cucumberPreprocessor.addCucumberPreprocessorPlugin(on, config)
  cypressSplit(on, config)

  on(
    "file:preprocessor", 
      createBundler({
        plugins: [createEsbuildPlugin.default(config)],
      })
  );

  on('task', {
    log(message) {
      console.log(message)
      return null
    }
  })

  // Make sure to return the config object as it might have been modified by the plugin.
  return config
}

module.exports = defineConfig({
  e2e: {
    specPattern: "**/*.feature",
    supportFile: false,
    setupNodeEvents,
    experimentalSessionAndOrigin: true,
    chromeWebSecurity: false
    },
});

version:
"cypress-split": "^1.3.12"
"cypress": "^11.2.0"

related github actions versions:
cypress-io/github-action@v5
runs-on: ubuntu-22.04

@fatinfarzanaazizan fatinfarzanaazizan changed the title Cypress run stopped working in Github Actions. Threw TypeError: patterns.reduce is not a function error under cypress-split Cypress runs failing in Github Actions. Threw TypeError: patterns.reduce is not a function error under cypress-split Jul 5, 2023
@fatinfarzanaazizan fatinfarzanaazizan changed the title Cypress runs failing in Github Actions. Threw TypeError: patterns.reduce is not a function error under cypress-split Cypress runs failing in Github Actions. Threw 'TypeError: patterns.reduce is not a function error' under cypress-split Jul 5, 2023
@fatinfarzanaazizan fatinfarzanaazizan changed the title Cypress runs failing in Github Actions. Threw 'TypeError: patterns.reduce is not a function error' under cypress-split Cypress runs failing in Github Actions. Threw 'TypeError: patterns.reduce is not a function error' under cypressSplit(on, config) Jul 5, 2023
@bahmutov
Copy link
Owner

bahmutov commented Jul 5, 2023

Hello,
Can you try using exact version of this plugin and go back to find the last working version https://github.com/bahmutov/cypress-split/releases ?
Also, for the breaking version, can you provide the DEBUG logs? https://github.com/bahmutov/cypress-split#debugging

@bahmutov bahmutov added the bug Something isn't working label Jul 5, 2023
@fatinfarzanaazizan
Copy link
Author

fatinfarzanaazizan commented Jul 6, 2023

Hi @bahmutov, thanks for your reply. The version that used to work (1.3.12) is the same as the version that's failing. It started failing on github actions 5 days ago.

Included the debug logs for reference

Run cypress-io/github-action@v5
/usr/local/bin/yarn --frozen-lockfile
yarn install v1.22.19
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.54s.
/opt/hostedtoolcache/node/14.21.3/x64/bin/npx cypress cache list
┌─────────┬──────────────┐
│ version │ last used    │
├─────────┼──────────────┤
│ 11.2.0  │ 7 months ago │
└─────────┴──────────────┘
/opt/hostedtoolcache/node/14.21.3/x64/bin/npx cypress verify

[STARTED] Task without title.
[SUCCESS] Task without title.
/usr/bin/tar --posix -cf cache.tzst --exclude cache.tzst -P -C /home/runner/work/qualityAssuranceAutomation/qualityAssuranceAutomation --files-from manifest.txt --use-compress-program zstdmt
Cache Size: ~379 MB (397439308 B)
Cache saved successfully
/usr/bin/tar --posix -cf cache.tzst --exclude cache.tzst -P -C /home/runner/work/qualityAssuranceAutomation/qualityAssuranceAutomation --files-from manifest.txt --use-compress-program zstdmt
Cache Size: ~148 MB ([15](https://github.com/popmeals/qualityAssuranceAutomation/actions/runs/5473373123/jobs/9966761136#step:10:16)5450544 B)
Cache saved successfully
[2780:0706/084254.885439:ERROR:gpu_memory_buffer_support_x11.cc(44)] dri3 extension not supported.
Couldn't find tsconfig.json. tsconfig-paths will be skipped
  cypress-split Cypress config env +0ms
  cypress-split {
  cypress-split   CACHE_FOLDER: '/home/runner/.cache/Cypress',
  cypress-split   __cypress_cucumber_preprocessor_dont_use_this_suite: { isEventHandlersAttached: true }
  cypress-split } +1ms
  find-cypress-specs finding specs of type e2e +0ms
  find-cypress-specs Cypress version 11.2.0 +0ms
  find-cypress-specs treating options as Cypress version 11 +0ms
  find-cypress-specs config has "e2e" property, treating as Cypress v10+ +0ms
  find-cypress-specs options v10 { specPattern: '**/*.feature', excludeSpecPattern: '*.hot-update.js' } +1ms
Your configFile threw an error from: /home/runner/work/qualityAssuranceAutomation/qualityAssuranceAutomation/PopMealsKioskAutomationCypress/cypress.config.js

The error was thrown while executing your e2e.setupNodeEvents() function:

TypeError: patterns.reduce is not a function
    at Object.expandPatternsWithBraceExpansion (/home/runner/work/qualityAssuranceAutomation/qualityAssuranceAutomation/PopMealsKioskAutomationCypress/node_modules/fast-glob/out/utils/pattern.js:131:21)
    at processPatterns (/home/runner/work/qualityAssuranceAutomation/qualityAssuranceAutomation/PopMealsKioskAutomationCypress/node_modules/fast-glob/out/managers/tasks.js:27:34)
    at Object.generate (/home/runner/work/qualityAssuranceAutomation/qualityAssuranceAutomation/PopMealsKioskAutomationCypress/node_modules/fast-glob/out/managers/tasks.js:7:[20](https://github.com/popmeals/qualityAssuranceAutomation/actions/runs/5473373123/jobs/9966761136#step:10:21))
    at getWorks (/home/runner/work/qualityAssuranceAutomation/qualityAssuranceAutomation/PopMealsKioskAutomationCypress/node_modules/fast-glob/out/index.js:91:31)
    at AsyncFunction.sync (/home/runner/work/qualityAssuranceAutomation/qualityAssuranceAutomation/PopMealsKioskAutomationCypress/node_modules/fast-glob/out/index.js:23:23)
    at AsyncFunction.module.exports.sync (/home/runner/work/qualityAssuranceAutomation/qualityAssuranceAutomation/PopMealsKioskAutomationCypress/node_modules/globby/index.js:151:42)
    at findCypressSpecsV10 (/home/runner/work/qualityAssuranceAutomation/qualityAssuranceAutomation/PopMealsKioskAutomationCypress/node_modules/find-cypress-specs/src/index.js:150:24)
    at findCypressSpecs (/home/runner/work/qualityAssuranceAutomation/qualityAssuranceAutomation/PopMealsKioskAutomationCypress/node_modules/find-cypress-specs/src/index.js:233:[21](https://github.com/popmeals/qualityAssuranceAutomation/actions/runs/5473373123/jobs/9966761136#step:10:22))
    at getSpecs (/home/runner/work/qualityAssuranceAutomation/qualityAssuranceAutomation/PopMealsKioskAutomationCypress/node_modules/find-cypress-specs/src/index.js:210:10)
    at cypressSplit (/home/runner/work/qualityAssuranceAutomation/qualityAssuranceAutomation/PopMealsKioskAutomationCypress/node_modules/cypress-split/src/index.js:94:15)
    at setupNodeEvents (/home/runner/work/qualityAssuranceAutomation/qualityAssuranceAutomation/PopMealsKioskAutomationCypress/cypress.config.js:11:3)

Let me know if you require more info. Thank you

@tamasmagyar
Copy link

tamasmagyar commented Jul 6, 2023

Error might be coming from fast-glob? mrmlnc/fast-glob#404

  1. cypress-split is using find-cypress-specs package
  2. find-cypress-specs is using globby
  3. globby is using fast-glob

@toriumi0118
Copy link

try adding

excludeSpecPattern: ["*.hot-update.js"]

to your cypress.config.js file. like below

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      cypressSplit(on, config);
      // IMPORTANT: return the config object
      return config;
    },
    excludeSpecPattern: ["*.hot-update.js"],
  },
});

the rest of configurations is depends on your setting.

samtsai added a commit to samtsai/find-cypress-specs that referenced this issue Jul 11, 2023
globby depends on fast-glob which introduced a breaking change in 3.3.0. Their API has been expecting an string[] for `ignore` option for awhile but in the latest version it causes a TypeError.
Make sure the `ignore` option is passed an array.

Fixes issues for: bahmutov/cypress-split#78 (comment)
@bahmutov
Copy link
Owner

Updated the code to fix. Soon will be released.

@fatinfarzanaazizan
Copy link
Author

Thanks @bahmutov! Fix is working well :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants