Running into a small issue with using this package, specifically in regards to using the --project
flag on cypress and using the KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true
env variable. Bit of a text dump here, sorry about that 😅 . For context, I'm using Bitbucket Pipelines, and the config file looks something like
- step:
name: Cypress 1/N
script:
- export KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true
- export KNAPSACK_PRO_TEST_FILE_PATTERN=subdir1/subdir2/cypress/integration/**/*.js
- <All other knapsack pro env variables set appropriately>
- yarn install --frozen-lockfile
- yarn cypress install
- yarn run knapsack-pro-cypress --project subdir1/subdir2
On first run, this works great. However, when rerunning a failed pipeline, instead of passing in the file paths as subdir1/subdir2/cypress/integration/<sometestfile>
, cypress seems to be instead called with cypress/integration/<sometestfile>
, which results in an error that looks like:
Can't run because no spec files were found.
We searched for any files matching this glob pattern:
../../cypress/integration/<sometestfile>.
I did a bit of digging about why this might be, and in the knapsack-pro-cypress.ts, line 61 you have:
const recordedTestFiles: TestFile[] = tests.map((test: any) => ({
path: test.spec.relative,
time_execution:
// test.stats.wallClockDuration - Cypress 3.x and 4.x
// test.stats.duration - Cypress 5.x
(test.stats.wallClockDuration || test.stats.duration) / 1000,
}));
Based on what cypress says in their code here: https://github.com/cypress-io/cypress/blob/4d76049d2c419d77968beafcdda45585744fc542/cli/types/cypress-npm-api.d.ts, test.spec.relative
returns paths relative to the project root. So, because I set the project root to be subdir1/subdir2
, the path returned by test.spec.relative
will be cypress/integration/<sometestfile>
. Not going to pretend I know how the internals of the API (or client for that matter) work, but I'm assuming that this is later used to deal with rerunning a pipeline when the KNAPSACK_PRO_FIXED_QUEUE_SPLIT
env var is set to true.
So, the file path that cypress is called with on the first and 2nd run will be different, and while the first run works great, any reruns of the pipeline will break.
I think the solution to this could either be as simple as changing test.spec.relative
to test.spec.absolute
, or by just using the file paths that are originally provided instead of the file paths that cypress.run
returns. FWIW, I think the first solution I proposed might not work for all CI runners, for example if the absolute path would change on rerun (haven't seen this for bitbucket but it could be the case for other CI runners), but I think the second solution would probably work?
More than happy to put up a PR for this with either proposed solution, just let me know!
Thanks!!