How to use the hooker.unhook function in hooker

To help you get started, we’ve selected a few hooker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jwarby / i18n-lint / test / lib / reporters / default.js View on Github external
});

    var expected = fs.readFileSync(
      __dirname + '/../../expected/reporters/default.txt'
    ).toString();

    // Execute method under test
    try {
      reporter(errors);
    } catch(e) {
      hooker.unhook(process.stdout, 'write');
      console.log(e);
      console.log(e.stack);
    }

    hooker.unhook(process.stdout, 'write');
    expect(actual).to.equal(expected);

    done();
  });
github jwarby / i18n-lint / test / lib / reporters / unix.js View on Github external
it('should not output anything if there are no errors', function() {
    var actual = '';

    hooker.hook(process.stdout, 'write', {
      pre: function(out) {
        actual += out;

        return hooker.preempt();
      }
    });

    // Execute
    reporter([]);

    hooker.unhook(process.stdout, 'write');

  });
});
github pghalliday / grunt-mocha-test / tasks / mocha.js View on Github external
run(function(error, failureCount) {
      // close the file if it was opened
      if (fd) {
        fs.closeSync(fd);
      }
      // Restore process.stdout.write to its original value
      hooker.unhook(process.stdout, 'write');
      // Actually test the actually-logged stdout string to the expected value
      done(error, failureCount);
    });
  };
github sitespeedio / grunt-sitespeedio / test / testBudgetOutput.js View on Github external
var stdoutEqual = function(callback, done) {
  var actual = '';
  // Hook process.stdout.write
  hooker.hook(grunt.log, ['error', 'ok'], {
    // This gets executed before the original process.stdout.write.
    pre: function(result) {
      // Concatenate uncolored result onto actual.
      actual += grunt.log.uncolor(result);
      // Prevent the original process.stdout.write from executing.
      return hooker.preempt();
    }
  });
  // Execute the logging code to be tested.
  callback();
  // Restore process.stdout.write to its original value.
  hooker.unhook(grunt.log, ['error', 'ok']);
  // Actually test the actually-logged stdout string to the expected value.
  done(actual);
};
github jwarby / i18n-lint / test / lib / reporters / json.js View on Github external
hooker.hook(process.stdout, 'write', {
      pre: function(out) {
        actual += stripAnsi(out);

        return hooker.preempt();
      }
    });

    var expected = fs.readFileSync(
      __dirname + '/../../expected/reporters/json.txt'
    ).toString();

    // Execute method under test
    reporter(errors);

    hooker.unhook(process.stdout, 'write');
    expect(actual).to.equal(expected);

    // Test that valid json is output
    expect(JSON.stringify.bind(JSON, actual)).not.to.throw.error;

    done();
  });
github sindresorhus / time-grunt / index.js View on Github external
process.once('timegruntexit', function (exitCode) {
		clearInterval(interval);

		process.exit = originalExit;
		hooker.unhook(grunt.log, 'header');

		var diff = Date.now() - prevTime;

		if (prevTaskName) {
			tableData.push([prevTaskName, diff]);
		}

		// `grunt.log.header` should be unhooked above, but in some cases it's not
		log('\n\n' + chalk.underline('Execution Time') + chalk.gray(' (' + startTimePretty + ')'));
		log(formatTable(tableData) + '\n');

		if (cb) {
			cb(tableData, function () {
				process.exit(exitCode);
			});
github gruntjs / grunt-contrib-jshint / tasks / jshint.js View on Github external
return memo + (result.error ? 1 : 0);
          }, 0);

          var numFiles = data.length;
          grunt.log.error(numErrors + ' ' + grunt.util.pluralize(numErrors, 'error/errors') + ' in ' +
                          numFiles + ' ' + grunt.util.pluralize(numFiles, 'file/files'));
        }
      } else {
        if (jshint.usingGruntReporter === true && data.length > 0) {
          grunt.log.ok(data.length + ' ' + grunt.util.pluralize(data.length, 'file/files') + ' lint free.');
        }
      }

      // Write the output of the reporter if wanted
      if (reporterOutput) {
        hooker.unhook(process.stdout, 'write');
        reporterOutput = grunt.template.process(reporterOutput);
        var destDir = path.dirname(reporterOutput);
        if (!grunt.file.exists(destDir)) {
          grunt.file.mkdir(destDir);
        }
        grunt.file.write(reporterOutput, output);
        grunt.log.ok('Report "' + reporterOutput + '" created.');
      }

      done(failed);
    });
  });
github frederickf / presentable / node_modules / grunt-contrib-jshint / tasks / jshint.js View on Github external
return memo + (result.error ? 1 : 0);
          }, 0);

          var numFiles = data.length;
          grunt.log.error(numErrors + ' ' + grunt.util.pluralize(numErrors, 'error/errors') + ' in ' +
                          numFiles + ' ' + grunt.util.pluralize(numFiles, 'file/files'));
        }
      } else {
        if (jshint.usingGruntReporter === true && data.length > 0) {
          grunt.log.ok(data.length + ' ' + grunt.util.pluralize(data.length, 'file/files') + ' lint free.');
        }
      }

      // Write the output of the reporter if wanted
      if (reporterOutput) {
        hooker.unhook(process.stdout, 'write');
        reporterOutput = grunt.template.process(reporterOutput);
        var destDir = path.dirname(reporterOutput);
        if (!grunt.file.exists(destDir)) {
          grunt.file.mkdir(destDir);
        }
        grunt.file.write(reporterOutput, output);
        grunt.log.ok('Report "' + reporterOutput + '" created.');
      }

      done(failed);
    });
  });
github evolution / wordpress / test / support / mock-generator.js View on Github external
DB_PASSWORD:  'generator_test'
    };

    prompts.forEach(function(prompt) {
      if (answers[prompt.name]) {
        return;
      }

      if (prompt.default instanceof Function) {
        answers[prompt.name] = prompt.default(answers);
      } else {
        answers[prompt.name] = prompt.default;
      }
    });

    hooker.unhook(this.app, 'prompt');

    done(answers);

    return hooker.preempt(answers);
  }.bind(this));
};
github leecrossley / grunt-timer / grunt-timer.js View on Github external
process.on("exit", function () {
            logCurrent();
            if (deferLogs) {
                logDeferred();
            }
            logTotal();
            hooker.unhook(grunt.log, "header");
        });
    };

hooker

Monkey-patch (hook) functions for debugging and stuff.

MIT
Latest version published 13 years ago

Package Health Score

65 / 100
Full package analysis