Cypress - Plugins and Ecosystem
Which task definition correctly reads a JSON file and returns the parsed object in
cypress.config.js?cypress.config.js?tasks: {
readJson({filePath}) {
const fs = require('fs')
const data = fs.readFileSync(filePath, 'utf8')
return JSON.parse(data)
}
} uses an object argument and parses correctly but is valid style-wise; however, the question asks for the correct definition, and tasks: {
readJson(filePath) {
const fs = require('fs')
return JSON.parse(fs.readFileSync(filePath, 'utf8'))
}
} is more standard with a single argument.tasks: {
readJson(filePath) {
const fs = require('fs')
return fs.readFileSync(filePath)
}
} returns raw buffer without parsing.tasks: {
readJson(filePath) {
const fs = require('fs')
return JSON.parse(fs.readFileSync(filePath))
}
} misses the encoding argument, so readFileSync returns a buffer, causing JSON.parse to fail.tasks: {
readJson(filePath) {
const fs = require('fs')
return JSON.parse(fs.readFileSync(filePath, 'utf8'))
}
} correctly reads the file as UTF-8 string and parses it.tasks: {
readJson(filePath) {
const fs = require('fs')
return JSON.parse(fs.readFileSync(filePath, 'utf8'))
}
} is the correct task definition.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions