saucelabs-unit-test.js 1.37 KB
Newer Older
1
2
const JSUnitSaucelabs = require('jsunitsaucelabs')

3
const jsUnitSaucelabs = new JSUnitSaucelabs({
4
5
6
7
8
9
10
  username: process.env.SAUCE_USERNAME,
  password: process.env.SAUCE_ACCESS_KEY
})


// TODO : get all the browsers in sauce_browsers.yml

11
12
const testURL = 'http://localhost:3000/js/tests/index.html?hidepassed'

13
14
jsUnitSaucelabs.start([
  ['Windows 8', 'internet explorer', '10']
15
], testURL, 'qunit', (error, success) => {
16
  if (typeof success !== 'undefined') {
17
    const taskIds = success['js tests']
18
19
20
21
    if (!taskIds || !taskIds.length) {
      throw new Error('Error starting tests through SauceLabs API')
    }

22
    const waitingCallback = (error, success) => {
23
24
25
26
27
28
29
30
31
      if (error) {
        console.error(error)
        return
      }

      if (typeof success !== 'undefined') {
        if (!success.completed) {
          jsUnitSaucelabs.getStatus(taskIds[0], waitingCallback)
        } else {
32
33
          const test = success['js tests'][0]
          let passed = false
34
35
36
          if (test.result !== null) {
            passed = test.result.total === test.result.passed
          }
37
38
39
40
          console.log(`Tested ${testURL}`)
          console.log(`Platform: ${test.platform.join(',')}`)
          console.log(`Passed: ${passed.toString()}`)
          console.log(`Url ${test.url}`)
41
42
43
44
        }
      }
    }

45
    taskIds.forEach((id) => {
46
47
48
49
      jsUnitSaucelabs.getStatus(id, waitingCallback)
    })
  }
})