<commit_before>var fs = require('fs')
var path = require('path')
var webpack = require('webpack')
var jsdom = require('jsdom')
var expect = require('chai').expect
var assign = require('object-assign')
var rimraf = require('rimraf')
var hash = require('hash-sum')
var SourceMapConsumer = require('source-map').SourceMapConsumer

describe('vue-loader', function () {

  var testHTML = '<!DOCTYPE html><html><head></head><body></body></html>'
  var outputDir = path.resolve(__dirname, './output')
  var loaderPath = path.resolve(__dirname, '../')
  var globalConfig = {
    output: {
      path: outputDir,
      filename: 'test.build.js'
    },
    module: {
      loaders: [
        {
          test: /\.vue$/,
          loader: loaderPath
        }
      ]
    }
  }

  beforeEach(function (done) {
    rimraf(outputDir, done)
  })

  function getFile (file, cb) {
    fs.readFile(path.resolve(outputDir, file), 'utf-8', function (err, data) {
      expect(err).to.be.null
      cb(data)
    })
  }

  function test (options, assert) {
    var config = assign({}, globalConfig, options)
    webpack(config, function (err) {
      expect(err).to.be.null
      getFile('test.build.js', function (data) {
        jsdom.env({
          html: testHTML,
          src: [data],
          done: function (err, window) {
            if (err) {
              console.log(err[0].data.error.stack)
              expect(err).to.be.null
            }
            assert(window)
          }
        })
      })
    })
  }

  it('basic', function (done) {
    test({
      entry: './test/fixtures/basic.js'
    }, function (window) {
      var module = window.testModule
      expect(module.template).to.contain('<h2 class="red">{{msg}}</h2>')
      expect(module.data().msg).to.contain('Hello from Component A!')
      var style = window.document.querySelector('style').textContent
      expect(style).to.contain('comp-a h2 {\n  color: #f00;\n}')
      done()
    })
  })

  it('pre-processors', function (done) {
    test({
      entry: './test/fixtures/pre.js'
    }, function (window) {
      var module = window.testModule
      expect(module.template).to.contain(
        '<h1>This is the app</h1>' +
        '<comp-a></comp-a>' +
        '<comp-b></comp-b>'
      )
      expect(module.data().msg).to.contain('Hello from babel!')
      var style = window.document.querySelector('style').textContent
      expect(style).to.contain('body {\n  font: 100% Helvetica, sans-serif;\n  color: #999;\n}')
      done()
    })
  })

  it('local style', function (done) {
    test({
      entry: './test/fixtures/local-css.js'
    }, function (window) {
      var module = window.testModule
      expect(module.template).to.contain(
        '<div class="v-5f0cf35a"><h1>hi</h1></div>\n' +
        '<p class="abc def v-5f0cf35a">hi</p>'
      )
      var style = window.document.querySelector('style').textContent
      var cls = '.v-' + hash(require.resolve('./fixtures/local-css.vue'))
      expect(style).to.contain('div' + cls + '.test {\n    color: blue;\n}')
      expect(style).to.contain(cls + ' {\n    color: red;\n}')
      expect(style).to.contain(cls + ' h1 {\n    color: green;\n}')
      done()
    })
  })

  it('style import', function (done) {
    test({
      entry: './test/fixtures/import.vue'
    }, function (window) {
      var styles = window.document.querySelectorAll('style')
      expect(styles[0].textContent).to.contain('h1 { color: red; }')
      // import with local
      var cls = '.v-' + hash(require.resolve('./fixtures/import.local.css'))
      expect(styles[1].textContent).to.contain(cls + ' h1 {\n    color: green;\n}')
      done()
    })
  })

  it('source map', function (done) {
    var config = assign({}, globalConfig, {
      entry: './test/fixtures/basic.js',
      devtool: 'source-map'
    })
    webpack(config, function (err) {
      expect(err).to.be.null
      getFile('test.build.js.map', function (map) {
        var smc = new SourceMapConsumer(JSON.parse(map))
        getFile('test.build.js', function (code) {
          var line
          code.split('\n').some(function (l, i) {
            if (l.indexOf('Hello from Component A') > -1) {
              line = i + 1
              return true
            }
          })
          var pos = smc.originalPositionFor({
            line: line,
            column: 0
          })
          expect(pos.source.indexOf('webpack:///test/fixtures/basic.vue') > -1)
          expect(pos.line).to.equal(4)
          done()
        })
      })
    })
  })

})
<commit_msg>fix it for real<commit_after>var fs = require('fs')
var path = require('path')
var webpack = require('webpack')
var jsdom = require('jsdom')
var expect = require('chai').expect
var assign = require('object-assign')
var rimraf = require('rimraf')
var hash = require('hash-sum')
var SourceMapConsumer = require('source-map').SourceMapConsumer

describe('vue-loader', function () {

  var testHTML = '<!DOCTYPE html><html><head></head><body></body></html>'
  var outputDir = path.resolve(__dirname, './output')
  var loaderPath = path.resolve(__dirname, '../')
  var globalConfig = {
    output: {
      path: outputDir,
      filename: 'test.build.js'
    },
    module: {
      loaders: [
        {
          test: /\.vue$/,
          loader: loaderPath
        }
      ]
    }
  }

  beforeEach(function (done) {
    rimraf(outputDir, done)
  })

  function getFile (file, cb) {
    fs.readFile(path.resolve(outputDir, file), 'utf-8', function (err, data) {
      expect(err).to.be.null
      cb(data)
    })
  }

  function test (options, assert) {
    var config = assign({}, globalConfig, options)
    webpack(config, function (err) {
      expect(err).to.be.null
      getFile('test.build.js', function (data) {
        jsdom.env({
          html: testHTML,
          src: [data],
          done: function (err, window) {
            if (err) {
              console.log(err[0].data.error.stack)
              expect(err).to.be.null
            }
            assert(window)
          }
        })
      })
    })
  }

  it('basic', function (done) {
    test({
      entry: './test/fixtures/basic.js'
    }, function (window) {
      var module = window.testModule
      expect(module.template).to.contain('<h2 class="red">{{msg}}</h2>')
      expect(module.data().msg).to.contain('Hello from Component A!')
      var style = window.document.querySelector('style').textContent
      expect(style).to.contain('comp-a h2 {\n  color: #f00;\n}')
      done()
    })
  })

  it('pre-processors', function (done) {
    test({
      entry: './test/fixtures/pre.js'
    }, function (window) {
      var module = window.testModule
      expect(module.template).to.contain(
        '<h1>This is the app</h1>' +
        '<comp-a></comp-a>' +
        '<comp-b></comp-b>'
      )
      expect(module.data().msg).to.contain('Hello from babel!')
      var style = window.document.querySelector('style').textContent
      expect(style).to.contain('body {\n  font: 100% Helvetica, sans-serif;\n  color: #999;\n}')
      done()
    })
  })

  it('local style', function (done) {
    test({
      entry: './test/fixtures/local-css.js'
    }, function (window) {
      var module = window.testModule
      var cls = '.v-' + hash(require.resolve('./fixtures/local-css.vue'))
      expect(module.template).to.contain(
        '<div class="' + cls.slice(1) + '"><h1>hi</h1></div>\n' +
        '<p class="abc def ' + cls.slice(1) + '">hi</p>'
      )
      var style = window.document.querySelector('style').textContent
      expect(style).to.contain('div' + cls + '.test {\n    color: blue;\n}')
      expect(style).to.contain(cls + ' {\n    color: red;\n}')
      expect(style).to.contain(cls + ' h1 {\n    color: green;\n}')
      done()
    })
  })

  it('style import', function (done) {
    test({
      entry: './test/fixtures/import.vue'
    }, function (window) {
      var styles = window.document.querySelectorAll('style')
      expect(styles[0].textContent).to.contain('h1 { color: red; }')
      // import with local
      var cls = '.v-' + hash(require.resolve('./fixtures/import.local.css'))
      expect(styles[1].textContent).to.contain(cls + ' h1 {\n    color: green;\n}')
      done()
    })
  })

  it('source map', function (done) {
    var config = assign({}, globalConfig, {
      entry: './test/fixtures/basic.js',
      devtool: 'source-map'
    })
    webpack(config, function (err) {
      expect(err).to.be.null
      getFile('test.build.js.map', function (map) {
        var smc = new SourceMapConsumer(JSON.parse(map))
        getFile('test.build.js', function (code) {
          var line
          code.split('\n').some(function (l, i) {
            if (l.indexOf('Hello from Component A') > -1) {
              line = i + 1
              return true
            }
          })
          var pos = smc.originalPositionFor({
            line: line,
            column: 0
          })
          expect(pos.source.indexOf('webpack:///test/fixtures/basic.vue') > -1)
          expect(pos.line).to.equal(4)
          done()
        })
      })
    })
  })

})

{'fraction_non_alphanumeric': 0.17716794731064764, 'fraction_numerical': 0.007025246981339188, 'mean_word_length': 2.2171610169491527, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 49, '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': '5746541', 'n_tokens_mistral': 2978, 'n_tokens_neox': 2948, 'n_words': 568}