<commit_before>
Tinytest.add(
  'Client Side - Error Manager - Utils - stackFramesFilter()',
  function (test) {
    test.equal('function', typeof stackFramesFilter);
    test.equal(false, stackFramesFilter('/packages/zones/assets/zone.js'));
    test.equal(true, stackFramesFilter('/packages/foo/bar.js'));
  }
);

Tinytest.add(
  'Client Side - Error Manager - Utils - getCurrentOrigin()',
  function (test) {
    test.equal('function', typeof getCurrentOrigin);
    // Simple regex to catch origin part of the url
    // (may not work for all cases but sufficient for tests)
    var regex = /^https?:\/\/[a-zA-Z0-9\.]+:?[0-9]*$/;
    var origin = getCurrentOrigin();
    test.equal('string', typeof origin);
    test.equal(true, !!origin.match(regex));
  }
);

Tinytest.add(
  'Client Side - Error Manager - Utils - formatTraceLine()',
  function (test) {
    test.equal('function', typeof formatTraceLine);
    var lines = [
      '{anonymous}()@'+getCurrentOrigin()+'/foo/bar.js:12:34',
      'funName@'+getCurrentOrigin()+'/foo/bar.js:12:34'
    ];
    var expected = [
      '    at foo/bar.js:12:34',
      '    at funName (foo/bar.js:12:34)',
    ];
    for(var i=lines.length; i-->0;) {
      test.equal(expected[i], formatTraceLine(lines[i]));
    }
  }
);

Tinytest.add(
  'Client Side - Error Manager - Utils - getNormalizedStacktrace()',
  function (test) {
    hijackPrintStackTrace(mock_printStackTrace);
    test.equal('function', typeof getNormalizedStacktrace);
    var expected = [
      '    at foo/bar.js:12:34',
      '    at funName (foo/bar.js:12:34)',
    ].join('\n');
    test.equal(expected, getNormalizedStacktrace());
    restorePrintStackTrace();
  }
);

Tinytest.add(
  'Client Side - Error Manager - Utils - getErrorStack()',
  function (test) {
    test.equal('function', typeof getErrorStack);
  }
);

Tinytest.add(
  'Client Side - Error Manager - Utils - getErrorStack() errored stack',
  function (test) {
    hijackPrintStackTrace(mock_printStackTrace);
    var zone = {
      erroredStack: {_e: new Error()}
    };
    var trace = getErrorStack(zone);
    test.equal(1, trace.length);
    test.equal('number', typeof trace[0].at);
    test.equal('string', typeof trace[0].stack);
    restorePrintStackTrace();
  }
);

Tinytest.add(
  'Client Side - Error Manager - Utils - getErrorStack() without events',
  function (test) {
    hijackPrintStackTrace(mock_printStackTrace);
    var stack = '    at foo/bar.js:12:34\n    at funName (foo/bar.js:12:34)';

    var zone = {
      id: 'foo',
      createdAt: 100,
      runAt: 200,
      owner: '_owner',
      currentStack: {_e: new Error()},
      erroredStack: {_e: new Error()},
      // eventMap: {}
    };

    var expected = {
      createdAt: 100,
      runAt: 200,
      stack: stack,
      owner: '_owner',
      ownerArgs: [],
      info: [],
      events: undefined,
      zoneId: 'foo'
    };

    var trace = getErrorStack(zone);
    test.equal(2, trace.length);
    test.equal('number', typeof trace[0].at);
    test.equal(stack, trace[0].stack);
    test.equal(expected, trace[1]);
    restorePrintStackTrace();
  }
);

Tinytest.add(
  'Client Side - Error Manager - Utils - getErrorStack() with stack',
  function (test) {
    hijackPrintStackTrace(mock_printStackTrace);
    var stack = '    at foo/bar.js:12:34\n    at funName (foo/bar.js:12:34)';

    var eventMap = {foo: [
      {type: 'owner-args', args: ['foo', 'bar'], at: 300},
      {type: '_type', args: ['bar', 'baz']},
    ]};

    var zone = {
      id: 'foo',
      createdAt: 100,
      runAt: 200,
      owner: '_owner',
      currentStack: {_e: new Error()},
      erroredStack: {_e: new Error()},
      eventMap: eventMap
    };

    var expected = {
      createdAt: 100,
      runAt: 300,
      stack: stack,
      owner: '_owner',
      ownerArgs: ['foo', 'bar'],
      info: [],
      events: [{type: '_type', args: ['bar', 'baz']}],
      zoneId: 'foo'
    };

    var trace = getErrorStack(zone);
    test.equal(2, trace.length);
    test.equal('number', typeof trace[0].at);
    test.equal(stack, trace[0].stack);
    test.equal(expected, trace[1]);
    restorePrintStackTrace();
  }
);

Tinytest.add(
  'Client Side - Error Manager - Utils - getErrorStack() with parent zone',
  function (test) {
    hijackPrintStackTrace(mock_printStackTrace);
    var stack = '    at foo/bar.js:12:34\n    at funName (foo/bar.js:12:34)';

    var eventMap = {
      foo: [
        {type: 'owner-args', args: ['foo', 'bar'], at: 300},
        {type: '_type', args: ['bar', 'baz']},
      ],
      bar: [
        {type: 'owner-args', args: ['foo2', 'bar2'], at: 310},
        {type: '_type2', args: ['bar2', 'baz2']},
      ]
    };

    var zone2 = {
      id: 'bar',
      createdAt: 110,
      runAt: 210,
      owner: '_owner2',
      currentStack: {_e: new Error()},
      erroredStack: {_e: new Error()},
    };

    var zone = {
      id: 'foo',
      createdAt: 100,
      runAt: 200,
      owner: '_owner',
      parent: zone2,
      currentStack: {_e: new Error()},
      erroredStack: {_e: new Error()},
      eventMap: eventMap
    };<commit_msg>fixed tests with a recent change<commit_after>
Tinytest.add(
  'Client Side - Error Manager - Utils - stackFramesFilter()',
  function (test) {
    test.equal('function', typeof stackFramesFilter);
    test.equal(false, stackFramesFilter('/packages/zones/assets/zone.js'));
    test.equal(true, stackFramesFilter('/packages/foo/bar.js'));
  }
);

Tinytest.add(
  'Client Side - Error Manager - Utils - getCurrentOrigin()',
  function (test) {
    test.equal('function', typeof getCurrentOrigin);
    // Simple regex to catch origin part of the url
    // (may not work for all cases but sufficient for tests)
    var regex = /^https?:\/\/[a-zA-Z0-9\.]+:?[0-9]*$/;
    var origin = getCurrentOrigin();
    test.equal('string', typeof origin);
    test.equal(true, !!origin.match(regex));
  }
);

Tinytest.add(
  'Client Side - Error Manager - Utils - formatTraceLine()',
  function (test) {
    test.equal('function', typeof formatTraceLine);
    var lines = [
      '{anonymous}()@'+getCurrentOrigin()+'/foo/bar.js:12:34',
      'funName@'+getCurrentOrigin()+'/foo/bar.js:12:34'
    ];
    var expected = [
      '    at foo/bar.js:12:34',
      '    at funName (foo/bar.js:12:34)',
    ];
    for(var i=lines.length; i-->0;) {
      test.equal(expected[i], formatTraceLine(lines[i]));
    }
  }
);

Tinytest.add(
  'Client Side - Error Manager - Utils - getNormalizedStacktrace()',
  function (test) {
    hijackPrintStackTrace(mock_printStackTrace);
    test.equal('function', typeof getNormalizedStacktrace);
    var expected = [
      '    at foo/bar.js:12:34',
      '    at funName (foo/bar.js:12:34)',
    ].join('\n');
    test.equal(expected, getNormalizedStacktrace());
    restorePrintStackTrace();
  }
);

Tinytest.add(
  'Client Side - Error Manager - Utils - getErrorStack()',
  function (test) {
    test.equal('function', typeof getErrorStack);
  }
);

Tinytest.add(
  'Client Side - Error Manager - Utils - getErrorStack() errored stack',
  function (test) {
    hijackPrintStackTrace(mock_printStackTrace);
    var zone = {
      erroredStack: {_e: new Error()}
    };
    var trace = getErrorStack(zone);
    test.equal(1, trace.length);
    test.equal('number', typeof trace[0].at);
    test.equal('string', typeof trace[0].stack);
    restorePrintStackTrace();
  }
);

Tinytest.add(
  'Client Side - Error Manager - Utils - getErrorStack() without events',
  function (test) {
    hijackPrintStackTrace(mock_printStackTrace);
    var stack = '    at foo/bar.js:12:34\n    at funName (foo/bar.js:12:34)';

    var zone = {
      id: 'foo',
      createdAt: 100,
      runAt: 200,
      owner: '_owner',
      currentStack: {_e: new Error()},
      erroredStack: {_e: new Error()},
      // eventMap: {}
      depth: 20
    };

    var expected = {
      createdAt: 100,
      runAt: 200,
      stack: stack,
      owner: '_owner',
      ownerArgs: [],
      info: [],
      events: undefined,
      zoneId: 'foo'
    };

    var trace = getErrorStack(zone);
    test.equal(2, trace.length);
    test.equal('number', typeof trace[0].at);
    test.equal(stack, trace[0].stack);
    test.equal(expected, trace[1]);
    restorePrintStackTrace();
  }
);

Tinytest.add(
  'Client Side - Error Manager - Utils - getErrorStack() with stack',
  function (test) {
    hijackPrintStackTrace(mock_printStackTrace);
    var stack = '    at foo/bar.js:12:34\n    at funName (foo/bar.js:12:34)';

    var eventMap = {foo: [
      {type: 'owner-args', args: ['foo', 'bar'], at: 300},
      {type: '_type', args: ['bar', 'baz']},
    ]};

    var zone = {
      id: 'foo',
      createdAt: 100,
      runAt: 200,
      owner: '_owner',
      currentStack: {_e: new Error()},
      erroredStack: {_e: new Error()},
      eventMap: eventMap,
      depth: 20
    };

    var expected = {
      createdAt: 100,
      runAt: 300,
      stack: stack,
      owner: '_owner',
      ownerArgs: ['foo', 'bar'],
      info: [],
      events: [{type: '_type', args: ['bar', 'baz']}],
      zoneId: 'foo'
    };

    var trace = getErrorStack(zone);
    test.equal(2, trace.length);
    test.equal('number', typeof trace[0].at);
    test.equal(stack, trace[0].stack);
    test.equal(expected, trace[1]);
    restorePrintStackTrace();
  }
);

Tinytest.add(
  'Client Side - Error Manager - Utils - getErrorStack() with parent zone',
  function (test) {
    hijackPrintStackTrace(mock_printStackTrace);
    var stack = '    at foo/bar.js:12:34\n    at funName (foo/bar.js:12:34)';

    var eventMap = {
      foo: [
        {type: 'owner-args', args: ['foo', 'bar'], at: 300},
        {type: '_type', args: ['bar', 'baz']},
      ],
      bar: [
        {type: 'owner-args', args: ['foo2', 'bar2'], at: 310},
        {type: '_type2', args: ['bar2', 'baz2']},
      ]
    };

    var zone2 = {
      id: 'bar',
      createdAt: 110,
      runAt: 210,
      owner: '_owner2',
      currentStack: {_e: new Error()},
      erroredStack: {_e: new Error()},
      depth: 20
    };

    var zone = {
      id: 'foo',
      createdAt: 100,
      runAt: 200,
      owner: '_owner',
      parent: zone2,
      currentStack: {_e: new Error()},
      erroredStack: {_e: new Error()},
      eventMap: eventMap,
      depth: 20
    };
{'fraction_non_alphanumeric': 0.16978027296486303, 'fraction_numerical': 0.0234246442745136, 'mean_word_length': 2.67425320056899, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1165716', 'n_tokens_mistral': 3672, 'n_tokens_neox': 3509, 'n_words': 807}