<commit_before>"use strict";

var test = require("tap").test;
var semver = require("semver");
var VError = require("verror");
var nock = require("nock");

var Raygun = require("../lib/raygun.js");

nock(/.*/)
  .post(/.*/, function() {
    return true;
  })
  .reply(202, {})
  .persist();
var API_KEY = "apikey";

test("send basic", {}, function(t) {
  t.plan(1);

  if (semver.satisfies(process.version, "=0.10")) {
    t.pass("Ignored on node 0.10");
    t.end();
    return;
  }

  var client = new Raygun.Client().init({
    apiKey: API_KEY
  });
  client.send(new Error(), {}, function(response) {
    t.equals(response.statusCode, 202);
    t.end();
  });
});

test("send complex", {}, function(t) {
  t.plan(1);

  if (semver.satisfies(process.version, "=0.10")) {
    t.pass("Ignored on node 0.10");
    t.end();
    return;
  }

  var client = new Raygun.Client()
    .init({ apiKey: API_KEY })
    .setUser("<EMAIL>")
    .setVersion("1.0.0.0");

  client.send(new Error(), {}, function(response) {
    t.equals(response.statusCode, 202);
    t.end();
  });
});

test("send with inner error", {}, function(t) {
  t.plan(1);

  if (semver.satisfies(process.version, "=0.10")) {
    t.pass("Ignored on node 0.10");
    t.end();
    return;
  }

  var error = new Error("Outer");
  var innerError = new Error("Inner");

  error.cause = function() {
    return innerError;
  };

  var client = new Raygun.Client().init({
    apiKey: API_KEY
  });
  client.send(error, {}, function(response) {
    t.equals(response.statusCode, 202);
    t.end();
  });
});

test("send with verror", {}, function(t) {
  t.plan(1);

  if (semver.satisfies(process.version, "=0.10")) {
    t.pass("Ignored on node 0.10");
    t.end();
    return;
  }

  var error = new VError(
    new VError(new VError("Deep Error"), "Inner Error"),
    "Outer Error"
  );

  var client = new Raygun.Client().init({
    apiKey: API_KEY
  });
  client.send(error, {}, function(response) {
    t.equals(response.statusCode, 202);
    t.end();
  });
});

test("send with OnBeforeSend", {}, function(t) {
  t.plan(1);

  if (semver.satisfies(process.version, "=0.10")) {
    t.pass("Ignored on node 0.10");
    t.end();
    return;
  }

  var client = new Raygun.Client().init({
    apiKey: API_KEY
  });

  var onBeforeSendCalled = false;
  client.onBeforeSend(function(payload) {
    onBeforeSendCalled = true;
    return payload;
  });

  client.send(new Error(), {}, function() {
    t.equals(onBeforeSendCalled, true);
    t.end();
  });
});

test("send with expressHandler custom data", function(t) {
  t.plan(1);
  var client = new Raygun.Client().init({
    apiKey: API_KEY
  });

  client.expressCustomData = function() {
    return { test: "data" };
  };
  client._send = client.send;
  client.send = function(err, data) {
    client.send = client._send;
    t.equals(data.test, "data");
    t.end();
  };
  client.expressHandler(new Error(), {}, {}, function() {});
});

test("check that tags get passed through", {}, function(t) {
  var tag = ["Test"];
  var client = new Raygun.Client().init({ apiKey: "TEST" });

  client.setTags(tag);

  client.onBeforeSend(function(payload) {
    t.same(payload.details.tags, tag);
    t.end();
  });

  client.send(new Error(), {}, function() {
    t.end();
  });
});

test("check that tags get merged", {}, function(t) {
  var client = new Raygun.Client().init({ apiKey: "TEST" });
  client.setTags(["Tag1"]);

  client.onBeforeSend(function(payload) {
    t.same(payload.details.tags, ["Tag1", "Tag2"]);
    t.end();
  });

  client.send(
    new Error(),
    {},
    function() {
      t.end();
    },
    null,
    ["Tag2"]
  );
});<commit_msg>Fix transport errors in tests<commit_after>"use strict";

var test = require("tap").test;
var semver = require("semver");
var VError = require("verror");
var nock = require("nock");

var Raygun = require("../lib/raygun.js");

nock(/.*/)
  .post(/.*/, function() {
    return true;
  })
  .reply(202, {})
  .persist();
var API_KEY = "apikey";

test("send basic", {}, function(t) {
  t.plan(1);

  if (semver.satisfies(process.version, "=0.10")) {
    t.pass("Ignored on node 0.10");
    t.end();
    return;
  }

  var client = new Raygun.Client().init({
    apiKey: API_KEY
  });
  client.send(new Error(), {}, function(response) {
    t.equals(response.statusCode, 202);
    t.end();
  });
});

test("send complex", {}, function(t) {
  t.plan(1);

  if (semver.satisfies(process.version, "=0.10")) {
    t.pass("Ignored on node 0.10");
    t.end();
    return;
  }

  var client = new Raygun.Client()
    .init({ apiKey: API_KEY })
    .setUser("<EMAIL>")
    .setVersion("1.0.0.0");

  client.send(new Error(), {}, function(response) {
    t.equals(response.statusCode, 202);
    t.end();
  });
});

test("send with inner error", {}, function(t) {
  t.plan(1);

  if (semver.satisfies(process.version, "=0.10")) {
    t.pass("Ignored on node 0.10");
    t.end();
    return;
  }

  var error = new Error("Outer");
  var innerError = new Error("Inner");

  error.cause = function() {
    return innerError;
  };

  var client = new Raygun.Client().init({
    apiKey: API_KEY
  });
  client.send(error, {}, function(response) {
    t.equals(response.statusCode, 202);
    t.end();
  });
});

test("send with verror", {}, function(t) {
  t.plan(1);

  if (semver.satisfies(process.version, "=0.10")) {
    t.pass("Ignored on node 0.10");
    t.end();
    return;
  }

  var error = new VError(
    new VError(new VError("Deep Error"), "Inner Error"),
    "Outer Error"
  );

  var client = new Raygun.Client().init({
    apiKey: API_KEY
  });
  client.send(error, {}, function(response) {
    t.equals(response.statusCode, 202);
    t.end();
  });
});

test("send with OnBeforeSend", {}, function(t) {
  t.plan(1);

  if (semver.satisfies(process.version, "=0.10")) {
    t.pass("Ignored on node 0.10");
    t.end();
    return;
  }

  var client = new Raygun.Client().init({
    apiKey: API_KEY
  });

  var onBeforeSendCalled = false;
  client.onBeforeSend(function(payload) {
    onBeforeSendCalled = true;
    return payload;
  });

  client.send(new Error(), {}, function() {
    t.equals(onBeforeSendCalled, true);
    t.end();
  });
});

test("send with expressHandler custom data", function(t) {
  t.plan(1);
  var client = new Raygun.Client().init({
    apiKey: API_KEY
  });

  client.expressCustomData = function() {
    return { test: "data" };
  };
  client._send = client.send;
  client.send = function(err, data) {
    client.send = client._send;
    t.equals(data.test, "data");
    t.end();
  };
  client.expressHandler(new Error(), {}, {}, function() {});
});

test("check that tags get passed through", {}, function(t) {
  var tag = ["Test"];
  var client = new Raygun.Client().init({ apiKey: "TEST" });

  client.setTags(tag);

  client.onBeforeSend(function(payload) {
    t.same(payload.details.tags, tag);
    return payload;
  });

  client.send(new Error(), {}, function() {
    t.end();
  });
});

test("check that tags get merged", {}, function(t) {
  var client = new Raygun.Client().init({ apiKey: "TEST" });
  client.setTags(["Tag1"]);

  client.onBeforeSend(function(payload) {
    t.same(payload.details.tags, ["Tag1", "Tag2"]);
    return payload;
  });

  client.send(
    new Error(),
    {},
    function() {
      t.end();
    },
    null,
    ["Tag2"]
  );
});
{'fraction_non_alphanumeric': 0.20532319391634982, 'fraction_numerical': 0.016023900054318304, 'mean_word_length': 3.1260504201680672, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2850495', 'n_tokens_mistral': 2745, 'n_tokens_neox': 2644, 'n_words': 546}