How to return multiple objects from plugins file for use with Configuration API and Code Coverage #14375
-
Hi, Currently my cypress tests are using this example for multi environment configuration which has a method to return from plugins file. so i also want to measure code coverage for my application, but when referring to documentation, it needs a different object to be returned. From what i read, we can return only single object from the plugins file. How do i achieve having both multi environment and code coverage? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
At the end of the day, you need to:
In our case, you want to first load the appropriate environment config, then send it to the code coverage's registration function // promisified fs module
const fs = require('fs-extra')
const path = require('path')
function getConfigurationByFile (file) {
const pathToConfigFile = path.resolve('..', 'config', `${file}.json`)
return fs.readJson(pathToConfigFile)
}
// plugins file
module.exports = (on, config) => {
// accept a configFile value or use development by default
const file = config.env.configFile || 'development'
const envConfig = getConfigurationByFile(file)
// now register the code coverage plugin
require('@cypress/code-coverage/task')(on, envConfig)
// notice that the code coverage plugin modifies the config
// passed as a parameter, thus we can simply return it
return envConfig
} |
Beta Was this translation helpful? Give feedback.
At the end of the day, you need to:
on
andconfig
object to each plugin that requiresconfig
file.In our case, you want to first load the appropriate environment config, then send it to the code coverage's registration function