forked from http-tests/cache-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.mjs
More file actions
47 lines (43 loc) · 1.32 KB
/
cli.mjs
File metadata and controls
47 lines (43 loc) · 1.32 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
import { runTests, getResults } from './client/runner.mjs'
import * as display from './lib/display.mjs'
import { GREEN, NC } from './lib/defines.mjs'
import fetch from 'node-fetch-with-proxy'
import tests from './tests/index.mjs'
import surrogate from './tests/surrogate-control.mjs'
tests.push(surrogate)
const baseUrl = process.env.npm_config_base || process.env.npm_package_config_base
const testId = process.env.npm_config_id || process.env.npm_package_config_id
let testsToRun
if (testId !== '') {
console.log(`Running ${testId}`)
tests.forEach(suite => {
suite.tests.forEach(test => {
if (test.id === testId) {
test.dump = true
testsToRun = [{
name: suite.name,
id: suite.id,
description: suite.description,
tests: [test]
}]
}
})
})
} else {
testsToRun = tests
}
runTests(testsToRun, fetch, false, baseUrl)
.then(() => {
if (testId !== '') {
console.log(`${GREEN}==== Results${NC}`)
const result = getResults()
const resultSymbol = display.determineTestResult(tests, testId, result, false)
const resultDetails = result[testId][1] || ''
console.log(`${resultSymbol[2]} - ${resultDetails}`)
} else {
console.log(JSON.stringify(getResults(), null, 2))
}
})
.catch(err => {
console.error(err)
})