This commit is contained in:
2024-05-17 18:02:49 +08:00
parent 8407d51fb6
commit b5264dc222
4056 changed files with 308094 additions and 41932 deletions

View File

@@ -0,0 +1,13 @@
#!/usr/local/bin/node
var username = 'storejs'
var password = new Buffer('ZjhjMzUyNjgtNzc2ZC00ZjlkLWEwNWUtN2FkM2Q0ZDgyNzk5', 'base64').toString('utf8')
var saucelabs = require('./saucelabs')
saucelabs.setAuth(username, password)
saucelabs.listAllSupportedPlatforms(function(err, res) {
if (err) { throw err }
for (var i=0; i<res.length; i++) {
console.log(res[i])
}
})

59
node_modules/store/scripts/saucelabs/saucelabs-api.js generated vendored Normal file
View File

@@ -0,0 +1,59 @@
var request = require('request')
module.exports = {
setAuth: setAuth,
get: get,
post: post
}
var auth = {
user: null,
password: null,
}
function setAuth(saucelabsUsername, saucelabsToken) {
auth.user = saucelabsUsername
auth.password = saucelabsToken
}
function get(path, callback) {
var params = {
url: 'https://saucelabs.com/rest/v1/'+path,
auth: auth
}
// console.log("REQ", params)
request.get(params, function(err, res, body) {
if (err) {
throw err
}
if (res.statusCode != 200) {
console.log(params)
throw new Error('Non-200 status code: '+body)
}
// console.log("RES", params.url, body)
callback(JSON.parse(body))
})
}
function post(path, data, callback) {
var params = {
url: 'https://saucelabs.com/rest/v1/'+auth.user+'/'+path,
auth: { user:auth.user, password:auth.password },
json: data
}
// console.log("REQ", params)
request.post(params, function(err, res, body) {
if (err) {
throw err
}
if (res.statusCode != 200) {
throw new Error('Non-200 status code: '+body)
}
// console.log("RES", params.url, body)
callback(body)
})
}
// https://wiki.saucelabs.com/display/DOCS/JavaScript+Unit+Testing+Methods#JavaScriptUnitTestingMethods-StartJSUnitTests

View File

@@ -0,0 +1,71 @@
// See https://wiki.saucelabs.com/display/DOCS/Platform+Configurator?_ga=1.24059122.934400320.1451142104#/
// See ./list-saucelabs-platforms.js
var CURRENT_VERSION = ''
var BETA_VERSION = 'beta'
var CHROME_VERSIONS = ['31', CURRENT_VERSION]
var FIREFOX_VERSIONS = ['4', '5', '6', '7', CURRENT_VERSION]
var OPERA_VERSIONS = ['11', '12']
var platforms = module.exports = {
// Fast trial runs
//////////////////
fast: {
'Linux': { 'chrome': [CURRENT_VERSION] },
},
// Common browser sets
//////////////////////
ie: {
'Windows XP': { 'internet explorer': ['6', '7', '8'] },
'Windows 7': { 'internet explorer': ['9'] },
'Windows 8': { 'internet explorer': ['10'] },
'Windows 10': { 'internet explorer': ['11'], 'microsoftedge': [CURRENT_VERSION] },
},
safari: {
'Windows 7': { 'safari': ['5'] },
'OS X 10.8': { 'safari': ['6'] },
'OS X 10.9': { 'safari': ['7'] },
'OS X 10.10': { 'safari': ['8'] },
'OS X 10.11': { 'safari': ['9'] },
'OS X 10.12': { 'safari': ['10'] },
},
firefox: {
'Linux': { 'firefox': ['40'] },
'Windows XP': { 'firefox': ['4', '5'] },
'Windows 10': { 'firefox': [CURRENT_VERSION] },
'Mac 10.12': { 'firefox': [CURRENT_VERSION] },
},
android: {
'Linux': { 'android': ['4.4','5.0','5.1'] },
},
ios: {
'Mac 10.10': {
'ipad': ['8.4'],
'iphone':['8.4'],
},
'Mac 10.11': {
'ipad': ['9.3', '10.0'],
'iphone':['9.3', '10.0'],
}
},
chrome: {
'Mac 10.12': { 'chrome':['27', CURRENT_VERSION] },
'Windows 10': { 'chrome':['26', CURRENT_VERSION] },
},
opera: {
'Windows XP': { 'opera':'11' },
'Linux': { 'opera':'12' },
},
// Individual browser versions
//////////////////////////////
ie6: { 'Windows XP': { 'internet explorer': ['6'] } },
ie7: { 'Windows XP': { 'internet explorer': ['7'] } },
ie8: { 'Windows XP': { 'internet explorer': ['8'] } },
ie9: { 'Windows 7': { 'internet explorer': ['9'] } },
ie10:{ 'Windows 8': { 'internet explorer': ['10'] } },
ie11:{ 'Windows 10': { 'internet explorer': ['11'] } },
firefox4: { 'Windows XP': { 'firefox': ['4'] } },
firefox5: { 'Windows XP': { 'firefox': ['5'] } },
}

154
node_modules/store/scripts/saucelabs/saucelabs.js generated vendored Normal file
View File

@@ -0,0 +1,154 @@
var _ = require('lodash')
var api = require('./saucelabs-api')
module.exports = {
setAuth: api.setAuth,
listAllSupportedPlatforms: listAllSupportedPlatforms,
runTest: runTest,
platformSets: require('./saucelabs-platformSets'),
}
function listAllSupportedPlatforms(callback) {
api.get('info/platforms/webdriver', function(platformsInfo) {
var platforms = _.map(platformsInfo, function(info) {
return [info['os'], info['api_name'], info['short_version']]
})
platforms.sort(function(a, b) {
a = a.join('-')
b = b.join('-')
return a < b ? -1 : b < a ? 1 : 0
})
callback(null, filterUniquePlatforms(platforms))
})
}
function runTests(url, platforms, callback) {
var params = { maxDuration:1800, url:url, platforms:platforms, framework:'custom', recordVideo:false, recordScreenshots:false, recordLogs:true }
api.post('js-tests', params, callback)
}
function getPlatformId(platform) {
return platform.join('-')
.replace('OS X', 'Mac')
.replace('Windows XP', 'Windows 2003')
.replace('Windows 7', 'Windows 2008')
.replace('Windows 8', 'Windows 2012')
}
function filterUniquePlatforms(platforms) {
var seen = {}
return _.filter(platforms, function(platform) {
var platformId = getPlatformId(platform)
if (seen[platformId]) { return false }
seen[platformId] = true
return true
})
}
function runTest(url, platformSets, callback) {
getPlatformsArg(platformSets, function(platforms) {
var runTestsRes
runTests(url, platforms, function(res) {
runTestsRes = res
loopCheckStatus()
})
function loopCheckStatus() {
getTestsStatus(runTestsRes, function(res) {
var pending = []
var running = []
var passed = []
var failed = []
_.each(res['js tests'], function(test) {
var status = getTestStatus(test)
if (status == PENDING) { pending.push(test) }
else if (status == PASSED) { passed.push(test) }
else if (status == RUNNING) { running.push(test) }
else if (status == FAILED) { failed.push(test) }
else { throw new Error('Bad status') }
})
_.each(_.flatten([passed, pending, running, failed]), function(test) {
console.log(getTestStatus(test), test.id, test.platform, test.status || 'test finished')
})
if (pending.length == 0 && running.length == 0) {
console.log("Test suite completed")
callback(checkTestResults(res))
} else if (res.completed) {
throw new Error('No pending tests, but res.completed == true')
} else {
var delay = 5
console.log("Check again in", delay, "seconds")
setTimeout(loopCheckStatus, delay * 1000)
}
})
}
})
}
function getPlatformsArg(platformSets, callback) {
listAllSupportedPlatforms(function(err, supportedPlatforms) {
if (err) { return callback(err) }
var allSupportedPlatforms = {}
_.each(supportedPlatforms, function(platform) {
allSupportedPlatforms[getPlatformId(platform)] = true
})
var platforms = _.flatten(_.flatten(_.flatten(
_.map(platformSets, function(platformSet) {
return _.map(platformSet, function(browserSpecs, osName) {
return _.map(browserSpecs, function(browserVersions, browserName) {
if (typeof browserVersions == 'string') {
browserVersions = [browserVersions]
}
return _.map(browserVersions, function(browserVersion) {
return [osName, browserName, browserVersion]
})
})
})
})
)))
_.each(platforms, function(platform) {
if (!platform[2]) { return } // Don't sanity-check CURRENT_VERSION
var platformId = getPlatformId(platform)
if (!allSupportedPlatforms[platformId]) {
throw new Error('Unsupported platform: '+platform.join(', ')+' ('+platformId+')')
}
})
callback(filterUniquePlatforms(platforms))
})
}
function getTestsStatus(runTestsRes, callback) {
api.post('js-tests/status', { 'js tests':runTestsRes['js tests'] }, function(res) {
callback(res)
})
}
var PENDING = 'PENDING'
var RUNNING = 'RUNNING'
var FAILED = 'FAILED '
var PASSED = 'PASSED '
function getTestStatus(test) {
if (test.status == 'test error') {
return FAILED
} else if (test.status == 'test session in progress') {
return RUNNING
} else if (test.result) {
return (test.result.failed ? FAILED : PASSED)
} else {
return PENDING
}
}
function checkTestResults(res) {
var failed = 0
_.each(res['js tests'], function(test) {
console.log(getTestStatus(test), test.id, test.status, test.platform, test.url)
if (getTestStatus(test) == FAILED) {
failed += 1
console.log('Result:', test.result)
}
})
return (failed ? failed+' tests failed' : null)
}

73
node_modules/store/scripts/saucelabs/tunnel.js generated vendored Normal file
View File

@@ -0,0 +1,73 @@
var http = require('http')
var fs = require('fs')
var ngrok = require('ngrok')
module.exports = {
setup: setup,
}
function setup(port, callback) {
startServer(port, function(err) {
if (err) { return callback(err) }
console.log("Creating tunnel - this might take a few seconds")
startTunnel(port, function(err, url) {
if (err) { return callback(err) }
console.log("tunnel up at", url)
callback(null, url)
})
})
}
function startTunnel(port, callback) {
// return callback(null, 'https://07f51ed4.ngrok.io')
var authtoken = new Buffer('NTJuelB1dUpVSDNycDNjZ3pldHVEXzVnWlNObkpuMlFaR013WjZ0eUZUQw==', 'base64').toString('utf8')
ngrok.connect({ addr:port, subdomain:'storejs-test', authtoken:authtoken }, function(err, url) {
if (err) { return callback(err) }
url = url.replace('https:', 'http:')
callback(null, url)
})
}
function startServer(port, callback) {
var server = http.createServer(handleReq)
server.listen(port)
server.on('listening', function(err) {
if (err) { return callback(err) }
console.log('local server listening on http://localhost:'+port+'/')
callback()
})
function handleReq(req, res) {
console.log(req.url)
if (req.url == '/') {
res.writeHead(200, { 'Content-Type':'text/html' })
res.end(testRunnerHTML)
} else if (req.url == '/store.tests.min.js') {
var headers = {
'Content-Type':'application/javascript',
'Cache-Control': 'no-cache, no-store, must-revalidate',
'Pragma': 'no-cache',
'Expires': '0'
}
res.writeHead(200, headers)
fs.createReadStream(__dirname+'/../../dist/store.tests.min.js').pipe(res)
} else {
res.writeHead(404)
res.end('Not found')
}
}
var testRunnerHTML = `
<!doctype html>
<head>
<title>store.js test runner</title>
</head>
<body>
<h1>store.js test runner</h1>
<script src="/store.tests.min.js"></script>
</body>
</html>
`.replace(/\n\t\t/g, '\n').replace(/^\n/, '')
}