cypress-autorecord icon indicating copy to clipboard operation
cypress-autorecord copied to clipboard

Fix mock filename when running all specs

Open mhssmnn opened this issue 4 years ago • 3 comments

When running all specs, the mocks are recorded in a new file called "All Specs". This pull request attempts to find the filename based on the currentTest invocation details. AFAIK currentTest.invocationDetails is an undocumented api (Cypress adds it to mocha's Test instance). However this really helps when you want to run all specs on a CI server, but still maintain individual mock files.

Cypress v5.4.0

mhssmnn avatar Dec 22 '20 01:12 mhssmnn

@mhssmnn Thanks for the PR! Would this change how any existing tests are stored? I want to make sure this is properly marked if it is a breaking change.

Nanciee avatar Jan 04 '21 17:01 Nanciee

@Nanciee Thanks for the plugin :). Yes it will be a breaking change.

If you ran all the tests before it would create/use a file called All Specs.json, whereas now it would use the individual testFile.spec.json that is created for each individual test file. I wasn't sure if this was the intended behavior, but this is definitely how I'd prefer it.

Also, see my note that it uses undocumented api to get the test filename, so it may break in the future. We could always start a discussion with the Cypress folks to see if they would support a way of getting the current test file when running all the tests.

mhssmnn avatar Jan 05 '21 01:01 mhssmnn

Just realised that Cypress has experimental support for listening to before:spec events, which include the spec filename as an argument. So it's probably wise to move to using that once it's out of experimental stage.

mhssmnn avatar Jan 05 '21 01:01 mhssmnn