Sfoglia il codice sorgente

Refactor acceptance tests all over again, add global.uppyLog

Artur Paikin 9 anni fa
parent
commit
c3d3d6e465

+ 1 - 1
package.json

@@ -23,7 +23,7 @@
     "start:server": "uppy-server --port 3020",
     "start:server": "uppy-server --port 3020",
     "start": "parallelshell 'npm run watch' 'npm run start:server' 'npm run web:preview'",
     "start": "parallelshell 'npm run watch' 'npm run start:server' 'npm run web:preview'",
     "test:acceptance:handleservers": "bin/bootandkill-servers node test/acceptance/index.js",
     "test:acceptance:handleservers": "bin/bootandkill-servers node test/acceptance/index.js",
-    "test:acceptance": "node test/acceptance/index.js | tap-spec",
+    "test:acceptance": "node test/acceptance/index.js",
     "test:unit": "node test/unit/index.js | tap-spec",
     "test:unit": "node test/unit/index.js | tap-spec",
     "test": "npm run lint && npm run test:unit",
     "test": "npm run lint && npm run test:unit",
     "travis:deletecache": "travis cache --delete",
     "travis:deletecache": "travis cache --delete",

+ 5 - 0
src/core/Core.js

@@ -1,6 +1,7 @@
 import Utils from '../core/Utils'
 import Utils from '../core/Utils'
 import Translator from '../core/Translator'
 import Translator from '../core/Translator'
 import ee from 'events'
 import ee from 'events'
+// import freeze from 'deep-freeze'
 
 
 /**
 /**
  * Main Uppy core
  * Main Uppy core
@@ -49,6 +50,8 @@ export default class Core {
       }
       }
     }
     }
 
 
+    // freeze(this.defaultState)
+
     this.state = Object.assign({}, this.defaultState)
     this.state = Object.assign({}, this.defaultState)
     this.state.book = 'Harry Potter'
     this.state.book = 'Harry Potter'
 
 
@@ -260,6 +263,8 @@ export default class Core {
       console.log('DEBUG LOG')
       console.log('DEBUG LOG')
       console.dir(msg)
       console.dir(msg)
     }
     }
+    global.uppyLog = global.uppyLog || ''
+    global.uppyLog = global.uppyLog + '\n' + 'DEBUG LOG: ' + msg
   }
   }
 
 
 /**
 /**

+ 0 - 42
test/acceptance/Browser.js

@@ -1,42 +0,0 @@
-var webdriver = require('selenium-webdriver')
-var firefox = require('selenium-webdriver/firefox')
-var By = webdriver.By
-var path = require('path')
-var chalk = require('chalk')
-
-// Monitor for errors, and dump them
-function monitorErrors (driver) {
-  var promise = driver.executeScript('return window.JSErrorCollector_errors.pump()')
-  promise.then(function (errors) {
-    if (!errors || !errors.length) {
-      return
-    }
-    errors.forEach(function (error) {
-      console.error([
-        '[browser-error]',
-        chalk.magenta(error.sourceName),
-        chalk.dim('#' + error.lineNumber),
-        chalk.red(error.errorMessage)
-      ].join(' '))
-    })
-  })
-}
-
-function setDriver () {
-  var profile = new firefox.Profile()
-  profile.addExtension(path.join(__dirname, 'xpi', 'firebug-2.0.16.xpi'))
-  profile.addExtension(path.join(__dirname, 'xpi', 'JSErrorCollector.xpi'))
-  profile.setPreference('extensions.firebug.showChromeErrors', true)
-
-  var options = new firefox.Options().setProfile(profile)
-  var driver = new firefox.Driver(options)
-
-  monitorErrors(driver)
-
-  return driver
-}
-
-module.exports = {
-  setDriver,
-  By
-}

+ 54 - 0
test/acceptance/Driver.js

@@ -0,0 +1,54 @@
+var webdriver = require('selenium-webdriver')
+var firefox = require('selenium-webdriver/firefox')
+var By = webdriver.By
+var path = require('path')
+var chalk = require('chalk')
+
+// Monitor for errors, and dump them
+function collectErrors (driver) {
+  return driver.executeScript('return uppyLog;')
+    .then(function (uppyLog) {
+      console.error([
+        '[uppy-log]',
+        chalk.magenta(uppyLog)
+      ].join(' '))
+
+      return driver.executeScript('return window.JSErrorCollector_errors.pump()')
+        .then(function (errors) {
+          if (!errors || !errors.length) {
+            return
+          }
+          errors.forEach(function (error) {
+            console.error([
+              '[browser-error]',
+              chalk.magenta(error.sourceName),
+              chalk.dim('#' + error.lineNumber),
+              chalk.red(error.errorMessage)
+            ].join(' '))
+          })
+          return
+        })
+    })
+}
+
+function setDriver () {
+  var profile = new firefox.Profile()
+  profile.addExtension(path.join(__dirname, 'xpi', 'firebug-2.0.16.xpi'))
+  profile.addExtension(path.join(__dirname, 'xpi', 'JSErrorCollector.xpi'))
+  profile.setPreference('extensions.firebug.showChromeErrors', true)
+
+  var options = new firefox.Options().setProfile(profile)
+  var driver = new firefox.Driver(options)
+
+  // var driver = new webdriver.Builder()
+  //     .forBrowser('firefox')
+  //     .build()
+
+  return driver
+}
+
+module.exports = {
+  setDriver,
+  collectErrors,
+  By
+}

+ 27 - 24
test/acceptance/dragdrop.spec.js

@@ -1,37 +1,40 @@
 var test = require('tape')
 var test = require('tape')
 var path = require('path')
 var path = require('path')
-var Browser = require('./Browser')
-var browser = Browser.setDriver()
-var By = Browser.By
-
-var config = {
-  testUrl: 'http://localhost:4000/examples/dragdrop/',
-  dragDropInputSelector: '.UppyDragDrop-One .UppyDragDrop-input',
-  imagePath: path.join(__dirname, 'image.jpg')
-}
-
-var consoleElement = browser.findElement(By.id('console-log'))
+var Driver = require('./Driver')
+var By = Driver.By
+var collectErrors = Driver.collectErrors
 
 
 test('dragdrop: make sure DragDrop accepts and uploads 1 file via input', function (t) {
 test('dragdrop: make sure DragDrop accepts and uploads 1 file via input', function (t) {
   t.plan(1)
   t.plan(1)
 
 
-  // Go to the example URL
-  browser.get(config.testUrl)
+  var driver = Driver.setDriver()
 
 
-  // Find input by css selector
-  var input = browser.findElement(By.css(config.dragDropInputSelector))
+  // Go to the example URL
+  driver.get('http://localhost:4000/examples/dragdrop/')
 
 
-  // Pass absolute image path to the input
-  input.sendKeys(config.imagePath)
+  // Find input by css selector & pass absolute image path to it
+  driver
+    .findElement(By.css('.UppyDragDrop-One .UppyDragDrop-input'))
+    .sendKeys(path.join(__dirname, 'image.jpg'))
 
 
-  // Wait for a while for upload to go through
-  browser.sleep(3000)
+  driver.sleep(3000)
 
 
   // Get console elements’s value, then check if it has “Download” there somewhere,
   // Get console elements’s value, then check if it has “Download” there somewhere,
   // if it does, then test passes
   // if it does, then test passes
-  consoleElement.getAttribute('value').then(function (value) {
-    var isFileUploaded = value.indexOf('Download') !== -1
-    t.equal(isFileUploaded, true)
-    browser.quit()
-  })
+  driver.findElement(By.id('console-log'))
+        .getAttribute('value')
+        .then(function (value) {
+          var isFileUploaded = value.indexOf('Download') !== -1
+          collectErrors(driver).then(function () {
+            t.equal(isFileUploaded, true)
+            driver.quit()
+          })
+        })
+
+  // driver.wait(isUploadSuccessful, 5000).then(function (result) {
+  //   t.equal(result, true)
+  // })
+  // .catch(function (err) {
+  //   console.error('Something went wrong\n', err.stack, '\n')
+  // })
 })
 })

+ 17 - 0
test/acceptance/dummy.spec.js

@@ -0,0 +1,17 @@
+var test = require('tape')
+var Driver = require('./Browser')
+
+test('open a page, create a variable and get its value', function (t) {
+  t.plan(1)
+
+  var driver = Driver.setDriver()
+
+  driver.get('http://ya.ru')
+  driver.executeScript('window.a = "blabla";')
+  driver.sleep(2000)
+  driver.executeScript('return a').then(function (val) {
+    console.log(val)
+  })
+  driver.sleep(5000)
+  driver.quit()
+})

+ 12 - 19
test/acceptance/i18n.spec.js

@@ -1,28 +1,21 @@
 var test = require('tape')
 var test = require('tape')
-var Browser = require('./Browser')
-var browser = Browser.setDriver()
-var By = Browser.By
-
-var config = {
-  testUrl: 'http://localhost:4000/examples/i18n',
-  dragDropLabelSelector: '.UppyDragDrop-label'
-}
+var Driver = require('./Driver')
+var By = Driver.By
+var collectErrors = Driver.collectErrors
 
 
 test('make sure Uppy loads with Russian language pack', function (t) {
 test('make sure Uppy loads with Russian language pack', function (t) {
   t.plan(1)
   t.plan(1)
 
 
-  // Open the page
-  browser.get(config.testUrl)
-
-  // Wait 3 seconds, for the page to load
-  browser.sleep(3000)
+  var driver = Driver.setDriver()
 
 
-  // Find element, get its text and check that it matches
-  browser.findElement(By.css(config.dragDropLabelSelector))
+  driver.get('http://localhost:4000/examples/i18n')
+  driver
+    .findElement(By.css('.UppyDragDrop-label'))
     .getText()
     .getText()
-    .then(function (val) {
-      console.dir({val: val})
-      t.equal(val, 'Выберите файл или перенесите его сюда')
-      browser.quit()
+    .then(function (value) {
+      collectErrors(driver).then(function () {
+        t.equal(value, 'Выберите файл или перенесите его сюда')
+        driver.quit()
+      })
     })
     })
 })
 })

+ 4 - 2
test/acceptance/index.js

@@ -1,4 +1,6 @@
 // Docs aren't that great to find. Mostly JAVA based. Here are few helpful resources:
 // Docs aren't that great to find. Mostly JAVA based. Here are few helpful resources:
+// - http://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/firefox/index_exports_Driver.html
+//
 // - https://github.com/SeleniumHQ/selenium/wiki/WebDriverJs
 // - https://github.com/SeleniumHQ/selenium/wiki/WebDriverJs
 // - http://seleniumhq.github.io/selenium/docs/api/javascript/
 // - http://seleniumhq.github.io/selenium/docs/api/javascript/
 // - http://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/firefox/index.html
 // - http://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/firefox/index.html
@@ -6,5 +8,5 @@
 // - http://selenium.googlecode.com/git/docs/api/javascript/class_webdriver_WebElement.html
 // - http://selenium.googlecode.com/git/docs/api/javascript/class_webdriver_WebElement.html
 
 
 require('babel-register')
 require('babel-register')
-require('./new-i18n.spec.js')
-require('./new-dragdrop.spec.js')
+require('./i18n.spec.js')
+require('./dragdrop.spec.js')

+ 0 - 40
test/acceptance/new-dragdrop.spec.js

@@ -1,40 +0,0 @@
-var test = require('tape')
-var path = require('path')
-var webdriver = require('selenium-webdriver')
-var By = require('selenium-webdriver').By
-
-test('dragdrop: make sure DragDrop accepts and uploads 1 file via input', function (t) {
-  t.plan(1)
-
-  var driver = new webdriver.Builder()
-      .forBrowser('firefox')
-      .build()
-
-  // Go to the example URL
-  driver.get('http://localhost:4000/examples/dragdrop/')
-
-  // Find input by css selector & pass absolute image path to it
-  driver
-    .findElement(By.css('.UppyDragDrop-One .UppyDragDrop-input'))
-    .sendKeys(path.join(__dirname, 'image.jpg'))
-
-  // Get console elements’s value, then check if it has “Download” there somewhere,
-  // if it does, then test passes
-
-  driver.sleep(10000)
-
-  driver.findElement(By.id('console-log'))
-        .getAttribute('value')
-        .then(function (value) {
-          var isFileUploaded = value.indexOf('Download') !== -1
-          t.equal(isFileUploaded, true)
-          driver.quit()
-        })
-
-  // driver.wait(isUploadSuccessful, 5000).then(function (result) {
-  //   t.equal(result, true)
-  // })
-  // .catch(function (err) {
-  //   console.error('Something went wrong\n', err.stack, '\n')
-  // })
-})

+ 0 - 24
test/acceptance/new-i18n.spec.js

@@ -1,24 +0,0 @@
-var test = require('tape')
-var webdriver = require('selenium-webdriver')
-var By = require('selenium-webdriver').By
-
-test('make sure Uppy loads with Russian language pack', function (t) {
-  t.plan(1)
-  var driver = new webdriver.Builder()
-      .forBrowser('firefox')
-      .build()
-
-  driver.get('http://localhost:4000/examples/i18n')
-  driver.findElement(By.css('.UppyDragDrop-label'))
-        .getText()
-        .then(function (val) {
-          console.dir({val: val})
-          t.equal(val, 'Выберите файл или перенесите его сюда')
-        })
-  driver.quit()
-  // driver.wait(function () {
-  //   return driver.getTitle().then(function (title) {
-  //     return title === 'webdriver - Google Search'
-  //   })
-  // }, 1000)
-})

+ 1 - 1
website/src/examples/i18n/app.es6

@@ -2,7 +2,7 @@ import Uppy from 'uppy/core'
 import { Tus10 } from 'uppy/plugins'
 import { Tus10 } from 'uppy/plugins'
 import { ru_RU } from 'uppy/locales'
 import { ru_RU } from 'uppy/locales'
 
 
-const uppy = new Uppy({wait: false, locales: ru_RU})
+const uppy = new Uppy({debug: true, wait: false, locales: ru_RU})
 
 
 uppy
 uppy
   .use(Tus10, {endpoint: 'http://master.tus.io:3020/files/'})
   .use(Tus10, {endpoint: 'http://master.tus.io:3020/files/'})