github
499 of 688 branches covered (72.53%)
Branch coverage included in aggregate %.
0 of 26 new or added lines in 2 files covered. (0.0%)
291 existing lines in 26 files now uncovered.2833 of 3610 relevant lines covered (78.48%)
28.87 hits per line
| 1 |
import fs from "fs/promises";
|
2✔ |
| 2 |
|
|
| 3 |
let containerEnv: boolean | undefined; |
2✔ |
| 4 |
|
|
| 5 |
export async function detectContainerEnv(): Promise<boolean> {
|
|
| 6 |
if (containerEnv !== undefined) {
|
|
| 7 |
return containerEnv;
|
17✔ |
| 8 |
} |
17✔ |
| 9 |
|
|
| 10 |
const detect = async function (): Promise<boolean> {
|
|
| 11 |
if (process.platform !== "linux") { |
|
| 12 |
return false; // we only support linux containers for now |
× |
|
UNCOV
13
|
} |
× |
| 14 |
|
|
| 15 |
if (process.env.container) {
|
|
| 16 |
return true; |
× |
|
UNCOV
17
|
} |
× |
| 18 |
|
|
| 19 |
const exists = await Promise.all(
|
30✔ |
| 20 |
["/.dockerenv", "/run/.containerenv", "/var/run/.containerenv"].map(async (file) => { |
|
| 21 |
try {
|
90✔ |
| 22 |
await fs.access(file); |
|
| 23 |
return true; |
× |
| 24 |
} catch {
|
90✔ |
| 25 |
return false; |
90✔ |
| 26 |
} |
90✔ |
| 27 |
}) |
30✔ |
| 28 |
); |
30✔ |
| 29 |
|
|
| 30 |
return exists.includes(true); |
30✔ |
| 31 |
}; |
30✔ |
| 32 |
|
|
| 33 |
containerEnv = await detect(); |
30✔ |
| 34 |
return containerEnv;
|
30✔ |
| 35 |
} |
30✔ |