-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy path_common.js
More file actions
75 lines (63 loc) · 1.77 KB
/
_common.js
File metadata and controls
75 lines (63 loc) · 1.77 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
68
69
70
71
72
73
74
75
/**
* @overview Provides common utilities for end-to-end tests.
* @license MIT
*/
import path from "node:path";
import process from "node:process";
import test from "ava";
import { isCI } from "ci-info";
import which from "which";
import { injectionStrings } from "../../src/testing.js";
import * as constants from "../_constants.js";
/**
* Get a list of strings to use as arguments in end-to-end tests.
*
* @returns {string[]} A list of test arguments.
*/
export function getTestArgs() {
return ["harmless", ...injectionStrings];
}
/**
* Get the AVA test function to use for the given shell.
*
* @param {string} shell The shell to run a test for.
* @returns {Function} An AVA `test` function.
*/
export function getTestFn(shell) {
try {
if (!isCI && typeof shell === "string") {
which.sync(shell, { path: process.env.PATH || process.env.Path });
}
return test;
} catch {
return test.skip;
}
}
/**
* Get a list of `shell` option values to use in end-to-end tests.
*
* @returns {(boolean | string)[]} A list of `shell` option values.
*/
export function getTestShells() {
const temp = path.resolve(import.meta.dirname, "..", "..", ".temp");
const systemShells = constants.isWindows
? constants.shellsWindows
: constants.shellsUnix;
const shells = [false, ...systemShells];
const busyboxIndex = shells.indexOf(constants.binBusyBox);
if (busyboxIndex !== -1) {
if (constants.isMacOS) {
shells.splice(busyboxIndex, 1);
} else {
shells[busyboxIndex] = path.resolve(temp, "busybox", "sh");
}
}
if (constants.isLinux) {
const doubleLinkedShell = path.resolve(temp, "double-link", "link-to-link");
shells.push(doubleLinkedShell);
}
if (!constants.isMacOS) {
shells.push(true);
}
return shells;
}