<commit_before>var tape = require('tape')
var fs = require('fs')
var autoUpdater = require('..')

tape('check for new version', function (t) {
  var updater = new autoUpdater({ 
    manifestUrl: 'http://www.strem.io/stremioVersions.json', downloadUrl: 'http://dl.strem.io/Stremio',
    version: { version: '3.4.4', stremioRuntimeVersion: '3.2' } 
  })

  updater.check(function (err, newVersion, manifest) {
    t.error(err, 'no error')
    t.ok(newVersion, 'has new version object')
    t.ok(newVersion && newVersion.version, 'has new version code')
    t.ok(Array.isArray(manifest), 'passes manifest')
    t.end()
  })
})


tape('check for new version - we have the newest', function (t) {
  var updater = new autoUpdater({ 
    manifestUrl: 'http://www.strem.io/stremioVersions.json', downloadUrl: 'http://dl.strem.io/Stremio',
    version: { version: '3.4.4', stremioRuntimeVersion: '3.2' } 
  })

  updater.manifest(function (err, versions) {
    var latest = versions.filter(updater.options.filter).pop()
    updater.options.version = latest

    updater.check(function (err, newVersion) {
      t.error(err, 'no error')
      t.ok(!newVersion, 'has no new version object')
      t.end()
    })
  })
})


tape('basic check for new version - handle errors', function (t) {
  var updater = new autoUpdater({ 
    manifestUrl: 'http://ewrqwerqwreqw.io/stremioVersions.json', downloadUrl: 'http://dl.strem.io/Stremio',
    version: { version: '3.4.4', stremioRuntimeVersion: '3.2' } 
  })

  updater.check(function (err, newVersion) {
    t.ok(err, 'we have an error')
    t.end()
  })
})

tape('basic check for new version - use fallback urls', function (t) {
  var updater = new autoUpdater({ 
    manifestUrl: ['http://ewrqwerqwreqw.io/stremioVersions.json', 'http://www.strem.io/stremioVersions.json'], downloadUrl: 'http://dl.strem.io/Stremio',
    version: { version: '3.4.4', stremioRuntimeVersion: '3.2' } 
  })

  updater.check(function (err, newVersion) {
    t.error(err, 'no error')
    t.ok(newVersion, 'has new version object')
    t.ok(newVersion && newVersion.version, 'has new version code')
    t.end()
  })
})


tape('update to new version via asar', function (t) {
  var updater = new autoUpdater({ 
    manifestUrl: 'http://www.strem.io/stremioVersions.json', downloadUrl: 'http://dl.strem.io/Stremio',
    runtimeVerProp: 'stremioRuntimeVersion',
    version: { version: '3.4.4', stremioRuntimeVersion: '3.1' } 
  })

  updater.check(function (err, newVersion) {
    t.error(err, 'no error')
    t.ok(newVersion, 'has new version object')
    t.ok(newVersion && newVersion.version, 'has new version code')
    t.ok(newVersion.stremioRuntimeVersion === '3.1', 'asar only update')

    updater.prepare(newVersion, function (err, res) {
      t.error(err, 'no error')
      t.ok(res.isAsarUpdate, 'is asar update')
      t.ok(res.saveTo.match('.asar$'), 'downloaded .asar file')
      t.end()
    })<commit_msg>Fix tests<commit_after>var tape = require('tape')
var fs = require('fs')
var autoUpdater = require('..')

tape('check for new version', function (t) {
  var updater = new autoUpdater({ 
    manifestUrl: 'http://www.strem.io/stremioVersions.json', downloadUrl: 'http://dl.strem.io/Stremio',
    version: { version: '3.4.4', stremioRuntimeVersion: '3.2' } 
  })

  updater.check(function (err, newVersion, manifest) {
    t.error(err, 'no error')
    t.ok(newVersion, 'has new version object')
    t.ok(newVersion && newVersion.version, 'has new version code')
    t.ok(Array.isArray(manifest), 'passes manifest')
    t.end()
  })
})


tape('check for new version - we have the newest', function (t) {
  var updater = new autoUpdater({ 
    manifestUrl: 'http://www.strem.io/stremioVersions.json', downloadUrl: 'http://dl.strem.io/Stremio',
    version: { version: '3.4.4', stremioRuntimeVersion: '3.2' } 
  })

  updater.manifest(function (err, versions) {
    var latest = versions.filter(updater.options.filter).pop()
    updater.options.version = latest

    updater.check(function (err, newVersion) {
      t.error(err, 'no error')
      t.ok(!newVersion, 'has no new version object')
      t.end()
    })
  })
})


tape('basic check for new version - handle errors', function (t) {
  var updater = new autoUpdater({ 
    manifestUrl: 'http://ewrqwerqwreqw.io/stremioVersions.json', downloadUrl: 'http://dl.strem.io/Stremio',
    version: { version: '3.4.4', stremioRuntimeVersion: '3.2' } 
  })

  updater.check(function (err, newVersion) {
    t.ok(err, 'we have an error')
    t.end()
  })
})

tape('basic check for new version - use fallback urls', function (t) {
  var updater = new autoUpdater({ 
    manifestUrl: ['http://ewrqwerqwreqw.io/stremioVersions.json', 'http://www.strem.io/stremioVersions.json'], downloadUrl: 'http://dl.strem.io/Stremio',
    version: { version: '3.4.4', stremioRuntimeVersion: '3.2' } 
  })

  updater.check(function (err, newVersion) {
    t.error(err, 'no error')
    t.ok(newVersion, 'has new version object')
    t.ok(newVersion && newVersion.version, 'has new version code')
    t.end()
  })
})


tape('update to new version via asar', function (t) {
  var updater = new autoUpdater({ 
    manifestUrl: 'http://www.strem.io/stremioVersions.json', downloadUrl: 'http://dl.strem.io/Stremio',
    runtimeVerProp: 'stremioRuntimeVersion',
    version: { version: '3.5.4', stremioRuntimeVersion: '3.5' } 
  })

  updater.check(function (err, newVersion) {
    t.error(err, 'no error')
    t.ok(newVersion, 'has new version object')
    t.ok(newVersion && newVersion.version, 'has new version code')
    t.ok(newVersion.stremioRuntimeVersion === '3.5', 'asar only update')

    updater.prepare(newVersion, function (err, res) {
      t.error(err, 'no error')
      t.ok(res.isAsarUpdate, 'is asar update')
      t.ok(res.saveTo.match('.asar$'), 'downloaded .asar file')
      t.end()
    })
{'fraction_non_alphanumeric': 0.16723549488054607, 'fraction_numerical': 0.009215017064846417, 'mean_word_length': 3.57890625, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 8, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1299840', 'n_tokens_mistral': 2124, 'n_tokens_neox': 2111, 'n_words': 457}