Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for running Cypress under Windows/WSL #712

Closed
wants to merge 10 commits into from
Closed
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ Run all tests via the command line ```yarn test:cypress-all```, individual specs

[Optional] For VS Code, clone [opensphere-tests-vscode](https://github.com/justin-bits/opensphere-tests-vscode) for useful snippets and settings created specifically for testing OpenSphere.

### Windows

Tests run out of the box on Linux and OS X. For Windows users, see [this page](windows.md) for instructions on running Cypress tests under WSL.

## License

Copyright 2017 BIT Systems
Expand Down
7 changes: 6 additions & 1 deletion cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// the project's config changing)

var addMatchImageSnapshotPlugin = require('cypress-image-snapshot/plugin').addMatchImageSnapshotPlugin;
os = require('os');

/** This is a description of the foo function.
*
Expand All @@ -22,7 +23,11 @@ module.exports = function(on, config) {
addMatchImageSnapshotPlugin(on, config);
on('before:browser:launch', function(browser, args) {
if (browser.name === 'chrome') {
args.push('--window-size=1280,1200');
if (os.platform() === 'win32') {
args.push('--window-size=1295,1200');
} else {
args.push('--window-size=1280,1200');
}
return args;
}

Expand Down
2 changes: 1 addition & 1 deletion cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Cypress.Commands.add('login', function(clearLocalStorage) {
indexedDB.deleteDatabase(config.IndexedDB.FILES);
indexedDB.deleteDatabase(config.IndexedDB.SETTINGS);
}
cy.visit(config.HIDE_TIPS);
cy.visit('index.html' + config.HIDE_TIPS); // TODO: Windows 10 issue. Remove index.html after fixed: https://github.com/http-party/http-server/issues/525
cy.get(layers.layersTab.Tree.STREET_MAP_TILES, {timeout: 15000}).should('be.visible');
cy.get(layers.layersTab.Tree.LOADING_SPINNER, {timeout: 20000}).should('not.be.visible');
});
Expand Down
33 changes: 26 additions & 7 deletions cypress/support/execute-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function main() {
checkArguments
configureSound
overrideSettings
patchWindows
startWebServer
runTests
stopWebServer
Expand Down Expand Up @@ -49,6 +50,8 @@ function setVariables() {
export TEST_PATH=cypress/integration/

export TEST_RESULT

export CYPRESS_BIN_CMD=node_modules/.bin/cypress.cmd
}

function checkArguments() {
Expand Down Expand Up @@ -129,8 +132,22 @@ function overrideSettings() {
cp $SETTINGS_OS_SOURCE $SETTINGS_OS_TARGET
}

function patchWindows() {
if [ "$OSTYPE" == "msys" ] && ! [ -f "$CYPRESS_BIN_CMD" ]; then
echo "INFO: tests running under unpatched windows, patching yarn install"
./cypress/support/windows/patch-windows.cmd >/dev/null
echo "INFO: finished patch!"
else
echo "INFO: tests running under patched windows, no action"
fi
}

function startWebServer() {
webServerProcess=$(ps -ef | grep http-server | grep -v grep)
if [ "$OSTYPE" == "msys" ]; then
webServerProcess="$(netstat -ano | findstr 0.0.0.0:8282 | awk '{print $5}')"
else
webServerProcess=$(ps -ef | grep http-server | grep -v grep)
fi

if [ -z "$webServerProcess" ]; then
SERVER_STARTED=true
Expand Down Expand Up @@ -191,16 +208,18 @@ function runTests() {
}

function stopWebServer() {
if pgrep "node" > /dev/null; then
if $SERVER_STARTED; then
echo 'INFO: terminating web server'
npm run stop-server
if $SERVER_STARTED; then
echo 'INFO: terminating web server'
if [ "$OSTYPE" == "msys" ]; then
webServerProcess="$(netstat -ano | findstr 0.0.0.0:8282 | awk '{print $5}')"
taskkill //PID $webServerProcess //F
else
echo 'INFO: server was running before tests started, leaving it running'
npm run stop-server
fi
else
echo 'INFO: web server is not running, nothing to terminate'
echo 'INFO: server was running before tests started, leaving it running'
fi

}

function restoreSettings() {
Expand Down
15 changes: 15 additions & 0 deletions cypress/support/windows/.bin/cypress
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../../../../node_modules/cypress/bin/cypress" "$@"
ret=$?
else
node "$basedir/../../../../node_modules/cypress/bin/cypress" "$@"
ret=$?
fi
exit $ret
7 changes: 7 additions & 0 deletions cypress/support/windows/.bin/cypress.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\..\..\..\node_modules\cypress\bin\cypress" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\..\..\..\node_modules\cypress\bin\cypress" %*
)
15 changes: 15 additions & 0 deletions cypress/support/windows/.bin/http-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../../../../node_modules/http-server/bin/http-server" "$@"
ret=$?
else
node "$basedir/../../../../node_modules/http-server/bin/http-server" "$@"
ret=$?
fi
exit $ret
7 changes: 7 additions & 0 deletions cypress/support/windows/.bin/http-server.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\..\..\..\node_modules\http-server\bin\http-server" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\..\..\..\node_modules\http-server\bin\http-server" %*
)
15 changes: 15 additions & 0 deletions cypress/support/windows/.bin/run-os
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../../../../node_modules/run-script-os/index.js" "$@"
ret=$?
else
node "$basedir/../../../../node_modules/run-script-os/index.js" "$@"
ret=$?
fi
exit $ret
7 changes: 7 additions & 0 deletions cypress/support/windows/.bin/run-os.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\..\..\..\node_modules\run-script-os\index.js" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\..\..\..\node_modules\run-script-os\index.js" %*
)
15 changes: 15 additions & 0 deletions cypress/support/windows/.bin/run-script-os
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../../../../node_modules/run-script-os/index.js" "$@"
ret=$?
else
node "$basedir/../../../../node_modules/run-script-os/index.js" "$@"
ret=$?
fi
exit $ret
7 changes: 7 additions & 0 deletions cypress/support/windows/.bin/run-script-os.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\..\..\..\node_modules\run-script-os\index.js" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\..\..\..\node_modules\run-script-os\index.js" %*
)
5 changes: 5 additions & 0 deletions cypress/support/windows/patch-windows.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
del node_modules\.bin\cypress
del node_modules\.bin\http-server
del node_modules\.bin\run-os
del node_modules\.bin\run-script-os
copy cypress\support\windows\.bin\ node_modules\.bin
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@
"test:cypress": "bash cypress/support/execute-tests.sh dev gui",
"test:cypress-all": "bash cypress/support/execute-tests.sh dev cli all",
"test:cypress-smoke": "bash cypress/support/execute-tests.sh dev cli smoke",
"test:cypress-spec": "bash cypress/support/execute-tests.sh dev cli spec $1",
"test:cypress-loop": "bash cypress/support/execute-tests.sh dev cli loop $1",
"test:cypress-spec": "run-script-os",
"test:cypress-spec:macos:linux": "bash cypress/support/execute-tests.sh dev cli spec $1",
"test:cypress-spec:windows": "bash cypress/support/execute-tests.sh dev cli spec",
"test:cypress-loop": "run-script-os",
"test:cypress-loop:macos:linux": "bash cypress/support/execute-tests.sh dev cli loop $1",
"test:cypress-loop:windows": "bash cypress/support/execute-tests.sh dev cli loop",
"init:apidoc": "rimraf .build/*.conf.json dist/apidoc && mkdirp .build dist/apidoc",
"init:base": "rimraf .build dist && mkdirp .build dist/opensphere",
"init:debug": "rimraf index.html",
Expand Down Expand Up @@ -132,7 +136,9 @@
"perms": "chmod -R u+rwX,go+rX,go-w .",
"semantic-release": "semantic-release --dry-run",
"start-server": "http-server ../../ -p 8282 -c-1 -o -U -s &",
"stop-server": "pkill -f http-server"
"stop-server": "run-script-os",
"stop-server:macos:linux": "pkill -f http-server",
"stop-server:windows": "taskkill -im node.exe -f"
},
"keywords": [
"geospatial",
Expand Down Expand Up @@ -270,6 +276,7 @@
"opensphere-state-schema": "^2.4.0",
"postcss-cli": "^5.0.0",
"rimraf": "^2.5.4",
"run-script-os": "^1.0.7",
"sass-lint": "^1.12.1",
"semantic-release": "^15.13.18",
"surge": "^0.20.4",
Expand Down
5 changes: 5 additions & 0 deletions windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ Please be aware of the coding styles and linux/windows end of line differences.

Otherwise, use the WSL terminal to run project related commands, and code editing in your Windows editor of choice.

## E2E Test Setup
Cypress will not run correctly under Ubuntu with WSL 1 or WSL 2 (see https://github.com/cypress-io/cypress/issues/4145). However, Cypress can still run via Git Bash alongside an Ubuntu/WSL 1 installation. On the first execution under Windows via yarn test:cypress, a patch will be applied to the yarn installation that allows Cypress to run under Git Bash.

To support running Cypress under Git Bash, be sure the following are installed and configured under Windows (not just under Ubuntu): git for windows, node.js, npm, and yarn. Be sure to run yarn install and yarn build under Ubuntu, not Git Bash. Git Bash can then be used to start Cypress and run the tests.

## Using VSCode
[Visual Studio Code](https://code.visualstudio.com/) Is a free multi-platform open source code editor with a lot of handy features.This IDE is actually pretty good (maybe not prefect, but I like it). One feature that is very useful for projects like OpenSphere, is a way to define a preferred integrated terminal environment, like WSL terminal on Windows, see: https://blogs.msdn.microsoft.com/commandline/2017/10/27/running-node-js-on-wsl-from-visual-studio-code/

Expand Down