<commit_before>'use strict';

var nock    = require('../.')
  , test    = require('tap').test
  , http    = require('http')
  , https   = require('https')
  , _       = require('lodash')
  , mikealRequest = require('request')
  , superagent = require('superagent');

var globalCount;

test("setup", function(t) {
  globalCount = Object.keys(global).length;
  t.end();
});

test('recording turns off nock interception (backward compatibility behavior)', function(t) {

  //  We ensure that there are no overrides.
  nock.restore();
  t.false(nock.isActive());
  //  We active the nock overriding - as it's done by merely loading nock.
  nock.activate();
  t.true(nock.isActive());
  //  We start recording.
  nock.recorder.rec();
  //  Nothing happens (nothing has been thrown) - which was the original behavior -
  //  and mocking has been deactivated.
  t.false(nock.isActive());

  t.end();

});

// Do not copy tests that rely on the process.env.AIRPLANE, we are deprecating that via #1231
test('records', function(t) {
  t.plan(5)

  nock.restore();
  nock.recorder.clear();
  t.equal(nock.recorder.play().length, 0);

  const server = http.createServer((request, response) => {
    t.pass('server received a request')
    response.writeHead(200)
    response.end()
  });

  t.once('end', () => {
    server.close()
  });

  nock.recorder.rec(true);
  server.listen(() => {
    const options = {
      uri: `http://localhost:${server.address().port}`,
      method: 'post'
    }

    mikealRequest(options, function(err, resp, body) {
      nock.restore()
      var ret = nock.recorder.play();
      t.equal(ret.length, 1);
      t.type(ret[0], 'string');
      t.equal(ret[0].indexOf(`\nnock('${options.uri}', {"encodedQueryParams":true})\n  .post('/')`), 0);
      t.end()
    })
  })
})

// Do not copy tests that rely on the process.env.AIRPLANE, we are deprecating that via #1231
test('records objects', function(t) {
  nock.restore();
  nock.recorder.clear();
  t.equal(nock.recorder.play().length, 0);

  const server = http.createServer((request, response) => {
    t.pass('server received a request')<commit_msg>chore: remove obsolete comment<commit_after>'use strict';

var nock    = require('../.')
  , test    = require('tap').test
  , http    = require('http')
  , https   = require('https')
  , _       = require('lodash')
  , mikealRequest = require('request')
  , superagent = require('superagent');

var globalCount;

test("setup", function(t) {
  globalCount = Object.keys(global).length;
  t.end();
});

test('recording turns off nock interception (backward compatibility behavior)', function(t) {

  //  We ensure that there are no overrides.
  nock.restore();
  t.false(nock.isActive());
  //  We active the nock overriding - as it's done by merely loading nock.
  nock.activate();
  t.true(nock.isActive());
  //  We start recording.
  nock.recorder.rec();
  //  Nothing happens (nothing has been thrown) - which was the original behavior -
  //  and mocking has been deactivated.
  t.false(nock.isActive());

  t.end();

});

// Do not copy tests that rely on the process.env.AIRPLANE, we are deprecating that via #1231
test('records', function(t) {
  t.plan(5)

  nock.restore();
  nock.recorder.clear();
  t.equal(nock.recorder.play().length, 0);

  const server = http.createServer((request, response) => {
    t.pass('server received a request')
    response.writeHead(200)
    response.end()
  });

  t.once('end', () => {
    server.close()
  });

  nock.recorder.rec(true);
  server.listen(() => {
    const options = {
      uri: `http://localhost:${server.address().port}`,
      method: 'post'
    }

    mikealRequest(options, function(err, resp, body) {
      nock.restore()
      var ret = nock.recorder.play();
      t.equal(ret.length, 1);
      t.type(ret[0], 'string');
      t.equal(ret[0].indexOf(`\nnock('${options.uri}', {"encodedQueryParams":true})\n  .post('/')`), 0);
      t.end()
    })
  })
})

test('records objects', function(t) {
  nock.restore();
  nock.recorder.clear();
  t.equal(nock.recorder.play().length, 0);

  const server = http.createServer((request, response) => {
    t.pass('server received a request')
{'fraction_non_alphanumeric': 0.17661155044332613, 'fraction_numerical': 0.007668344116942248, 'mean_word_length': 3.2678936605316973, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 11, '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': '775375', 'n_tokens_mistral': 1449, 'n_tokens_neox': 1393, 'n_words': 319}