Skip to content

Commit

Permalink
chore: run all windows shims tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Jun 23, 2023
1 parent ffcbb2e commit ea9e4a0
Show file tree
Hide file tree
Showing 5 changed files with 267 additions and 98 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,38 @@ jobs:
run: node . test -w smoke-tests --ignore-scripts
- name: Check Git Status
run: node scripts/git-dirty.js

windows-shims:
name: Windows Shims Tests
runs-on: windows-latest
defaults:
run:
shell: cmd
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Git User
run: |
git config --global user.email "[email protected]"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: npm
- name: Check Git Status
run: node scripts/git-dirty.js
- name: Reset Deps
run: node scripts/resetdeps.js
- name: Setup WSL
uses: Vampire/[email protected]
- name: Setup Cygwin
uses: egor-tensin/[email protected]
with:
install-dir: C:\cygwin64
- name: Run Windows Shims Tests
run: node . test --ignore-scripts -- test/bin/windows-shims.js --no-coverage
env:
WINDOWS_SHIMS_TEST: true
- name: Check Git Status
run: node scripts/git-dirty.js
16 changes: 14 additions & 2 deletions bin/npm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ `uname` = 'Linux' ] && type wslpath &>/dev/null ; then
IS_WSL="true"
fi

NODE_EXE="$basedir/node.exe"
if ! [ -x "$NODE_EXE" ]; then
NODE_EXE="$basedir/node"
Expand All @@ -21,7 +25,15 @@ fi

# this path is passed to node.exe, so it needs to match whatever
# kind of paths Node.js thinks it's using, typically win32 paths.
CLI_BASEDIR="$("$NODE_EXE" -p 'require("path").dirname(process.execPath)')"
CLI_BASEDIR="$("$NODE_EXE" -p 'require("path").dirname(process.execPath)' 2> /dev/null)"
if [ $? -ne 0 ]; then
# this fails under WSL 1 so add an additional message
if [ "$IS_WSL" == "true" ]; then
echo "WSL 1 is not supported. Please upgrade to WSL 2" >&2
fi
echo "Could not determine Node.js install directory" >&2
exit 1
fi
NPM_CLI_JS="$CLI_BASEDIR/node_modules/npm/bin/npm-cli.js"
NPM_PREFIX=`"$NODE_EXE" "$NPM_CLI_JS" prefix -g`
if [ $? -ne 0 ]; then
Expand All @@ -37,7 +49,7 @@ NPM_WSL_PATH="/.."
# WSL can run Windows binaries, so we have to give it the win32 path
# however, WSL bash tests against posix paths, so we need to construct that
# to know if npm is installed globally.
if [ `uname` = 'Linux' ] && type wslpath &>/dev/null ; then
if [ "$IS_WSL" == "true" ]; then
NPM_WSL_PATH=`wslpath "$NPM_PREFIX_NPM_CLI_JS"`
fi
if [ -f "$NPM_PREFIX_NPM_CLI_JS" ] || [ -f "$NPM_WSL_PATH" ]; then
Expand Down
16 changes: 14 additions & 2 deletions bin/npx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ `uname` = 'Linux' ] && type wslpath &>/dev/null ; then
IS_WSL="true"
fi

NODE_EXE="$basedir/node.exe"
if ! [ -x "$NODE_EXE" ]; then
NODE_EXE="$basedir/node"
Expand All @@ -21,7 +25,15 @@ fi

# this path is passed to node.exe, so it needs to match whatever
# kind of paths Node.js thinks it's using, typically win32 paths.
CLI_BASEDIR="$("$NODE_EXE" -p 'require("path").dirname(process.execPath)')"
CLI_BASEDIR="$("$NODE_EXE" -p 'require("path").dirname(process.execPath)' 2> /dev/null)"
if [ $? -ne 0 ]; then
# this fails under WSL 1 so add an additional message
if [ "$IS_WSL" == "true" ]; then
echo "WSL 1 is not supported. Please upgrade to WSL 2" >&2
fi
echo "Could not determine Node.js install directory" >&2
exit 1
fi
NPM_CLI_JS="$CLI_BASEDIR/node_modules/npm/bin/npm-cli.js"
NPX_CLI_JS="$CLI_BASEDIR/node_modules/npm/bin/npx-cli.js"
NPM_PREFIX=`"$NODE_EXE" "$NPM_CLI_JS" prefix -g`
Expand All @@ -38,7 +50,7 @@ NPX_WSL_PATH="/.."
# WSL can run Windows binaries, so we have to give it the win32 path
# however, WSL bash tests against posix paths, so we need to construct that
# to know if npm is installed globally.
if [ `uname` = 'Linux' ] && type wslpath &>/dev/null ; then
if [ "$IS_WSL" == "true" ]; then
NPX_WSL_PATH=`wslpath "$NPM_PREFIX_NPX_CLI_JS"`
fi
if [ -f "$NPM_PREFIX_NPX_CLI_JS" ] || [ -f "$NPX_WSL_PATH" ]; then
Expand Down
21 changes: 21 additions & 0 deletions scripts/template-oss/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,24 @@
run: {{rootNpmPath}} test -w smoke-tests --ignore-scripts
- name: Check Git Status
run: node scripts/git-dirty.js

windows-shims:
name: Windows Shims Tests
runs-on: windows-latest
defaults:
run:
shell: cmd
steps:
{{> stepsSetup }}
- name: Setup WSL
uses: Vampire/[email protected]
- name: Setup Cygwin
uses: egor-tensin/[email protected]
with:
install-dir: C:\cygwin64
- name: Run Windows Shims Tests
run: {{rootNpmPath}} test --ignore-scripts -- test/bin/windows-shims.js --no-coverage
env:
WINDOWS_SHIMS_TEST: true
- name: Check Git Status
run: node scripts/git-dirty.js
Loading

0 comments on commit ea9e4a0

Please sign in to comment.