presidium 4.0.1 → 4.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DynamoDBGlobalSecondaryIndex.js +3 -3
- package/DynamoDBStream.js +3 -3
- package/DynamoDBTable.js +3 -3
- package/ECR.js +3 -3
- package/GoogleChromeForTesting.js +25 -83
- package/S3Bucket.js +4 -12
- package/SecretsManager.js +62 -45
- package/internal/getAbsoluteFilePath.js +17 -0
- package/internal/getAbsoluteFilePath.test.js +19 -0
- package/internal/getChromeBinaryOrExecutableFilePath.js +15 -0
- package/internal/getChromeBinaryOrExecutableFilePath.test.js +17 -0
- package/internal/getChromeUrl.js +20 -0
- package/internal/getChromeUrl.test.js +22 -0
- package/internal/getChromeVersions.js +19 -0
- package/internal/getPlatform.js +22 -0
- package/internal/getPlatform.test.js +33 -0
- package/package.json +1 -1
|
@@ -98,9 +98,9 @@ class DynamoDBGlobalSecondaryIndex {
|
|
|
98
98
|
this.key = options.key
|
|
99
99
|
this.name = DynamoDBIndexname(this.key)
|
|
100
100
|
|
|
101
|
-
this.accessKeyId = options.accessKeyId
|
|
102
|
-
this.secretAccessKey = options.secretAccessKey
|
|
103
|
-
this.region = options.region
|
|
101
|
+
this.accessKeyId = options.accessKeyId
|
|
102
|
+
this.secretAccessKey = options.secretAccessKey
|
|
103
|
+
this.region = options.region
|
|
104
104
|
this.apiVersion = '2012-08-10'
|
|
105
105
|
|
|
106
106
|
this.endpoint = `dynamodb.${this.region}.amazonaws.com`
|
package/DynamoDBStream.js
CHANGED
|
@@ -116,9 +116,9 @@ class DynamoDBStream {
|
|
|
116
116
|
this.ListStreamsLimit = options.ListStreamsLimit ?? 100
|
|
117
117
|
this.JSON = options.JSON ?? false
|
|
118
118
|
|
|
119
|
-
this.accessKeyId = options.accessKeyId
|
|
120
|
-
this.secretAccessKey = options.secretAccessKey
|
|
121
|
-
this.region = options.region
|
|
119
|
+
this.accessKeyId = options.accessKeyId
|
|
120
|
+
this.secretAccessKey = options.secretAccessKey
|
|
121
|
+
this.region = options.region
|
|
122
122
|
this.apiVersion = '2012-08-10'
|
|
123
123
|
|
|
124
124
|
this.endpoint = `dynamodb.${this.region}.amazonaws.com`
|
package/DynamoDBTable.js
CHANGED
|
@@ -94,9 +94,9 @@ class DynamoDBTable {
|
|
|
94
94
|
this.name = options.name
|
|
95
95
|
this.key = options.key
|
|
96
96
|
|
|
97
|
-
this.accessKeyId = options.accessKeyId
|
|
98
|
-
this.secretAccessKey = options.secretAccessKey
|
|
99
|
-
this.region = options.region
|
|
97
|
+
this.accessKeyId = options.accessKeyId
|
|
98
|
+
this.secretAccessKey = options.secretAccessKey
|
|
99
|
+
this.region = options.region
|
|
100
100
|
this.apiVersion = '2012-08-10'
|
|
101
101
|
|
|
102
102
|
this.endpoint = `dynamodb.${this.region}.amazonaws.com`
|
package/ECR.js
CHANGED
|
@@ -46,9 +46,9 @@ const retryHTTPRequest = require('./internal/retryHTTPRequest')
|
|
|
46
46
|
*/
|
|
47
47
|
class ECR {
|
|
48
48
|
constructor(options) {
|
|
49
|
-
this.accessKeyId = options.accessKeyId
|
|
50
|
-
this.secretAccessKey = options.secretAccessKey
|
|
51
|
-
this.region = options.region
|
|
49
|
+
this.accessKeyId = options.accessKeyId
|
|
50
|
+
this.secretAccessKey = options.secretAccessKey
|
|
51
|
+
this.region = options.region
|
|
52
52
|
this.apiVersion = '2015-09-21'
|
|
53
53
|
|
|
54
54
|
this.endpoint = `ecr.${this.region}.amazonaws.com`
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
const https = require('https')
|
|
9
|
+
const EventEmitter = require('events')
|
|
9
10
|
const os = require('os')
|
|
10
11
|
const fs = require('fs')
|
|
11
12
|
const path = require('path')
|
|
@@ -15,15 +16,12 @@ const extract = require('extract-zip')
|
|
|
15
16
|
const HTTP = require('./HTTP')
|
|
16
17
|
const XML = require('./XML')
|
|
17
18
|
const Readable = require('./Readable')
|
|
19
|
+
const getPlatform = require('./internal/getPlatform')
|
|
18
20
|
const walk = require('./internal/walk')
|
|
19
21
|
const sleep = require('./internal/sleep')
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const response = await http.GET('https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json')
|
|
24
|
-
const data = await Readable.JSON(response)
|
|
25
|
-
return data
|
|
26
|
-
}
|
|
22
|
+
const getChromeUrl = require('./internal/getChromeUrl')
|
|
23
|
+
const getAbsoluteFilePath = require('./internal/getAbsoluteFilePath')
|
|
24
|
+
const getChromeBinaryOrExecutableFilePath = require('./internal/getChromeBinaryOrExecutableFilePath')
|
|
27
25
|
|
|
28
26
|
function updateConsoleLog(message, platform) {
|
|
29
27
|
readline.cursorTo(process.stdout, 0, undefined);
|
|
@@ -31,66 +29,16 @@ function updateConsoleLog(message, platform) {
|
|
|
31
29
|
process.stdout.write(message);
|
|
32
30
|
}
|
|
33
31
|
|
|
34
|
-
function
|
|
35
|
-
let platform = os.platform()
|
|
36
|
-
if (platform == 'darwin') {
|
|
37
|
-
platform = 'mac'
|
|
38
|
-
}
|
|
39
|
-
const arch = os.arch()
|
|
40
|
-
|
|
41
|
-
if (platform == 'mac') {
|
|
42
|
-
platform = `${platform}-${arch}`
|
|
43
|
-
}
|
|
44
|
-
else if (platform == 'win32') {
|
|
45
|
-
platform = `win${arch.slice(1)}`
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
platform = `${platform}${arch.slice(1)}`
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return platform
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async function getChromeUrl() {
|
|
32
|
+
async function installChrome() {
|
|
55
33
|
const platform = getPlatform()
|
|
34
|
+
const url = await getChromeUrl.call(this, platform)
|
|
56
35
|
|
|
57
|
-
let url
|
|
58
|
-
|
|
59
|
-
const chromeVersions = await getChromeVersions()
|
|
60
|
-
const channel = `${this.chromeVersion[0].toUpperCase()}${this.chromeVersion.slice(1)}`
|
|
61
|
-
const chromeVersionNumber = chromeVersions.channels[channel].version
|
|
62
|
-
url = `https://storage.googleapis.com/chrome-for-testing-public/${chromeVersionNumber}/${platform}/chrome-${platform}.zip`
|
|
63
|
-
} else {
|
|
64
|
-
const chromeVersionNumber = this.chromeVersion
|
|
65
|
-
url = `https://storage.googleapis.com/chrome-for-testing-public/${chromeVersionNumber}/${platform}/chrome-${platform}.zip`
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return url
|
|
69
|
-
}
|
|
36
|
+
let filepath = `${this.chromeDir}/${url.replace('https://storage.googleapis.com/chrome-for-testing-public/', '')}`
|
|
37
|
+
filepath = getAbsoluteFilePath(filepath, platform)
|
|
70
38
|
|
|
71
|
-
async function installChrome() {
|
|
72
|
-
const platform = getPlatform()
|
|
73
39
|
const delimiter = platform.startsWith('win') ? '\\' : '/'
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
let filepath = `${this.chromeDir}${delimiter}${url.replace('https://storage.googleapis.com/chrome-for-testing-public/', '')}`
|
|
77
|
-
if (platform.startsWith('win')) {
|
|
78
|
-
filepath = filepath.replace(/\//g, '\\')
|
|
79
|
-
if (!filepath.startsWith(`${__dirname[0]}:`)) {
|
|
80
|
-
filepath = path.join(process.cwd(), filepath)
|
|
81
|
-
}
|
|
82
|
-
} else if (!filepath.startsWith('/')) {
|
|
83
|
-
filepath = path.join(process.cwd(), filepath)
|
|
84
|
-
}
|
|
40
|
+
const parentDir = `${filepath.split(delimiter).slice(0, -1).join(delimiter)}`
|
|
85
41
|
|
|
86
|
-
let parentDir = `${filepath.split(delimiter).slice(0, -1).join(delimiter)}`
|
|
87
|
-
if (platform.startsWith('win')) {
|
|
88
|
-
if (!filepath.startsWith(`${__dirname[0]}:`)) {
|
|
89
|
-
parentDir = path.join(process.cwd(), parentDir)
|
|
90
|
-
}
|
|
91
|
-
} else if (!parentDir.startsWith('/')) {
|
|
92
|
-
parentDir = path.join(process.cwd(), parentDir)
|
|
93
|
-
}
|
|
94
42
|
await fs.promises.mkdir(parentDir, { recursive: true })
|
|
95
43
|
|
|
96
44
|
const http = new HTTP()
|
|
@@ -113,27 +61,26 @@ async function installChrome() {
|
|
|
113
61
|
fileStream.write(chunk)
|
|
114
62
|
})
|
|
115
63
|
|
|
64
|
+
response.on('end', () => {
|
|
65
|
+
fileStream.end()
|
|
66
|
+
})
|
|
67
|
+
|
|
116
68
|
let resolve
|
|
117
69
|
const promise = new Promise(_resolve => {
|
|
118
70
|
resolve = _resolve
|
|
119
71
|
})
|
|
120
|
-
|
|
72
|
+
fileStream.on('finish', () => {
|
|
121
73
|
resolve()
|
|
122
74
|
})
|
|
123
75
|
await promise
|
|
124
76
|
|
|
125
77
|
console.log('Extracting', filepath)
|
|
126
|
-
|
|
127
|
-
await extract(filepath, { dir: parentDir })
|
|
128
|
-
} catch (_error) {
|
|
129
|
-
await sleep(1000)
|
|
130
|
-
await extract(filepath, { dir: parentDir })
|
|
131
|
-
}
|
|
78
|
+
await extract(filepath, { dir: parentDir })
|
|
132
79
|
}
|
|
133
80
|
|
|
134
81
|
async function getChromeFilepath() {
|
|
135
82
|
const platform = getPlatform()
|
|
136
|
-
const url = await getChromeUrl.call(this)
|
|
83
|
+
const url = await getChromeUrl.call(this, platform)
|
|
137
84
|
const filepath = `${this.chromeDir}/${url.replace('https://storage.googleapis.com/chrome-for-testing-public/', '')}`
|
|
138
85
|
const parentDir = `${filepath.split('/').slice(0, -1).join('/')}`
|
|
139
86
|
|
|
@@ -144,16 +91,13 @@ async function getChromeFilepath() {
|
|
|
144
91
|
}
|
|
145
92
|
|
|
146
93
|
for await (const filepath of walk(parentDir)) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return filepath
|
|
152
|
-
}
|
|
153
|
-
if (platform.startsWith('win') && filepath.endsWith('chrome.exe')) {
|
|
154
|
-
return filepath
|
|
94
|
+
const chromeBinaryOrExecutableFilePath =
|
|
95
|
+
getChromeBinaryOrExecutableFilePath(filepath, platform)
|
|
96
|
+
if (chromeBinaryOrExecutableFilePath) {
|
|
97
|
+
return chromeBinaryOrExecutableFilePath
|
|
155
98
|
}
|
|
156
99
|
}
|
|
100
|
+
throw new Error('chrome binary or executable not found.')
|
|
157
101
|
} catch (error) {
|
|
158
102
|
if (error.code == 'ENOENT') {
|
|
159
103
|
await installChrome.call(this)
|
|
@@ -162,8 +106,6 @@ async function getChromeFilepath() {
|
|
|
162
106
|
}
|
|
163
107
|
throw error
|
|
164
108
|
}
|
|
165
|
-
|
|
166
|
-
throw new Error('unable to find Google Chrome for Testing executable.')
|
|
167
109
|
}
|
|
168
110
|
|
|
169
111
|
/**
|
|
@@ -220,8 +162,9 @@ async function getChromeFilepath() {
|
|
|
220
162
|
* sudo apt-get update && sudo apt-get install -y libcairo2 libpango-1.0-0 libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 libatspi2.0-0 libcups2 libdrm-dev libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm-dev libasound2-dev
|
|
221
163
|
* ```
|
|
222
164
|
*/
|
|
223
|
-
class GoogleChromeForTesting {
|
|
165
|
+
class GoogleChromeForTesting extends EventEmitter {
|
|
224
166
|
constructor(options = {}) {
|
|
167
|
+
super()
|
|
225
168
|
this.chromeVersion = options.chromeVersion ?? 'stable'
|
|
226
169
|
this.chromeDir = options.chromeDir ?? 'google-chrome-for-testing'
|
|
227
170
|
this.remoteDebuggingPort = options.remoteDebuggingPort ?? 9222
|
|
@@ -295,8 +238,7 @@ class GoogleChromeForTesting {
|
|
|
295
238
|
})
|
|
296
239
|
|
|
297
240
|
cmd.on('error', error => {
|
|
298
|
-
|
|
299
|
-
process.exit(1)
|
|
241
|
+
this.emit('error', error)
|
|
300
242
|
})
|
|
301
243
|
|
|
302
244
|
cmd.on('exit', code => {
|
package/S3Bucket.js
CHANGED
|
@@ -90,9 +90,9 @@ class S3Bucket {
|
|
|
90
90
|
constructor(options) {
|
|
91
91
|
this.name = options.name
|
|
92
92
|
|
|
93
|
-
this.accessKeyId = options.accessKeyId
|
|
94
|
-
this.secretAccessKey = options.secretAccessKey
|
|
95
|
-
this.region = options.region
|
|
93
|
+
this.accessKeyId = options.accessKeyId
|
|
94
|
+
this.secretAccessKey = options.secretAccessKey
|
|
95
|
+
this.region = options.region
|
|
96
96
|
this.apiVersion = '2012-08-10'
|
|
97
97
|
|
|
98
98
|
this.host0 = 's3.amazonaws.com'
|
|
@@ -2243,15 +2243,9 @@ class S3Bucket {
|
|
|
2243
2243
|
}
|
|
2244
2244
|
|
|
2245
2245
|
if (response1.Errors.length > 0) {
|
|
2246
|
-
const errors = response1.Errors.map(
|
|
2247
|
-
if (VersionId) {
|
|
2248
|
-
return new Error(`${Key} (VersionId ${VersionId}): ${Code}: ${Message}`)
|
|
2249
|
-
}
|
|
2250
|
-
return new Error(`${Key}: ${Code}: ${Message}`)
|
|
2251
|
-
})
|
|
2246
|
+
const errors = response1.Errors.map(createS3DeleteObjectError)
|
|
2252
2247
|
throw new AggregateError(errors)
|
|
2253
2248
|
}
|
|
2254
|
-
|
|
2255
2249
|
}
|
|
2256
2250
|
|
|
2257
2251
|
let versions = await this.listObjectVersions({ MaxKeys: BatchSize }).then(get('Versions'))
|
|
@@ -2272,7 +2266,6 @@ class S3Bucket {
|
|
|
2272
2266
|
const errors = response1.Errors.map(createS3DeleteObjectError)
|
|
2273
2267
|
throw new AggregateError(errors)
|
|
2274
2268
|
}
|
|
2275
|
-
|
|
2276
2269
|
}
|
|
2277
2270
|
|
|
2278
2271
|
let deleteMarkers = await this.listObjectVersions({ MaxKeys: BatchSize }).then(get('DeleteMarkers'))
|
|
@@ -2293,7 +2286,6 @@ class S3Bucket {
|
|
|
2293
2286
|
const errors = response1.Errors.map(createS3DeleteObjectError)
|
|
2294
2287
|
throw new AggregateError(errors)
|
|
2295
2288
|
}
|
|
2296
|
-
|
|
2297
2289
|
}
|
|
2298
2290
|
|
|
2299
2291
|
return response
|
package/SecretsManager.js
CHANGED
|
@@ -16,6 +16,7 @@ const Readable = require('./Readable')
|
|
|
16
16
|
const handleAwsResponse = require('./internal/handleAwsResponse')
|
|
17
17
|
const retryableErrorNames = require('./internal/retryableErrorNames')
|
|
18
18
|
const retryHTTPRequest = require('./internal/retryHTTPRequest')
|
|
19
|
+
const sleep = require('./internal/sleep')
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* @name SecretsManager
|
|
@@ -49,9 +50,9 @@ const retryHTTPRequest = require('./internal/retryHTTPRequest')
|
|
|
49
50
|
*/
|
|
50
51
|
class SecretsManager {
|
|
51
52
|
constructor(options) {
|
|
52
|
-
this.accessKeyId = options.accessKeyId
|
|
53
|
-
this.secretAccessKey = options.secretAccessKey
|
|
54
|
-
this.region = options.region
|
|
53
|
+
this.accessKeyId = options.accessKeyId
|
|
54
|
+
this.secretAccessKey = options.secretAccessKey
|
|
55
|
+
this.region = options.region
|
|
55
56
|
this.apiVersion = '2017-10-17'
|
|
56
57
|
|
|
57
58
|
this.endpoint = `secretsmanager.${this.region}.amazonaws.com`
|
|
@@ -118,6 +119,53 @@ class SecretsManager {
|
|
|
118
119
|
return retryHTTPRequest(this.http, method, url, { headers, body: payload })
|
|
119
120
|
}
|
|
120
121
|
|
|
122
|
+
// _createSecret(name string, secretString string) -> Promise<{
|
|
123
|
+
// ARN: string,
|
|
124
|
+
// Name: string,
|
|
125
|
+
// VersionId: string,
|
|
126
|
+
// }>
|
|
127
|
+
async _createSecret(name, secretString) {
|
|
128
|
+
const payload = JSON.stringify({
|
|
129
|
+
ClientRequestToken: crypto.randomUUID(),
|
|
130
|
+
Name: name,
|
|
131
|
+
SecretString: secretString,
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
const response = await this._awsRequest('POST', '/', 'CreateSecret', payload)
|
|
135
|
+
|
|
136
|
+
if (response.ok) {
|
|
137
|
+
const data = await Readable.JSON(response)
|
|
138
|
+
return data
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
throw new AwsError(await Readable.Text(response), response.status)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// _createSecret(name string, secretString string) -> Promise<{
|
|
145
|
+
// ARN: string,
|
|
146
|
+
// Name: string,
|
|
147
|
+
// VersionId: string,
|
|
148
|
+
// }>
|
|
149
|
+
async _updateSecret(name, secretString) {
|
|
150
|
+
const secret = await this.getSecret(name)
|
|
151
|
+
|
|
152
|
+
const payload = JSON.stringify({
|
|
153
|
+
ClientRequestToken: crypto.randomUUID(),
|
|
154
|
+
SecretId: secret.ARN,
|
|
155
|
+
SecretString: secretString,
|
|
156
|
+
})
|
|
157
|
+
const updateSecretResponse =
|
|
158
|
+
await this._awsRequest('POST', '/', 'UpdateSecret', payload)
|
|
159
|
+
|
|
160
|
+
return handleAwsResponse.call(
|
|
161
|
+
this,
|
|
162
|
+
updateSecretResponse,
|
|
163
|
+
this.putSecret,
|
|
164
|
+
name,
|
|
165
|
+
secretString
|
|
166
|
+
)
|
|
167
|
+
}
|
|
168
|
+
|
|
121
169
|
/**
|
|
122
170
|
* @name putSecret
|
|
123
171
|
*
|
|
@@ -152,50 +200,19 @@ class SecretsManager {
|
|
|
152
200
|
* ```
|
|
153
201
|
*/
|
|
154
202
|
async putSecret(name, secretString) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
Name: name,
|
|
158
|
-
SecretString: secretString,
|
|
159
|
-
})
|
|
160
|
-
const createSecretResponse =
|
|
161
|
-
await this._awsRequest('POST', '/', 'CreateSecret', createSecretPayload)
|
|
162
|
-
|
|
163
|
-
if (createSecretResponse.ok) {
|
|
164
|
-
const data = await Readable.JSON(createSecretResponse)
|
|
203
|
+
try {
|
|
204
|
+
const data = await this._createSecret(name, secretString)
|
|
165
205
|
return data
|
|
206
|
+
} catch (error) {
|
|
207
|
+
if (error.name == 'ResourceExistsException') {
|
|
208
|
+
return this._updateSecret(name, secretString)
|
|
209
|
+
} else if (retryableErrorNames.includes(error.name)) {
|
|
210
|
+
await sleep(1000)
|
|
211
|
+
return this.putSecret.call(this, name, secretString)
|
|
212
|
+
} else {
|
|
213
|
+
throw error
|
|
214
|
+
}
|
|
166
215
|
}
|
|
167
|
-
|
|
168
|
-
const createSecretAwsError = new AwsError(
|
|
169
|
-
await Readable.Text(createSecretResponse),
|
|
170
|
-
createSecretResponse.status
|
|
171
|
-
)
|
|
172
|
-
|
|
173
|
-
if (createSecretAwsError.name == 'ResourceExistsException') {
|
|
174
|
-
// continue
|
|
175
|
-
} else if (retryableErrorNames.includes(createSecretAwsError.name)) {
|
|
176
|
-
await sleep(1000)
|
|
177
|
-
return putSecret.call(this, name, secretString)
|
|
178
|
-
} else {
|
|
179
|
-
throw createSecretAwsError
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const secret = await this.getSecret(name)
|
|
183
|
-
|
|
184
|
-
const updateSecretPayload = JSON.stringify({
|
|
185
|
-
ClientRequestToken: crypto.randomUUID(),
|
|
186
|
-
SecretId: secret.ARN,
|
|
187
|
-
SecretString: secretString,
|
|
188
|
-
})
|
|
189
|
-
const updateSecretResponse =
|
|
190
|
-
await this._awsRequest('POST', '/', 'UpdateSecret', updateSecretPayload)
|
|
191
|
-
|
|
192
|
-
return handleAwsResponse.call(
|
|
193
|
-
this,
|
|
194
|
-
updateSecretResponse,
|
|
195
|
-
this.putSecret,
|
|
196
|
-
name,
|
|
197
|
-
secretString
|
|
198
|
-
)
|
|
199
216
|
}
|
|
200
217
|
|
|
201
218
|
/**
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
|
|
3
|
+
// getAbsoluteFilePath(filepath string, platform string) -> absoluteFilePath string
|
|
4
|
+
function getAbsoluteFilePath(filepath, platform) {
|
|
5
|
+
if (platform.startsWith('win')) {
|
|
6
|
+
if (/^[A-Z]:/.test(filepath)) {
|
|
7
|
+
filepath = filepath.replace(/\//g, '\\')
|
|
8
|
+
} else {
|
|
9
|
+
filepath = path.join(process.cwd(), filepath).replace(/\//g, '\\')
|
|
10
|
+
}
|
|
11
|
+
} else if (!filepath.startsWith('/')) {
|
|
12
|
+
filepath = path.join(process.cwd(), filepath)
|
|
13
|
+
}
|
|
14
|
+
return filepath
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = getAbsoluteFilePath
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const Test = require('thunk-test')
|
|
2
|
+
const assert = require('assert')
|
|
3
|
+
const getAbsoluteFilePath = require('./getAbsoluteFilePath')
|
|
4
|
+
|
|
5
|
+
const test = new Test('getAbsoluteFilePath', getAbsoluteFilePath)
|
|
6
|
+
|
|
7
|
+
const cwd = process.cwd()
|
|
8
|
+
|
|
9
|
+
test.case('/test', 'linux64', '/test')
|
|
10
|
+
test.case('test', 'linux64', `${cwd}/test`)
|
|
11
|
+
test.case('/test', 'win64', `${cwd.replace(/\//g, '\\')}\\test`)
|
|
12
|
+
test.case('C:\\test', 'win64', 'C:\\test')
|
|
13
|
+
test.case('D:\\test', 'win64', 'D:\\test')
|
|
14
|
+
|
|
15
|
+
if (process.argv[1] == __filename) {
|
|
16
|
+
test()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = test
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// getChromeBinaryOrExecutableFilePath(filepath string, platform string) -> string
|
|
2
|
+
function getChromeBinaryOrExecutableFilePath(filepath, platform) {
|
|
3
|
+
if (platform.startsWith('mac') && filepath.endsWith('Google Chrome for Testing')) {
|
|
4
|
+
return filepath
|
|
5
|
+
}
|
|
6
|
+
if (platform.startsWith('linux') && filepath.endsWith('chrome')) {
|
|
7
|
+
return filepath
|
|
8
|
+
}
|
|
9
|
+
if (platform.startsWith('win') && filepath.endsWith('chrome.exe')) {
|
|
10
|
+
return filepath
|
|
11
|
+
}
|
|
12
|
+
return undefined
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports = getChromeBinaryOrExecutableFilePath
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const Test = require('thunk-test')
|
|
2
|
+
const getChromeBinaryOrExecutableFilePath = require('./getChromeBinaryOrExecutableFilePath.js')
|
|
3
|
+
|
|
4
|
+
const test = new Test('getChromeBinaryOrExecutableFilePath', getChromeBinaryOrExecutableFilePath)
|
|
5
|
+
|
|
6
|
+
test.case('/path/to/Google Chrome for Testing', 'mac-x64', '/path/to/Google Chrome for Testing')
|
|
7
|
+
test.case('/path/to/other', 'mac-x64', undefined)
|
|
8
|
+
test.case('/path/to/chrome', 'linux64', '/path/to/chrome')
|
|
9
|
+
test.case('/path/to/other', 'linux64', undefined)
|
|
10
|
+
test.case('C:\\path\\to\\chrome.exe', 'win64', 'C:\\path\\to\\chrome.exe')
|
|
11
|
+
test.case('C:\\path\\to\\other.exe', 'win64', undefined)
|
|
12
|
+
|
|
13
|
+
if (process.argv[1] == __filename) {
|
|
14
|
+
test()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = test
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const getChromeVersions = require('./getChromeVersions')
|
|
2
|
+
|
|
3
|
+
// getChromeUrl(platform string) -> chromeUrl string
|
|
4
|
+
async function getChromeUrl(platform) {
|
|
5
|
+
|
|
6
|
+
let url
|
|
7
|
+
if (['stable', 'beta', 'dev', 'canary'].includes(this.chromeVersion)) {
|
|
8
|
+
const chromeVersions = await getChromeVersions()
|
|
9
|
+
const channel = `${this.chromeVersion[0].toUpperCase()}${this.chromeVersion.slice(1)}`
|
|
10
|
+
const chromeVersionNumber = chromeVersions.channels[channel].version
|
|
11
|
+
url = `https://storage.googleapis.com/chrome-for-testing-public/${chromeVersionNumber}/${platform}/chrome-${platform}.zip`
|
|
12
|
+
} else {
|
|
13
|
+
const chromeVersionNumber = this.chromeVersion
|
|
14
|
+
url = `https://storage.googleapis.com/chrome-for-testing-public/${chromeVersionNumber}/${platform}/chrome-${platform}.zip`
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return url
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = getChromeUrl
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const Test = require('thunk-test')
|
|
2
|
+
const assert = require('assert')
|
|
3
|
+
const getChromeUrl = require('./getChromeUrl')
|
|
4
|
+
const getChromeVersions = require('./getChromeVersions')
|
|
5
|
+
|
|
6
|
+
const test = new Test('getChromeUrl', async function integration() {
|
|
7
|
+
const chromeVersions = await getChromeVersions()
|
|
8
|
+
|
|
9
|
+
const chromeVersionNumber = chromeVersions.channels.Stable.version
|
|
10
|
+
const platform = 'linux64'
|
|
11
|
+
const url = `https://storage.googleapis.com/chrome-for-testing-public/${chromeVersionNumber}/${platform}/chrome-${platform}.zip`
|
|
12
|
+
|
|
13
|
+
assert.equal(await getChromeUrl.call({ chromeVersion: 'stable' }, 'linux64'), url)
|
|
14
|
+
assert.equal(await getChromeUrl.call({ chromeVersion: chromeVersionNumber }, 'linux64'), url)
|
|
15
|
+
|
|
16
|
+
}).case()
|
|
17
|
+
|
|
18
|
+
if (process.argv[1] == __filename) {
|
|
19
|
+
test()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = test
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const HTTP = require('../HTTP')
|
|
2
|
+
const Readable = require('../Readable')
|
|
3
|
+
|
|
4
|
+
// getChromeVersions() -> Promise<{
|
|
5
|
+
// channels: {
|
|
6
|
+
// Stable: { version: string },
|
|
7
|
+
// Beta: { version: string },
|
|
8
|
+
// Dev: { version: string },
|
|
9
|
+
// Canary: { version: string },
|
|
10
|
+
// },
|
|
11
|
+
// }>
|
|
12
|
+
async function getChromeVersions() {
|
|
13
|
+
const http = new HTTP()
|
|
14
|
+
const response = await http.GET('https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json')
|
|
15
|
+
const data = await Readable.JSON(response)
|
|
16
|
+
return data
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = getChromeVersions
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const os = require('os')
|
|
2
|
+
|
|
3
|
+
// getPlatform() -> platform string
|
|
4
|
+
function getPlatform() {
|
|
5
|
+
let platform = os.platform()
|
|
6
|
+
if (platform == 'darwin') {
|
|
7
|
+
platform = 'mac'
|
|
8
|
+
}
|
|
9
|
+
const arch = os.arch()
|
|
10
|
+
|
|
11
|
+
if (platform == 'mac') {
|
|
12
|
+
platform = `${platform}-${arch}`
|
|
13
|
+
} else if (platform == 'win32') {
|
|
14
|
+
platform = `win${arch.slice(1)}`
|
|
15
|
+
} else {
|
|
16
|
+
platform = `${platform}${arch.slice(1)}`
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return platform
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = getPlatform
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const Test = require('thunk-test')
|
|
2
|
+
const assert = require('assert')
|
|
3
|
+
const getPlatform = require('./getPlatform')
|
|
4
|
+
|
|
5
|
+
const test = new Test('getPlatform', async function integration() {
|
|
6
|
+
const os = require('os')
|
|
7
|
+
|
|
8
|
+
const osPlatform = os.platform
|
|
9
|
+
const osArch = os.arch
|
|
10
|
+
|
|
11
|
+
os.platform = () => 'darwin'
|
|
12
|
+
os.arch = () => 'x64'
|
|
13
|
+
|
|
14
|
+
assert.equal(getPlatform(), 'mac-x64')
|
|
15
|
+
|
|
16
|
+
os.platform = () => 'win32'
|
|
17
|
+
|
|
18
|
+
assert.equal(getPlatform(), 'win64')
|
|
19
|
+
|
|
20
|
+
os.platform = () => 'linux'
|
|
21
|
+
|
|
22
|
+
assert.equal(getPlatform(), 'linux64')
|
|
23
|
+
|
|
24
|
+
os.platform = osPlatform
|
|
25
|
+
os.arch = osArch
|
|
26
|
+
|
|
27
|
+
}).case()
|
|
28
|
+
|
|
29
|
+
if (process.argv[1] == __filename) {
|
|
30
|
+
test()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = test
|