Nanciee / cypress-autorecord

Simplify API mocking by auto-recording/stubbing HTTP interactions and automating the process of updating/deleting mocks.
223 stars 53 forks source link

Fix mock filename when running all specs #37

Open mhssmnn opened 3 years ago

mhssmnn commented 3 years ago

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

Nanciee commented 3 years ago

@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.

mhssmnn commented 3 years ago

@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 commented 3 years ago

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.