<commit_before>import {Then, When} from 'cucumber';
import fs from 'fs';
import http from 'http';


When(/^I wait$/, {timeout: 60 * 1000 * 5}, function () {
  return new Promise(() => {})
});


When(/^I make a form data request to "([^"]*)"$/, function (path, done) {
  var options = {
    hostname: 'localhost',
    port: this.options.port,
    path: path,
    headers: {
      'content-type': 'multipart/form-data; boundary="---TestBoundaryXYZ123"'
    },
    method: 'POST'
  };

  var postData = '---TestBoundaryXYZ123\r\nContent-Type: application/octet-stream\r\n\r\nHello World\r\n---TestBoundaryXYZ123--\r\n'

  var req = http.request(options, function(response) {
    var str = '';
    response.on('data', function (chunk) {str += chunk;});
    response.on('end', function() {
      this.result = str;
      done(str ? undefined : 'Empty Response');
    });
    response.on('error', function(){ done('Error during request.')});
  });
  req.on('error', function(){ done('Error during request.')});
  req.write(postData)
  req.end();
});


Then(/^the boundary is a mockingjays boundary$/, function (done) {
  var files = this.cacheFiles(this.options.cacheDir, '/formData');
  if (files.length != 1) {
    done('Expecting 1 file for form-data. '+ files.length +' found');
  }
  var generatedJSON = JSON.parse(fs.readFileSync(files[0], {encoding: 'utf-8'}));
  var hasUpdatedBoundary = generatedJSON.request.body.match('mockingjay');

  done(!hasUpdatedBoundary ? 'Missing Mockingjays Boundary in Form Data': null);
});

When(/^I make a POST request to "([^"]*)" with the JSON body:$/, function (path, postData, done) {<commit_msg>Return When Condition not Met<commit_after>import {Then, When} from 'cucumber';
import fs from 'fs';
import http from 'http';


When(/^I wait$/, {timeout: 60 * 1000 * 5}, function () {
  return new Promise(() => {})
});


When(/^I make a form data request to "([^"]*)"$/, function (path, done) {
  var options = {
    hostname: 'localhost',
    port: this.options.port,
    path: path,
    headers: {
      'content-type': 'multipart/form-data; boundary="---TestBoundaryXYZ123"'
    },
    method: 'POST'
  };

  var postData = '---TestBoundaryXYZ123\r\nContent-Type: application/octet-stream\r\n\r\nHello World\r\n---TestBoundaryXYZ123--\r\n'

  var req = http.request(options, function(response) {
    var str = '';
    response.on('data', function (chunk) {str += chunk;});
    response.on('end', function() {
      this.result = str;
      done(str ? undefined : 'Empty Response');
    });
    response.on('error', function(){ done('Error during request.')});
  });
  req.on('error', function(){ done('Error during request.')});
  req.write(postData)
  req.end();
});


Then(/^the boundary is a mockingjays boundary$/, function (done) {
  var files = this.cacheFiles(this.options.cacheDir, '/formData');
  if (files.length != 1) {
    done('Expecting 1 file for form-data. '+ files.length +' found');
    return;
  }
  var generatedJSON = JSON.parse(fs.readFileSync(files[0], {encoding: 'utf-8'}));
  var hasUpdatedBoundary = generatedJSON.request.body.match('mockingjay');

  done(!hasUpdatedBoundary ? 'Missing Mockingjays Boundary in Form Data': null);
});

When(/^I make a POST request to "([^"]*)" with the JSON body:$/, function (path, postData, done) {
{'fraction_non_alphanumeric': 0.187689508793208, 'fraction_numerical': 0.01212856276531231, 'mean_word_length': 3.7673410404624277, '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': '7381663', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1078, 'n_words': 275}