Bird
0
0

What is wrong with this plugin code?

medium📝 Debug Q7 of 15
Cypress - Plugins and Ecosystem
What is wrong with this plugin code?
module.exports = (on, config) => {
  on('task', {
    readFile(path) {
      const fs = require('fs')
      return fs.readFileSync(path, 'utf8')
    }
  })
  return config
}
AThe plugin function should return config, but it is missing a return statement
BThe require('fs') call is invalid inside plugins
CThe plugin function correctly returns config, no error
DThe task function readFile must be asynchronous
Step-by-Step Solution
Solution:
  1. Step 1: Check plugin function return value

    The plugin function returns config at the end, which is correct and required.
  2. Step 2: Validate usage of require and task function

    Using require('fs') inside plugins is valid. The task returns file content synchronously, which is allowed. The remaining options are incorrect.
  3. Final Answer:

    The plugin function correctly returns config, no error -> Option C
  4. Quick Check:

    Plugin returns config and uses require correctly [OK]
Quick Trick: Return config from plugin function [OK]
Common Mistakes:
  • Forgetting to return config
  • Thinking require is disallowed
  • Assuming tasks must be async

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes