<commit_before>var Circus = require('circus'),
    CircusRouter = require('../../lib'),
    ModuleNotFoundError = require('webpack/lib/ModuleNotFoundError'),
    webpack = require('webpack');

var expect = require('chai').expect,
    temp = require('temp'),
    fs = require('fs'),
    path = require('path');

describe('loader plugin', function() {
  var outputDir;

  beforeEach(function(done) {
    temp.mkdir('loader-plugin', function(err, dirPath) {
      if (err) {
        throw err;
      }

      outputDir = dirPath;
      done();
    });
  });
  afterEach(function() {
    temp.cleanupSync();
  });

  it('should create a chunk for each import', function(done) {
    var entry = path.resolve(__dirname + '/../fixtures/loader.js');

    var config = {
      entry: entry,
      output: {
        component: 'pack',
        path: outputDir
      },

      externals: {
        'circus': 'Circus'
      }
    };
    config = CircusRouter.config(config);
    config = Circus.config(config);

    webpack(config, function(err, status) {
      expect(err).to.not.exist;
      expect(status.compilation.errors).to.be.empty;
      expect(status.compilation.warnings.length).to.equal(3);
      expect(status.compilation.warnings[2]).to.match(/loader.js:\d+ - Circus.loader used to load module "`.\/router-no-routes.js" declaring no route/);

      // Verify the chunk division
      expect(status.compilation.chunks.length).to.equal(5);

      // Verify the loader boilerplate
      var output = fs.readFileSync(outputDir + '/bundle.js').toString();
      expect(output).to.match(/Circus.loader\(__webpack_require__, \{"modules":\{"2":\{"chunk":1\},"3":\{"chunk":2\}\},"routes":\{"\/foo":3,"\/bar":3\}\}\);/);

      // Verify the module map output
      var pack = JSON.parse(fs.readFileSync(outputDir + '/circus.json').toString());
      delete pack.circusVersion;   // To avoid erroring the tests
      expect(pack).to.eql({
        'bootstrap': 'bootstrap.js',
        'components': [],
        'chunks': [
          {'js': 'bundle.js', 'css': '0.bundle.css'},
          {'js': '1.bundle.js'},
          {'js': '2.bundle.js'},
          {'js': '3.bundle.js'}
        ],
        'modules': {
          '0': {
            'chunk': 0,
            'name': 'pack/test/fixtures/loader'
          },
          '2': {
            'chunk': 1,
            'name': 'pack/test/fixtures/router1'
          },
          '3': {
            'chunk': 2,
            'name': 'pack/test/fixtures/router-imported'
          },
          '4': {
            'chunk': 3,
            'name': 'pack/test/fixtures/router-no-routes'
          }
        },
        'routes': {
          '/foo': 3,
          '/bar': 3
        },
        'files': [
          'bundle.js',
          '0.bundle.css',
          'bundle.js.map',
          '1.bundle.js',
          '1.bundle.js.map',
          '2.bundle.js',
          '2.bundle.js.map',
          '3.bundle.js',
          '3.bundle.js.map'
        ],
        'published': {
          'bundle.js': 'bundle.js',
          'bundle.js.map': 'bundle.js.map',
          '1.bundle.js': '1.bundle.js',
          '1.bundle.js.map': '1.bundle.js.map',
          '2.bundle.js': '2.bundle.js',
          '2.bundle.js.map': '2.bundle.js.map',
          '3.bundle.js': '3.bundle.js',
          '3.bundle.js.map': '3.bundle.js.map',
          '0.bundle.css': '0.bundle.css'
        },
        'entry': 'bundle.js',
        'usedModules': []
      });
<commit_msg>Fix tests under latest webpack<commit_after>var Circus = require('circus'),
    CircusRouter = require('../../lib'),
    ModuleNotFoundError = require('webpack/lib/ModuleNotFoundError'),
    webpack = require('webpack');

var expect = require('chai').expect,
    temp = require('temp'),
    fs = require('fs'),
    path = require('path');

describe('loader plugin', function() {
  var outputDir;

  beforeEach(function(done) {
    temp.mkdir('loader-plugin', function(err, dirPath) {
      if (err) {
        throw err;
      }

      outputDir = dirPath;
      done();
    });
  });
  afterEach(function() {
    temp.cleanupSync();
  });

  it('should create a chunk for each import', function(done) {
    var entry = path.resolve(__dirname + '/../fixtures/loader.js');

    var config = {
      entry: entry,
      output: {
        component: 'pack',
        path: outputDir
      },

      externals: {
        'circus': 'Circus'
      }
    };
    config = CircusRouter.config(config);
    config = Circus.config(config);

    webpack(config, function(err, status) {
      expect(err).to.not.exist;
      expect(status.compilation.errors).to.be.empty;
      expect(status.compilation.warnings.length).to.equal(3);
      expect(status.compilation.warnings[2]).to.match(/loader.js:\d+ - Circus.loader used to load module "`.\/router-no-routes.js" declaring no route/);

      // Verify the chunk division
      expect(status.compilation.chunks.length).to.equal(5);

      // Verify the loader boilerplate
      var output = fs.readFileSync(outputDir + '/bundle.js').toString();
      expect(output).to.match(/Circus.loader\(__webpack_require__, \{"modules":\{"2":\{"chunk":1\},"3":\{"chunk":2\}\},"routes":\{"\/foo":3,"\/bar":3\}\}\);/);

      // Verify the module map output
      var pack = JSON.parse(fs.readFileSync(outputDir + '/circus.json').toString());
      delete pack.circusVersion;   // To avoid erroring the tests
      expect(pack).to.eql({
        'bootstrap': 'bootstrap.js',
        'components': [],
        'chunks': [
          {'js': 'bundle.js', 'css': '0.bundle.css'},
          {'js': '1.bundle.js'},
          {'js': '2.bundle.js'},
          {'js': '3.bundle.js'}
        ],
        'modules': {
          '0': {
            'chunk': 0,
            'name': 'pack/test/fixtures/loader'
          },
          '2': {
            'chunk': 1,
            'name': 'pack/test/fixtures/router1'
          },
          '3': {
            'chunk': 2,
            'name': 'pack/test/fixtures/router-imported'
          },
          '4': {
            'chunk': 3,
            'name': 'pack/test/fixtures/router-no-routes'
          }
        },
        'routes': {
          '/foo': 3,
          '/bar': 3
        },
        'files': [
          'bundle.js',
          '0.bundle.css',
          'bundle.js.map',
          '0.bundle.css.map',
          '1.bundle.js',
          '1.bundle.js.map',
          '2.bundle.js',
          '2.bundle.js.map',
          '3.bundle.js',
          '3.bundle.js.map'
        ],
        'published': {
          'bundle.js': 'bundle.js',
          'bundle.js.map': 'bundle.js.map',
          '1.bundle.js': '1.bundle.js',
          '1.bundle.js.map': '1.bundle.js.map',
          '2.bundle.js': '2.bundle.js',
          '2.bundle.js.map': '2.bundle.js.map',
          '3.bundle.js': '3.bundle.js',
          '3.bundle.js.map': '3.bundle.js.map',
          '0.bundle.css': '0.bundle.css',
          '0.bundle.css.map': '0.bundle.css.map'
        },
        'entry': 'bundle.js',
        'usedModules': []
      });

{'fraction_non_alphanumeric': 0.19264100014206564, 'fraction_numerical': 0.013212103992044325, 'mean_word_length': 1.8606257618854125, 'pattern_counts': {'":': 16, '<': 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': '2095017', 'n_tokens_mistral': 2313, 'n_tokens_neox': 2276, 'n_words': 375}