-
Notifications
You must be signed in to change notification settings - Fork 9
/
test.sh
executable file
·50 lines (42 loc) · 1.08 KB
/
test.sh
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
#!/bin/bash
set -euo pipefail
npm link
rm -R test-project 2>/dev/null || true
mkdir test-project
pushd test-project 1>/dev/null
cat <<'EOF' > package.json
{
"scripts": {
"echo": "echo \"$npm_config_user_agent\"",
"yarpm-echo": "yarpm run echo",
"yarpm-pnpm-echo": "yarpm-pnpm run echo",
"yarpm-yarn-echo": "yarpm-yarn run echo"
}
}
EOF
npm link yarpm
unset npm_execpath
function run_test {
exe=$1
npm_script=$2
test_pattern=$3
echo 'Testing "'"$exe"' run '"$npm_script"'"'
$exe run "$npm_script" foo > "$exe-$npm_script".$$.txt 2>&1
set +e
grep -E "$test_pattern" "$exe-$npm_script".$$.txt 1>/dev/null
grep_result=$?
set -e
if [[ $grep_result -ne 0 ]]; then
echo 'test for "'"$exe"' run '"$npm_script failed! Couldn't find pattern $test_pattern in output:"
cat "$exe-$npm_script".$$.txt
exit 1
else
echo "Success!"
fi
}
run_test npm yarpm-echo '^npm/.+foo$'
run_test pnpm yarpm-echo '^pnpm/.+foo$'
run_test npm yarpm-pnpm-echo '^pnpm/.+foo$'
run_test yarn yarpm-echo '^yarn/.+foo$'
run_test npm yarpm-yarn-echo '^yarn/.+foo$'
popd 1>/dev/null