Bez popisu

image-reporter.js 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // @noflow
  2. const chalk = require('chalk');
  3. const fs = require('fs');
  4. const poster = require('poster');
  5. const browser = process.env.BROWSER || 'chromium';
  6. // https://api.anonymousfiles.io/
  7. class ImageReporter {
  8. constructor(globalConfig, options) {
  9. this._globalConfig = globalConfig;
  10. this._options = options;
  11. }
  12. onTestResult(test, testResult, aggregateResults) {
  13. if (process.env.CI !== 'true') {
  14. return;
  15. }
  16. if (
  17. testResult.numFailingTests &&
  18. testResult.failureMessage.match(/different from snapshot/)
  19. ) {
  20. const files = fs.readdirSync(
  21. './tests/functional/__image_snapshots__/__diff_output__/'
  22. );
  23. files.forEach(async value => {
  24. const file = `./tests/functional/__image_snapshots__/__diff_output__/${value}`;
  25. poster.post(
  26. file,
  27. {
  28. uploadUrl: 'https://api.anonymousfiles.io/',
  29. fileId: 'file',
  30. fileContentType: 'image/png',
  31. },
  32. (err, data) => {
  33. console.log(
  34. chalk.red.bold(
  35. `[${browser}] ${value}\n${browser.replace(
  36. /./g,
  37. ' '
  38. )} Uploaded image diff file to ${JSON.parse(data).url}`
  39. )
  40. );
  41. }
  42. );
  43. });
  44. }
  45. }
  46. }
  47. module.exports = ImageReporter;