<commit_before>var proxyquire = require('proxyquire').noCallThru()
var simple = require('simple-mock')
var test = require('tap').test

test('bundle client', function (group) {
  group.test('client & bundle with same mtime', function (t) {
    var readFileMock = simple.stub().callbackWith(null, new Buffer('bundle content'))
    var bundleClient = proxyquire('../../server/plugins/client/bundle', {
      fs: {
        readFile: readFileMock,
        stat: simple.stub().callbackWith(null, {mtime: new Date()})
      }
    })

    bundleClient('client.js', 'bundle.js', {}, function (error) {
      t.error(error)

      t.is(readFileMock.callCount, 1, 'readFile called once')
      t.is(readFileMock.lastCall.arg, 'bundle.js', 'read bundle')

      t.end()
    })
  })

  group.test('bundle does not exist', function (t) {
    var readFileMock = simple.stub().callbackWith(null, new Buffer('hoodie client content'))
    var bundleClient = proxyquire('../../server/plugins/client/bundle', {
      fs: {
        readFile: readFileMock,
        stat: simple.stub().callFn(function (path, callback) {
          if (path === 'client.js') {
            return callback(null, {mtime: new Date()})
          }

          callback(new Error('boom'))
        })
      }
    })

    bundleClient('client.js', 'bundle.js', {}, function (error, buffer) {
      t.error(error)

      t.is(readFileMock.callCount, 1, 'readFile called once')
      t.is(readFileMock.lastCall.arg, 'client.js', 'read bundle')
      t.is(buffer.toString(), 'hoodie client content\n\nhoodie = new Hoodie()')

      t.end()
    })
  })

  group.test('with client options', function (t) {
    var readFileMock = simple.stub().callbackWith(null, new Buffer('hoodie client content'))
    var bundleClient = proxyquire('../../server/plugins/client/bundle', {
      fs: {
        readFile: readFileMock,
        stat: simple.stub().callFn(function (path, callback) {
          if (path === 'client.js') {
            return callback(null, {mtime: new Date()})
          }

          callback(new Error('boom'))
        })
      }
    })

    bundleClient('client.js', 'bundle.js', {
      client: {
        foo: 'bar'
      }
    }, function (error, buffer) {
      t.error(error)

      t.is(buffer.toString(), 'hoodie client content\n\nhoodie = new Hoodie({"foo":"bar"})')

      t.end()
    })
  })

  group.test('fs.readFile fails', function (t) {
    var bundleClient = proxyquire('../../server/plugins/client/bundle', {
      fs: {
        readFile: simple.stub().callbackWith(new Error('boom')),
        stat: simple.stub().callbackWith(null, {mtime: new Date()})
      }
    })

    bundleClient('client.js', 'bundle.js', {}, function (error) {
      t.is(error.message, 'boom', 'passes error')

      t.end()
    })
  })

  group.end()
})<commit_msg>test: pass config.url to client<commit_after>var proxyquire = require('proxyquire').noCallThru()
var simple = require('simple-mock')
var test = require('tap').test

test('bundle client', function (group) {
  group.test('client & bundle with same mtime', function (t) {
    var readFileMock = simple.stub().callbackWith(null, new Buffer('bundle content'))
    var bundleClient = proxyquire('../../server/plugins/client/bundle', {
      fs: {
        readFile: readFileMock,
        stat: simple.stub().callbackWith(null, {mtime: new Date()})
      }
    })

    bundleClient('client.js', 'bundle.js', {}, function (error) {
      t.error(error)

      t.is(readFileMock.callCount, 1, 'readFile called once')
      t.is(readFileMock.lastCall.arg, 'bundle.js', 'read bundle')

      t.end()
    })
  })

  group.test('bundle does not exist', function (t) {
    var readFileMock = simple.stub().callbackWith(null, new Buffer('hoodie client content'))
    var bundleClient = proxyquire('../../server/plugins/client/bundle', {
      fs: {
        readFile: readFileMock,
        stat: simple.stub().callFn(function (path, callback) {
          if (path === 'client.js') {
            return callback(null, {mtime: new Date()})
          }

          callback(new Error('boom'))
        })
      }
    })

    bundleClient('client.js', 'bundle.js', {}, function (error, buffer) {
      t.error(error)

      t.is(readFileMock.callCount, 1, 'readFile called once')
      t.is(readFileMock.lastCall.arg, 'client.js', 'read bundle')
      t.is(buffer.toString(), 'hoodie client content\n\nhoodie = new Hoodie()')

      t.end()
    })
  })

  group.test('with client options', function (t) {
    var readFileMock = simple.stub().callbackWith(null, new Buffer('hoodie client content'))
    var bundleClient = proxyquire('../../server/plugins/client/bundle', {
      fs: {
        readFile: readFileMock,
        stat: simple.stub().callFn(function (path, callback) {
          if (path === 'client.js') {
            return callback(null, {mtime: new Date()})
          }

          callback(new Error('boom'))
        })
      }
    })

    bundleClient('client.js', 'bundle.js', {
      url: 'https://myapp.com'
    }, function (error, buffer) {
      t.error(error)

      t.is(buffer.toString(), 'hoodie client content\n\nhoodie = new Hoodie({url: "https://myapp.com"})')

      t.end()
    })
  })

  group.test('fs.readFile fails', function (t) {
    var bundleClient = proxyquire('../../server/plugins/client/bundle', {
      fs: {
        readFile: simple.stub().callbackWith(new Error('boom')),
        stat: simple.stub().callbackWith(null, {mtime: new Date()})
      }
    })

    bundleClient('client.js', 'bundle.js', {}, function (error) {
      t.is(error.message, 'boom', 'passes error')

      t.end()
    })
  })

  group.end()
})
{'fraction_non_alphanumeric': 0.17453580901856763, 'fraction_numerical': 0.0007073386383731211, 'mean_word_length': 2.65374677002584, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '6946595', 'n_tokens_mistral': 1796, 'n_tokens_neox': 1765, 'n_words': 366}