Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
386 views
in Technique[技术] by (71.8m points)

javascript - How can I serve an instrumented folder to run my Cypress tests against?

Viewing the instrumenting code section in the Cypress documentation: https://docs.cypress.io/guides/tooling/code-coverage.html they state that you can serve the instrumented folder. 'We can see the counters if we serve the instrumented folder instead of src and open the application.'

What is the best approach for serving this? My understanding is that instrumented code only contains files where instrumentation can be added such as .js, and many files such as .html will not included in the folder, how can I serve the application with instrumentation so that I can test against it using Cypress?

question from:https://stackoverflow.com/questions/65833221/how-can-i-serve-an-instrumented-folder-to-run-my-cypress-tests-against

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Instrumenting the code is dependent on the way you serve the app, but for plain javascript (not bundled) see this blog Code Coverage for End-to-end Tests

The cp command answers your question about how to handle non-js file. Essentially everything ends up (duplicated and instrumented) in build/src.

package.json

{
  "scripts": {
    "build": "npm run instrument && npm run cp",
    "preinstrument": "npm run clean",
    "instrument": "nyc instrument --compact false src build/src",
    "cp": "cp src/*.css build/src && cp src/*.png build/src && cp index.html build",
    "clean": "rm -rf build .nyc_output || true",
    "report:coverage": "nyc report --reporter=html"
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...