<commit_before>var child = require('child_process');
var http = require('http');
var test = require('tape');
var fs = require('fs');
var path = require('path');
var url = require('url');

var browsers = [
  'chrome',
  'chromium',
];

browsers.forEach(function (browser) {
  test('bin hot patch basic with file url in ' + browser, function (test) {
    test.plan(23);

    var args = [
      'bin/amok.js',
      '--hot',
      '--browser',
      browser,
      url.resolve('file://', path.join('/' + __dirname, '/fixture/hotpatch-basic/index.html'))
    ];

    test.comment(args.join(' '));

    var cli = child.spawn('node', args);
    cli.stderr.pipe(process.stderr);

    cli.on('close', function () {
      test.pass('close');
    });

    var values = [
      'ready',
      'step-0',
      'step-1',
      'step-2',
      'step-3',
      'step-4',
      'step-5',
      'step-6',
      'step-7',
      'step-8',
      'step-9',
      'step-0',
    ];

    var source = fs.readFileSync('test/fixture/hotpatch-basic/index.js', 'utf-8');
    cli.stdout.setEncoding('utf-8');
    cli.stdout.on('data', function (chunk) {
      chunk.split('\n').forEach(function (line) {
        if (line.length === 0) {
          return;
        }

        test.comment(line);
        test.equal(line, values.shift(), line);

        if (values[0] === undefined) {
          cli.kill('SIGTERM')
        } else if (line.match(/^step/)) {
          source = source.replace(line, values[0]);

          fs.writeFile('test/fixture/hotpatch-basic/index.js', source, 'utf-8', function (error) {
            test.error(error);
          });
        }
      });
    });
  });
});

browsers.forEach(function (browser) {
  test('bin hot patch basic with server in ' + browser, function (test) {
    test.plan(13);

    var args = [
      'bin/amok.js',
      '--hot',
      '--browser',
      browser,
      'test/fixture/hotpatch-basic/index.js'
    ];

    test.comment(args.join(' '));

    var cli = child.spawn('node', args);
    cli.stderr.pipe(process.stderr);

    cli.on('close', function () {
      test.pass('close');
    });

    var values = [
      'ready',
      'step-0',
      'step-1',
      'step-2',
      'step-3',
      'step-4',
      'step-5',
      'step-6',
      'step-7',
      'step-8',
      'step-9',
      'step-0',
    ];

    var source = fs.readFileSync('test/fixture/hotpatch-basic/index.js', 'utf-8');
    cli.stdout.setEncoding('utf-8');
    cli.stdout.on('data', function (chunk) {
      chunk.split('\n').forEach(function (line) {
        if (line.length === 0) {
          return;
        }

        test.equal(line, values.shift(), line);

        if (values[0] === undefined) {
          cli.kill('SIGTERM')
        } else if (line.match(/^step/)) {
          source = source.replace(line, values[0]);

          fs.writeFileSync('test/fixture/hotpatch-basic/index.js', source, 'utf-8');
        }
      });
    });
  });
});<commit_msg>Remove duplicate code in test/bin_hotpatch.js<commit_after>var child = require('child_process');
var http = require('http');
var test = require('tape');
var fs = require('fs');
var path = require('path');
var url = require('url');

var browsers = [
  'chrome',
  'chromium',
];

browsers.forEach(function (browser) {
  var entries = [
    'test/fixture/hotpatch-basic/index.js',
    url.resolve('file://', path.join('/' + __dirname, '/fixture/hotpatch-basic/index.html'))
  ];

  entries.forEach(function (entry) {
    var args = [
      'bin/amok.js',
      '--hot',
      '--browser',
      browser,
      entry
    ];

    test(args.join(' '), function (test) {
      test.plan(23);

      var cli = child.spawn('node', args);
      cli.stderr.pipe(process.stderr);

      cli.on('close', function () {
        test.pass('close');
      });

      var values = [
        'ready',
        'step-0',
        'step-1',
        'step-2',
        'step-3',
        'step-4',
        'step-5',
        'step-6',
        'step-7',
        'step-8',
        'step-9',
        'step-0',
      ];

      var source = fs.readFileSync('test/fixture/hotpatch-basic/index.js', 'utf-8');
      cli.stdout.setEncoding('utf-8');
      cli.stdout.on('data', function (chunk) {
        chunk.split('\n').forEach(function (line) {
          if (line.length === 0) {
            return;
          }

          test.comment(line);
          test.equal(line, values.shift(), line);

          if (values[0] === undefined) {
            cli.kill('SIGTERM')
          } else if (line.match(/^step/)) {
            source = source.replace(line, values[0]);

            fs.writeFile('test/fixture/hotpatch-basic/index.js', source, 'utf-8', function (error) {
              test.error(error);
            });
          }
        });
      });
    });
  });
});
{'fraction_non_alphanumeric': 0.19691280767626199, 'fraction_numerical': 0.011889862327909888, 'mean_word_length': 1.9894014962593516, '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': '6233946', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1634, 'n_words': 280}