cypress-cache-variant.js 677 B

1234567891011121314151617181920212223
  1. const path = require('path')
  2. // Returns the cache subdirectory name for the current Cypress CT variant,
  3. // or null when CYPRESS_RESULTS is not set.
  4. // Throws if the derived basename is unsafe to prevent path traversal or
  5. // absolute-path escapes.
  6. function cypressCacheVariant() {
  7. if (!process.env.CYPRESS_RESULTS) return null
  8. const variant = path.basename(process.env.CYPRESS_RESULTS)
  9. if (
  10. !variant ||
  11. variant === '.' ||
  12. variant === '..' ||
  13. path.isAbsolute(variant)
  14. ) {
  15. throw new Error(
  16. `CYPRESS_RESULTS must resolve to a safe basename; got "${process.env.CYPRESS_RESULTS}"`
  17. )
  18. }
  19. return variant
  20. }
  21. module.exports = cypressCacheVariant