Bird
0
0

Identify the error in this plugin code:

medium📝 Debug Q14 of 15
Cypress - Plugins and Ecosystem
Identify the error in this plugin code:
module.exports = (on, config) => {
  on('task', {
    readFile(path) {
      return fs.readFileSync(path, 'utf8')
    }
  })
}
AMissing import of 'fs' module
BWrong event name instead of 'task'
CIncorrect return type for readFile
DPlugin file should be JSON, not JS
Step-by-Step Solution
Solution:
  1. Step 1: Check code dependencies

    The code uses fs.readFileSync but does not import the 'fs' module, causing a runtime error.
  2. Step 2: Verify other parts

    The event name 'task' is correct, return type is valid, and plugin files are JavaScript files.
  3. Final Answer:

    Missing import of 'fs' module -> Option A
  4. Quick Check:

    Using fs without import causes error = B [OK]
Quick Trick: Always import Node modules before use in plugins [OK]
Common Mistakes:
  • Assuming event name is wrong
  • Thinking return type must be a promise
  • Believing plugin files must be JSON

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes