bahmutov / cypress-split

Split Cypress specs across parallel CI machines for speed
MIT License
213 stars 24 forks source link

timing #175

Closed hooman-mirghasemi closed 10 months ago

hooman-mirghasemi commented 10 months ago

when I use CucumberPreprocessorPlugin my config is like this:

`

async setupNodeEvents(
  on: Cypress.PluginEvents,
  config: Cypress.PluginConfigOptions
): Promise<Cypress.PluginConfigOptions> {
  cypressSplit(on, config);
  await addCucumberPreprocessorPlugin(on, config);

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

  on(
    'after:spec',
    (spec: Cypress.Spec, results: CypressCommandLine.RunResult) => {
      if (results && results.video) {

        const failures = results.tests.some((test) =>
          test.attempts.some((attempt) => attempt.state === 'failed')
        )
        if (!failures) {

          fs.unlinkSync(results.video)
        }
      }
    }
  )

  return config;
},

`

then timing.json does not update and also console log timing duration dose not show

bahmutov commented 10 months ago

Can you please create a small repo with your configuration and all settings, otherwise I cannot debug it.

hooman-mirghasemi commented 10 months ago

I found the problem when move cypressSplit(on, config); to end of function before return config; it works correctly but now the problem is this part of my code doesn't work any more:

on( 'after:spec', (spec: Cypress.Spec, results: CypressCommandLine.RunResult) => { if (results && results.video) {

    const failures = results.tests.some((test) =>
      test.attempts.some((attempt) => attempt.state === 'failed')
    )
    if (!failures) {

      fs.unlinkSync(results.video)
    }
  }
}

)

I think cypressSplit(on, config); some where rewrite the after:spec

hooman-mirghasemi commented 10 months ago

Just need to add

on( 'after:spec', (spec: Cypress.Spec, results: CypressCommandLine.RunResult) => { console.log("ddd"); } )

after cypressSplit(on, config);

config file will be like this:

`import { defineConfig } from 'cypress' import cypressSplit from 'cypress-split'

module.exports = defineConfig({ e2e: { // baseUrl, etc supportFile: false, fixturesFolder: false, video: false, setupNodeEvents(on, config) { cypressSplit(on, config);

  on(
    'after:spec',
    (spec: Cypress.Spec, results: CypressCommandLine.RunResult) => {
      console.log("ddd");
    }
  )
  // IMPORTANT: return the config object
  return config
},

}, })`

then you see:

cypress-split: here are passing spec timings { "durations": [] } cypress-split: spec timings unchanged

durations is empty in the console.

I test it with your repo: cypress-split-timings-example

hooman-mirghasemi commented 10 months ago

Do you see the problem? how can I solve it? I want to use both of after:spec and cypressSplit(on, config); in my config file

bahmutov commented 10 months ago

Yeah, I think because this plugin and your code register on('after:spec' callbacks, Cypress has a bug. Luckily I have a fix: https://github.com/bahmutov/cypress-on-fix

hooman-mirghasemi commented 10 months ago

Thank you, it works Do you ever report this bug to the Cypress team?

bahmutov commented 10 months ago
Screenshot 2023-11-30 at 10 51 14

yes