<commit_before>'use strict';

import UserDefinition from '../UserDefinition';

describe('runtime', () => {
  test('user defined identity function', () => {
    const def = new UserDefinition(null, {
      inputs: [
        {tempo: 'step'},
      ],
      output: {tempo: 'step'},
    });

    def.addConnection(def.definitionInputs[0], def.definitionOutput);

    const outputs = [];
    const act = def.activate([{value: 123, changed: true}], (output) => {
      outputs.push(output);
    });

    expect(outputs).toEqual([123]);

    act.update([{value: 456, changed: true}]);

    expect(outputs).toEqual([123, 456]);
  });
});<commit_msg>Add another runtime test, try using mock functions<commit_after>'use strict';

import UserDefinition from '../UserDefinition';

describe('runtime', () => {
  test('user defined identity function', () => {
    const def = new UserDefinition(null, {
      inputs: [
        {tempo: 'step'},
      ],
      output: {tempo: 'step'},
    });

    def.addConnection(def.definitionInputs[0], def.definitionOutput);

    const outputCallback = jest.fn();
    const act = def.activate([{value: 123, changed: true}], outputCallback);

    expect(outputCallback.mock.calls).toEqual([[123]]);
    outputCallback.mockClear();

    act.update([{value: 456, changed: true}]);

    expect(outputCallback.mock.calls).toEqual([[456]]);
  });

  test('user defined identity function, adding connection after activation', () => {
    const def = new UserDefinition(null, {
      inputs: [
        {tempo: 'step'},
      ],
      output: {tempo: 'step'},
    });

    const outputCallback = jest.fn();
    const act = def.activate([{value: 123, changed: true}], outputCallback);

    // TODO: We might change expectation to be that outputCallback is called with undefined value
    expect(outputCallback).not.toBeCalled();
    outputCallback.mockClear();

    def.addConnection(def.definitionInputs[0], def.definitionOutput);

    expect(outputCallback.mock.calls).toEqual([[123]]);
    outputCallback.mockClear();

    act.update([{value: 456, changed: true}]);

    expect(outputCallback.mock.calls).toEqual([[456]]);
  });
});
{'fraction_non_alphanumeric': 0.17116279069767443, 'fraction_numerical': 0.01953488372093023, 'mean_word_length': 3.605995717344754, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '3739379', 'n_tokens_mistral': 659, 'n_tokens_neox': 620, 'n_words': 140}