<commit_before>import {
  instrument,
  subscribe,
  unsubscribe,
  reset
} from "ember-metal/instrumentation";

QUnit.module("Ember Instrumentation", {
  setup: function() {

  },
  teardown: function() {
    reset();
  }
});

test("execute block even if no listeners", function() {
  var result = instrument("render", {}, function() {
    return "hello";
  });
  equal(result, "hello", 'called block');
});

test("subscribing to a simple path receives the listener", function() {
  expect(12);

  var sentPayload = {};
  var count = 0;

  subscribe("render", {
    before: function(name, timestamp, payload) {
      if (count === 0) {
        strictEqual(name, "render");
      } else {
        strictEqual(name, "render.handlebars");
      }

      ok(typeof timestamp === 'number');
      strictEqual(payload, sentPayload);
    },

    after: function(name, timestamp, payload) {
      if (count === 0) {
        strictEqual(name, "render");
      } else {
        strictEqual(name, "render.handlebars");
      }

      ok(typeof timestamp === 'number');
      strictEqual(payload, sentPayload);

      count++;
    }
  });

  instrument("render", sentPayload, function() {

  });

  instrument("render.handlebars", sentPayload, function() {

  });
});

test("returning a value from the before callback passes it to the after callback", function() {
  expect(2);

  var passthru1 = {};
  var passthru2 = {};

  subscribe("render", {
    before: function(name, timestamp, payload) {
      return passthru1;
    },
    after: function(name, timestamp, payload, beforeValue) {
      strictEqual(beforeValue, passthru1);
    }
  });

  subscribe("render", {
    before: function(name, timestamp, payload) {
      return passthru2;
    },
    after: function(name, timestamp, payload, beforeValue) {
      strictEqual(beforeValue, passthru2);
    }
  });

  instrument("render", null, function() {});
});

test("raising an exception in the instrumentation attaches it to the payload", function() {
  expect(2);

  var error = new Error("Instrumentation");

  subscribe("render", {
    before: function() {},
    after: function(name, timestamp, payload) {
      strictEqual(payload.exception, error);
    }
  });

  subscribe("render", {
    before: function() {},<commit_msg>[BUGFIX beta] Failing tests for instrument without payload<commit_after>import {
  instrument,
  subscribe,
  unsubscribe,
  reset
} from "ember-metal/instrumentation";

QUnit.module("Ember Instrumentation", {
  setup: function() {

  },
  teardown: function() {
    reset();
  }
});

test("execute block even if no listeners", function() {
  var result = instrument("render", {}, function() {
    return "hello";
  });
  equal(result, "hello", 'called block');
});

test("subscribing to a simple path receives the listener", function() {
  expect(12);

  var sentPayload = {};
  var count = 0;

  subscribe("render", {
    before: function(name, timestamp, payload) {
      if (count === 0) {
        strictEqual(name, "render");
      } else {
        strictEqual(name, "render.handlebars");
      }

      ok(typeof timestamp === 'number');
      strictEqual(payload, sentPayload);
    },

    after: function(name, timestamp, payload) {
      if (count === 0) {
        strictEqual(name, "render");
      } else {
        strictEqual(name, "render.handlebars");
      }

      ok(typeof timestamp === 'number');
      strictEqual(payload, sentPayload);

      count++;
    }
  });

  instrument("render", sentPayload, function() {

  });

  instrument("render.handlebars", sentPayload, function() {

  });
});

test("returning a value from the before callback passes it to the after callback", function() {
  expect(2);

  var passthru1 = {};
  var passthru2 = {};

  subscribe("render", {
    before: function(name, timestamp, payload) {
      return passthru1;
    },
    after: function(name, timestamp, payload, beforeValue) {
      strictEqual(beforeValue, passthru1);
    }
  });

  subscribe("render", {
    before: function(name, timestamp, payload) {
      return passthru2;
    },
    after: function(name, timestamp, payload, beforeValue) {
      strictEqual(beforeValue, passthru2);
    }
  });

  instrument("render", null, function() {});
});

test("instrument with 2 args (name, callback) no payload", function() {
  expect(1);

  subscribe("render", {
    before: function(name, timestamp, payload) {
      deepEqual(payload, {});
    },
    after: function() {}
  });

  instrument("render", function() {});
});

test("instrument with 3 args (name, callback, binding) no payload", function() {
  expect(2);

  var binding = {};
  subscribe("render", {
    before: function(name, timestamp, payload) {
      deepEqual(payload, {});
    },
    after: function() {}
  });

  instrument("render", function() {
    deepEqual(this, binding);
  }, binding);
});


test("instrument with 3 args (name, payload, callback) with payload", function() {
  expect(1);

  var expectedPayload = { hi: 1};
  subscribe("render", {
    before: function(name, timestamp, payload) {
      deepEqual(payload, expectedPayload);
    },
    after: function() {}
  });

  instrument("render", expectedPayload, function() {});
});

test("instrument with 4 args (name, payload, callback, binding) with payload", function() {
  expect(2);

  var expectedPayload = { hi: 1 };
  var binding = {};
  subscribe("render", {
    before: function(name, timestamp, payload) {
      deepEqual(payload, expectedPayload);
    },
    after: function() {}
  });

  instrument("render", expectedPayload, function() {
    deepEqual(this, binding);
  }, binding);
});


test("raising an exception in the instrumentation attaches it to the payload", function() {
  expect(2);

  var error = new Error("Instrumentation");

  subscribe("render", {
    before: function() {},
    after: function(name, timestamp, payload) {
      strictEqual(payload.exception, error);
    }
  });

  subscribe("render", {
    before: function() {},
{'fraction_non_alphanumeric': 0.15824690531950486, 'fraction_numerical': 0.006022080963532954, 'mean_word_length': 3.3995584988962473, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '6534791', 'n_tokens_mistral': 1816, 'n_tokens_neox': 1745, 'n_words': 447}