Skip to content

Commit 7dea3b6

Browse files
committed
tools?: refactor test-npm into shell script
1 parent b97b96d commit 7dea3b6

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

Makefile

+1-13
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,7 @@ test-debugger: all
138138
$(PYTHON) tools/test.py debugger
139139

140140
test-npm: $(NODE_EXE)
141-
rm -rf npm-cache npm-tmp npm-prefix
142-
mkdir npm-cache npm-tmp npm-prefix
143-
cd deps/npm ; npm_config_cache="$(shell pwd)/npm-cache" \
144-
npm_config_prefix="$(shell pwd)/npm-prefix" \
145-
npm_config_tmp="$(shell pwd)/npm-tmp" \
146-
../../$(NODE_EXE) cli.js install --ignore-scripts
147-
cd deps/npm ; npm_config_cache="$(shell pwd)/npm-cache" \
148-
npm_config_prefix="$(shell pwd)/npm-prefix" \
149-
npm_config_tmp="$(shell pwd)/npm-tmp" \
150-
../../$(NODE_EXE) cli.js run-script test-all && \
151-
../../$(NODE_EXE) cli.js prune --prod && \
152-
cd ../.. && \
153-
rm -rf npm-cache npm-tmp npm-prefix
141+
NODE_EXE=$(NODE_EXE) tools/test-npm.sh
154142

155143
test-npm-publish: $(NODE_EXE)
156144
npm_package_config_publishtest=true ./$(NODE_EXE) deps/npm/test/run.js

tools/test-npm.sh

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# always change the working directory to the project's root directory
6+
cd $(dirname $0)/..
7+
8+
# pass NODE_EXE from something like Makefile
9+
# it should point to either ./node or ./node.exe, depending on the platform
10+
if ! [ -n "$NODE_EXE" ]; then
11+
echo "No node executable provided. Bailing." >&2
12+
exit 0
13+
fi
14+
15+
rm -rf test-npm
16+
mkdir test-npm
17+
18+
# make a copy of deps/npm to run the tests on
19+
cp -r deps/npm/ test-npm/
20+
21+
cd test-npm
22+
23+
# do a rm first just in case deps/npm contained these
24+
rm -rf npm-cache npm-tmp npm-prefix
25+
mkdir npm-cache npm-tmp npm-prefix
26+
27+
# these commands all require the same env variables, so run them as one
28+
npm_config_cache="npm-cache" \
29+
npm_config_prefix="npm-prefix" \
30+
npm_config_tmp="npm-tmp" \
31+
../$NODE_EXE cli.js install --ignore-scripts && \
32+
../$NODE_EXE cli.js run-script test-all && \
33+
../$NODE_EXE cli.js prune --prod
34+
35+
# clean up everything one single shot
36+
cd .. && rm -rf test-npm

0 commit comments

Comments
 (0)