var test = require('tape')
var Uppy = require('../src/core/Core.js')

test('core', function (t) {
  const uppy = new Uppy()

  t.equal(typeof uppy, 'object', '`new Core()` should return an `object`')
  t.ok(uppy instanceof Uppy, '`uppy` should be an instance of `Uppy` core')
  t.end()
})

test('use plugins', function (t) {
  const SelecterPlugin = require('./mocks/plugin-selecter1.js')
  const uppy = new Uppy()
  uppy
    .use(SelecterPlugin)

  t.equal(Object.keys(uppy.plugins).length, 1, 'should add a plugin to the plugins stack')
  t.end()
})

test('noDuplicates', function (t) {
  const Selecter1Plugin = require('./mocks/plugin-selecter1.js')
  const uppyTwoSelecters = new Uppy()
  let err = ''
  try {
    uppyTwoSelecters
    .use(Selecter1Plugin)
    .use(Selecter1Plugin)
    .run()
  } catch (e) {
    err = e.message
  }

  t.equal(err, 'Uppy is currently limited to running one of every plugin. Share your use case with us over at https://github.com/transloadit/uppy/issues/ if you want us to reconsider.', 'should throw error on use of duplicate plugin')
  t.end()
})

test('autoProceed', function (t) {
  const Selecter1Plugin = require('./mocks/plugin-selecter1.js')
  const Selecter2Plugin = require('./mocks/plugin-selecter2.js')

  const uppyOneSelecter = new Uppy()
  uppyOneSelecter
    .use(Selecter1Plugin)
    .run()

  const uppyTwoSelecters = new Uppy()
  uppyTwoSelecters
    .use(Selecter1Plugin)
    .use(Selecter2Plugin)
    .run()

  t.equal(uppyOneSelecter.opts.autoProceed, true, 'should autoProceed if only one selecter is used')
  t.equal(uppyTwoSelecters.opts.autoProceed, false, 'should not autoProceed if more than one selecter is used')
  t.end()
})

@@ -689,33 +689,9 @@
 y()%0A
-  let err = ''%0A  try %7B%0A  
+%0A
   up
@@ -696,37 +696,32 @@
 uppyTwoSelecters
-%0A    
 .use(Selecter1Pl
@@ -732,317 +732,166 @@
 )%0A  
-  .use(Selecter1Plugin)%0A    .run()%0A  %7D catch (e) %7B%0A    err = e.message%0A  %7D%0A%0A  t.equal(err, 'Uppy is currently limited to running one of every plugin. Share your use case with us over at https://github.com/transloadit/uppy/issues/ if you want us to reconsider.', 'should throw error on use of duplicate plugin'
+const fn = uppyTwoSelecters.use.bind(uppyTwoSelecters, Selecter1Plugin)%0A%0A  t.throws(fn, new RegExp('Uppy is currently limited to running one of every plugin')
 )%0A  

Use t.throws