log-to-test-harness.js 743 B

1234567891011121314151617181920212223242526
  1. /*
  2. * MIT License http://opensource.org/licenses/MIT
  3. * Author: Ben Holloway @bholloway
  4. */
  5. 'use strict';
  6. var stream = require('stream');
  7. var maybeStream = process[process.env.RESOLVE_URL_LOADER_TEST_HARNESS];
  8. function logToTestHarness(options) {
  9. if (!!maybeStream && (typeof maybeStream === 'object') && (maybeStream instanceof stream.Writable)) {
  10. Object.keys(options).map(eachOptionKey);
  11. maybeStream = null; // ensure we log only once
  12. }
  13. function eachOptionKey(key) {
  14. var value = options[key];
  15. var text = (typeof value === 'undefined') ?
  16. String(value) :
  17. (JSON.stringify(value.valueOf()) || '-unstringifyable-');
  18. maybeStream.write(key + ': ' + text + '\n');
  19. }
  20. }
  21. module.exports = logToTestHarness;