bahmutov / cypress-split

Split Cypress specs across parallel CI machines for speed
MIT License
201 stars 23 forks source link

TeamCity: Invalid chunk index 1 vs all chunks 1 #113

Closed denis-domanskii closed 9 months ago

denis-domanskii commented 9 months ago

It looks like cypress-split can't handle the situation when there is only 1 chunk and chunk index is 1. I understand that it has no sense, but I really need to support such a scenario (e.g. only 1 build agent is free), and expect that all specs will be executed as usual.

Log:

[19:07:23 ] cypress-split: there are 0 found specs
[19:07:23 ] cypress-split: chunk 2 of 1
[19:07:23 ] Your configFile threw an error from: /mnt/agent/work/bb494e5cdc59eb2f/tests/cypress/cypress.config.ts
[19:07:23 ] 
[19:07:23 ] The error was thrown while executing your e2e.setupNodeEvents() function:
[19:07:23 ] 
[19:07:23 ] Error: Invalid chunk index 1 vs all chunks 1
[19:07:23 ]     at getChunk (/mnt/agent/work/bb494e5cdc59eb2f/node_modules/cypress-split/src/chunk.js:47:11)
[19:07:23 ]     at cypressSplit (/mnt/agent/work/bb494e5cdc59eb2f/node_modules/cypress-split/src/index.js:106:24)
[19:07:23 ]     at module.exports (/mnt/agent/work/bb494e5cdc59eb2f/tests/cypress/plugins/index.js:8:3)
[19:07:23 ]     at setupNodeEvents (/mnt/agent/work/bb494e5cdc59eb2f/tests/cypress/cypress.config.ts:21:43)
[19:07:23 ]     at /mnt/agent/work/bb494e5cdc59eb2f/node_modules/cypress_cache/13.3.0/Cypress/resources/app/node_modules/@packages/server/lib/plugins/child/run_plugins.js:122:14
[19:07:23 ]     at tryCatcher (/mnt/agent/work/bb494e5cdc59eb2f/node_modules/cypress_cache/13.3.0/Cypress/resources/app/node_modules/bluebird/js/release/util.js:16:23)
[19:07:23 ]     at Function.Promise.attempt.Promise.try (/mnt/agent/work/bb494e5cdc59eb2f/node_modules/cypress_cache/13.3.0/Cypress/resources/app/node_modules/bluebird/js/release/method.js:39:29)
[19:07:23 ]     at RunPlugins.load (/mnt/agent/work/bb494e5cdc59eb2f/node_modules/cypress_cache/13.3.0/Cypress/resources/app/node_modules/@packages/server/lib/plugins/child/run_plugins.js:119:9)
[19:07:23 ]     at RunPlugins.runSetupNodeEvents (/mnt/agent/work/bb494e5cdc59eb2f/node_modules/cypress_cache/13.3.0/Cypress/resources/app/node_modules/@packages/server/lib/plugins/child/run_plugins.js:59:17)
[19:07:23 ]     at EventEmitter.<anonymous> (/mnt/agent/work/bb494e5cdc59eb2f/node_modules/cypress_cache/13.3.0/Cypress/resources/app/node_modules/@packages/server/lib/plugins/child/run_require_async_child.js:185:22)
[19:07:23 ]     at EventEmitter.emit (node:events:514:28)
[19:07:23 ]     at EventEmitter.emit (node:domain:489:12)
[19:07:23 ]     at process.<anonymous> (/mnt/agent/work/bb494e5cdc59eb2f/node_modules/cypress_cache/13.3.0/Cypress/resources/app/node_modules/@packages/server/lib/plugins/util.js:33:22)
[19:07:23 ]     at process.emit (node:events:514:28)
[19:07:23 ]     at process.emit (node:domain:489:12)
[19:07:23 ]     at process.emit.sharedData.processEmitHook.installedValue [as emit] (/mnt/agent/work/bb494e5cdc59eb2f/node_modules/cypress_cache/13.3.0/Cypress/resources/app/node_modules/@cspotcode/source-map-support/source-map-support.js:745:40)
[19:07:23 ]     at emit (node:internal/child_process:951:14)
[19:07:23 ]     at processTicksAndRejections (node:internal/process/task_queues:83:21)
dannyskoog commented 9 months ago

@denis-domanskii The chunk indices are 0-based. So in your case I believe your problem is that you're starting with index 1 (i.e. SPLIT_INDEX=1), when you really should start with 0

denis-domanskii commented 9 months ago

@dannyskoog thank you!

So, how abut to start chunks from 1, not 0? This is a common way for Jest (https://jestjs.io/docs/next/cli#--shard):

jest --shard=1/3
jest --shard=2/3
jest --shard=3/3

and for Playwright (https://playwright.dev/docs/test-sharding):

npx playwright test --shard=1/4
npx playwright test --shard=2/4
npx playwright test --shard=3/4
npx playwright test --shard=4/4
dannyskoog commented 9 months ago

@denis-domanskii Sure, it's debatable whether to use 0- or 1-based indices for chunks. But even though I'm not the author of this library I don't think that such breaking change is justified.

denis-domanskii commented 9 months ago

I also think that it's late to change, but maybe some ENV variable at least? Because, for example, TeamCity CI start count batches from 1, so I need an extra step to read TeamCity generated value, subtract 1 and then pass it to cypress-split as SPLIT_INDEX. Replacing all these stuff with simple SPLIT_START_INDEX=1 make my setup much convenient.

github-actions[bot] commented 9 months ago

:tada: This issue has been resolved in version 1.6.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: