<commit_before>
var describe = require('mocha').describe;
var it = require('mocha').it;
var expect = require('chai').expect;
var path = require('path');
var webpack = require('webpack');
var process = require('process');
var ForkTsCheckerWebpackPlugin = require('../../lib/index');
var IncrementalChecker = require('../../lib/IncrementalChecker');

var webpackMajorVersion = require('./webpackVersion')();

describe('[INTEGRATION] vue', function () {
  this.timeout(60000);
  process.setMaxListeners(20);   
  var plugin;
  var files;
  var compiler;
  var checker;

  function createCompiler(options) {
    plugin = new ForkTsCheckerWebpackPlugin(Object.assign({}, options, { silent: true }));

    compiler = webpack({
      ...(webpackMajorVersion >= 4 ? { mode: 'development' } : {}),
      context: path.resolve(__dirname, './vue'),
      entry: './src/index.ts',
      output: {
        path: path.resolve(__dirname, '../../tmp')
      },
      resolve: {
        extensions: ['.ts', '.js', '.vue', '.json'],
        alias: {
          '@': path.resolve(__dirname, './vue/src'),
        }
      },
      module: {
        rules: [
          {
            test: /\.vue$/,
            loader: 'vue-loader'
          },
          {
            test: /\.ts$/,
            loader: 'ts-loader',
            options: {
              appendTsSuffixTo: [/\.vue$/],
              transpileOnly: true,
              silent: true
            }
          },
          {
            test: /\.css$/,
            loader: 'css-loader'
          }
        ]
      },
      plugins: [
        plugin
      ]
    });

    files = {
      'example.vue': path.resolve(compiler.context, 'src/example.vue'),
      'syntacticError.ts': path.resolve(compiler.context, 'src/syntacticError.ts')
    };

    checker = new IncrementalChecker(
      plugin.tsconfigPath,
      plugin.tslintPath || false,
      [compiler.context],
      ForkTsCheckerWebpackPlugin.ONE_CPU,
      1,
      plugin.checkSyntacticErrors,
      plugin.vue
    );

    checker.nextIteration();
  }

  it('should create a Vue program config if vue=true', function () {
    createCompiler({ vue: true });

    var fileFound;
    
    fileFound = checker.programConfig.fileNames.indexOf(files['example.vue']) >= 0;
    expect(fileFound).to.be.true;
    
    fileFound = checker.programConfig.fileNames.indexOf(files['syntacticError.ts']) >= 0;
    expect(fileFound).to.be.true;
  });

  it('should not create a Vue program config if vue=false', function () {
    createCompiler();

    var fileFound;    
    
    fileFound = checker.programConfig.fileNames.indexOf(files['example.vue']) >= 0;
    expect(fileFound).to.be.false;
    
    fileFound = checker.programConfig.fileNames.indexOf(files['syntacticError.ts']) >= 0;
    expect(fileFound).to.be.true;
  });

  it('should create a Vue program if vue=true', function () {
    createCompiler({ vue: true });

    var source;

    source = checker.program.getSourceFile(files['example.vue']);
    expect(source).to.not.be.undefined;
    
    source = checker.program.getSourceFile(files['syntacticError.ts']);
    expect(source).to.not.be.undefined;  
  });

  it('should not create a Vue program if vue=false', function () {
    createCompiler();
    
    var source;
    
    source = checker.program.getSourceFile(files['example.vue']);
    expect(source).to.be.undefined;
    
    source = checker.program.getSourceFile(files['syntacticError.ts']);
    expect(source).to.not.be.undefined;  
  });

  it('should get syntactic diagnostics from Vue program', function () {
    createCompiler({ tslint: true, vue: true });

    const diagnostics = checker.program.getSyntacticDiagnostics();
    expect(diagnostics.length).to.be.equal(1);    
  });

  it('should not find syntactic errors when checkSyntacticErrors is false', function (callback) {
    createCompiler({ tslint: true, vue: true });
    
    compiler.run(function(error, stats) {
      expect(stats.compilation.errors.length).to.be.equal(1);
      callback();
    });
  });

  it('should find syntactic errors when checkSyntacticErrors is true', function (callback) {
    createCompiler({ tslint: true, vue: true, checkSyntacticErrors: true });
    
    compiler.run(function(error, stats) {
      expect(stats.compilation.errors.length).to.be.equal(2);
      callback();
    });
  });

  [
    'example-ts.vue',
    'example-tsx.vue',
    'example-js.vue',
    'example-jsx.vue',
    'example-nolang.vue'
  ].forEach(fileName => {
    it('should be able to extract script from ' + fileName, function () {
      createCompiler({ vue: true, tsconfig: 'tsconfig-langs.json' });
      var sourceFilePath = path.resolve(compiler.context, 'src/langs/' + fileName)
      var source = checker.program.getSourceFile(sourceFilePath);
      expect(source).to.not.be.undefined;
      // remove padding lines
      var text = source.text.replace(/^\s*\/\/.*$\n/gm, '');
      expect(text.startsWith('/* OK */')).to.be.true;
    });
  });

  function groupByFileName(errors) {
    var ret = {<commit_msg>vue tests now tolerant of crlf<commit_after>
var describe = require('mocha').describe;
var it = require('mocha').it;
var expect = require('chai').expect;
var path = require('path');
var webpack = require('webpack');
var process = require('process');
var ForkTsCheckerWebpackPlugin = require('../../lib/index');
var IncrementalChecker = require('../../lib/IncrementalChecker');

var webpackMajorVersion = require('./webpackVersion')();

describe('[INTEGRATION] vue', function () {
  this.timeout(60000);
  process.setMaxListeners(0);   
  var plugin;
  var files;
  var compiler;
  var checker;

  function createCompiler(options) {
    plugin = new ForkTsCheckerWebpackPlugin(Object.assign({}, options, { silent: true }));

    compiler = webpack({
      ...(webpackMajorVersion >= 4 ? { mode: 'development' } : {}),
      context: path.resolve(__dirname, './vue'),
      entry: './src/index.ts',
      output: {
        path: path.resolve(__dirname, '../../tmp')
      },
      resolve: {
        extensions: ['.ts', '.js', '.vue', '.json'],
        alias: {
          '@': path.resolve(__dirname, './vue/src'),
        }
      },
      module: {
        rules: [
          {
            test: /\.vue$/,
            loader: 'vue-loader'
          },
          {
            test: /\.ts$/,
            loader: 'ts-loader',
            options: {
              appendTsSuffixTo: [/\.vue$/],
              transpileOnly: true,
              silent: true
            }
          },
          {
            test: /\.css$/,
            loader: 'css-loader'
          }
        ]
      },
      plugins: [
        plugin
      ]
    });

    files = {
      'example.vue': path.resolve(compiler.context, 'src/example.vue'),
      'syntacticError.ts': path.resolve(compiler.context, 'src/syntacticError.ts')
    };

    checker = new IncrementalChecker(
      plugin.tsconfigPath,
      plugin.tslintPath || false,
      [compiler.context],
      ForkTsCheckerWebpackPlugin.ONE_CPU,
      1,
      plugin.checkSyntacticErrors,
      plugin.vue
    );

    checker.nextIteration();
  }

  it('should create a Vue program config if vue=true', function () {
    createCompiler({ vue: true });

    var fileFound;
    
    fileFound = checker.programConfig.fileNames.indexOf(files['example.vue']) >= 0;
    expect(fileFound).to.be.true;
    
    fileFound = checker.programConfig.fileNames.indexOf(files['syntacticError.ts']) >= 0;
    expect(fileFound).to.be.true;
  });

  it('should not create a Vue program config if vue=false', function () {
    createCompiler();

    var fileFound;    
    
    fileFound = checker.programConfig.fileNames.indexOf(files['example.vue']) >= 0;
    expect(fileFound).to.be.false;
    
    fileFound = checker.programConfig.fileNames.indexOf(files['syntacticError.ts']) >= 0;
    expect(fileFound).to.be.true;
  });

  it('should create a Vue program if vue=true', function () {
    createCompiler({ vue: true });

    var source;

    source = checker.program.getSourceFile(files['example.vue']);
    expect(source).to.not.be.undefined;
    
    source = checker.program.getSourceFile(files['syntacticError.ts']);
    expect(source).to.not.be.undefined;  
  });

  it('should not create a Vue program if vue=false', function () {
    createCompiler();
    
    var source;
    
    source = checker.program.getSourceFile(files['example.vue']);
    expect(source).to.be.undefined;
    
    source = checker.program.getSourceFile(files['syntacticError.ts']);
    expect(source).to.not.be.undefined;  
  });

  it('should get syntactic diagnostics from Vue program', function () {
    createCompiler({ tslint: true, vue: true });

    const diagnostics = checker.program.getSyntacticDiagnostics();
    expect(diagnostics.length).to.be.equal(1);    
  });

  it('should not find syntactic errors when checkSyntacticErrors is false', function (callback) {
    createCompiler({ tslint: true, vue: true });
    
    compiler.run(function(error, stats) {
      expect(stats.compilation.errors.length).to.be.equal(1);
      callback();
    });
  });

  it('should find syntactic errors when checkSyntacticErrors is true', function (callback) {
    createCompiler({ tslint: true, vue: true, checkSyntacticErrors: true });
    
    compiler.run(function(error, stats) {
      expect(stats.compilation.errors.length).to.be.equal(2);
      callback();
    });
  });

  [
    'example-ts.vue',
    'example-tsx.vue',
    'example-js.vue',
    'example-jsx.vue',
    'example-nolang.vue'
  ].forEach(fileName => {
    it('should be able to extract script from ' + fileName, function () {
      createCompiler({ vue: true, tsconfig: 'tsconfig-langs.json' });
      var sourceFilePath = path.resolve(compiler.context, 'src/langs/' + fileName)
      var source = checker.program.getSourceFile(sourceFilePath);
      expect(source).to.not.be.undefined;
      // remove padding lines
      var text = source.text.replace(/^\s*\/\/.*$\r*\n/gm, '');
      expect(text.startsWith('/* OK */')).to.be.true;
    });
  });

  function groupByFileName(errors) {
    var ret = {
{'fraction_non_alphanumeric': 0.1573388609219228, 'fraction_numerical': 0.003059915112032376, 'mean_word_length': 2.638061041292639, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '5540406', 'n_tokens_mistral': 3174, 'n_tokens_neox': 3106, 'n_words': 595}