forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecord-integration.js
More file actions
67 lines (57 loc) · 1.94 KB
/
record-integration.js
File metadata and controls
67 lines (57 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const { Console } = require('console')
const { readdir, readFile } = require('mz/fs')
const shelljs = require('shelljs')
const { compressRecordings, deleteRecordings } = require('./utils')
const recordSnapshot = grepValue =>
new Promise((resolve, reject) => {
shelljs.exec(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
`POLLYJS_MODE=record SOURCEGRAPH_BASE_URL=https://sourcegraph.com yarn run-integration --grep='${grepValue}'`,
(code, stdout, stderr) => {
console.log(`stdout: ${stdout}`)
console.log(`stderr: ${stderr}`)
if (code === 0) {
resolve()
}
const error = new Error()
error.code = code
reject(error)
}
)
})
const recordTests = async () => {
// 1. Record by --grep args
const args = process.argv.slice(2)
for (let index = 0; index < args.length; ++index) {
if (args[index] === '--grep' && !!args[index + 1]) {
await recordSnapshot(args[index + 1])
return
}
}
// 2. Record all tests
const fileNames = await readdir('./src/integration')
const testFileNames = fileNames.filter(fileName => fileName.endsWith('.test.ts'))
const testFiles = await Promise.all(
testFileNames.map(testFileName => readFile(`./src/integration/${testFileName}`, 'utf-8'))
)
const testNames = testFiles
// Ignore template strings for now. If we have lots of tests with parameterized test names, we
// can use heuristics to still be able to run them.
.flatMap(testFile => testFile.split('\n').map(line => line.match(/\bit\((["'])(.*)\1/)))
.filter(Boolean)
.map(matchArray => matchArray[2])
for (const testName of testNames) {
await recordSnapshot(testName)
}
}
// eslint-disable-next-line no-void
void (async () => {
try {
await recordTests()
await compressRecordings()
process.exit(0)
} catch (error) {
await deleteRecordings()
process.exit(error.code ?? 1)
}
})()