<commit_before>'use strict';


(() => {
  // include dependencies
  const unit = require('unit.js');
  const express = require('express');
  const virtual = require('../index');
  const app = express();

  app.use(virtual);

  app.get('/test', (req, res, next) => {
    res
      .status(200)
      .set('Content-Type', req.headers.accept)
      .set('X-Request-URL', req.url)
      .send();
  }); // end app.get

  // describe #virtual
  describe('#virtual', () => {
    it('should be a function', () => {
      unit
        .function(virtual);
    }); // end it

    it('should do nothing when url has no ext', (done) => {
      unit
        .httpAgent(app)
        .get('/test')
        .set('Accept', 'text/html')
        .expect(200)
        .expect('Content-Type', /^text\/html/i)
        .expect('X-Request-URL', '/test')
        .end(done);
    }); // end it

    it('should replace js ext in url with appropriate accept header', (done) => {
      unit
        .httpAgent(app)
        .get('/test.js')
        .expect(200)
        .expect('Content-Type', /^application\/javascript/i)
        .expect('X-Request-URL', '/test')
        .end(done);
    }); // end it

    it('should replace json ext in url with appropriate accept header', (done) => {
      unit
        .httpAgent(app)
        .get('/test.json')
        .expect(200)
        .expect('Content-Type', /^application\/json/i)
        .expect('X-Request-URL', '/test')
        .end(done);
    }); // end it

    it('should replace xml ext in url with appropriate accept header', (done) => {
      unit
        .httpAgent(app)
        .get('/test.xml')
        .expect(200)
        .expect('Content-Type', /^application\/xml/i)
        .expect('X-Request-URL', '/test')
        .end(done);
    }); // end it

    it('should replace html ext in url with appropriate accept header', (done) => {
      unit
        .httpAgent(app)
        .get('/test.html')
        .expect(200)
        .expect('Content-Type', /^text\/html/i)
        .expect('X-Request-URL', '/test')
        .end(done);
    }); // end it

    it('should replace txt ext in url with appropriate accept header', (done) => {
      unit
        .httpAgent(app)
        .get('/test.txt')
        .expect(200)
        .expect('Content-Type', /^text\/plain/i)
        .expect('X-Request-URL', '/test')
        .end(done);
    }); // end it

    it('should replace jpg ext in url with appropriate accept header', (done) => {
      unit
        .httpAgent(app)
        .get('/test.jpg')
        .expect(200)
        .expect('Content-Type', /^image\/jpeg/i)
        .expect('X-Request-URL', '/test')
        .end(done);
    }); // end it

    it('should replace ext in url and retain query parameters', (done) => {
      unit
        .httpAgent(app)
        .get('/test.json?q=hi&test=1')
        .expect(200)
        .expect('Content-Type', /^application\/json/i)
        .expect('X-Request-URL', '/test?q=hi&test=1')
        .end(done);
    }); // end it
  }); // end describe #virtual
})(); // end IIFE<commit_msg>remove iife from test/index.js<commit_after>'use strict';

// include dependencies
const unit = require('unit.js');
const express = require('express');
const virtual = require('../index');
const app = express();

app.use(virtual);

app.get('/test', (req, res, next) => {
  res
    .status(200)
    .set('Content-Type', req.headers.accept)
    .set('X-Request-URL', req.url)
    .send();
}); // end app.get

// describe #virtual
describe('#virtual', () => {
  it('should be a function', () => {
    unit
      .function(virtual);
  }); // end it

  it('should do nothing when url has no ext', (done) => {
    unit
      .httpAgent(app)
      .get('/test')
      .set('Accept', 'text/html')
      .expect(200)
      .expect('Content-Type', /^text\/html/i)
      .expect('X-Request-URL', '/test')
      .end(done);
  }); // end it

  it('should replace js ext in url with appropriate accept header', (done) => {
    unit
      .httpAgent(app)
      .get('/test.js')
      .expect(200)
      .expect('Content-Type', /^application\/javascript/i)
      .expect('X-Request-URL', '/test')
      .end(done);
  }); // end it

  it('should replace json ext in url with appropriate accept header', (done) => {
    unit
      .httpAgent(app)
      .get('/test.json')
      .expect(200)
      .expect('Content-Type', /^application\/json/i)
      .expect('X-Request-URL', '/test')
      .end(done);
  }); // end it

  it('should replace xml ext in url with appropriate accept header', (done) => {
    unit
      .httpAgent(app)
      .get('/test.xml')
      .expect(200)
      .expect('Content-Type', /^application\/xml/i)
      .expect('X-Request-URL', '/test')
      .end(done);
  }); // end it

  it('should replace html ext in url with appropriate accept header', (done) => {
    unit
      .httpAgent(app)
      .get('/test.html')
      .expect(200)
      .expect('Content-Type', /^text\/html/i)
      .expect('X-Request-URL', '/test')
      .end(done);
  }); // end it

  it('should replace txt ext in url with appropriate accept header', (done) => {
    unit
      .httpAgent(app)
      .get('/test.txt')
      .expect(200)
      .expect('Content-Type', /^text\/plain/i)
      .expect('X-Request-URL', '/test')
      .end(done);
  }); // end it

  it('should replace jpg ext in url with appropriate accept header', (done) => {
    unit
      .httpAgent(app)
      .get('/test.jpg')
      .expect(200)
      .expect('Content-Type', /^image\/jpeg/i)
      .expect('X-Request-URL', '/test')
      .end(done);
  }); // end it

  it('should replace ext in url and retain query parameters', (done) => {
    unit
      .httpAgent(app)
      .get('/test.json?q=hi&test=1')
      .expect(200)
      .expect('Content-Type', /^application\/json/i)
      .expect('X-Request-URL', '/test?q=hi&test=1')
      .end(done);
  }); // end it
}); // end describe #virtual
{'fraction_non_alphanumeric': 0.19530851606323305, 'fraction_numerical': 0.009858915519292877, 'mean_word_length': 2.106652587117212, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '452153', 'n_tokens_mistral': 1941, 'n_tokens_neox': 1881, 'n_words': 442}