diff --git a/package.json b/package.json index c9676cc94..54494a3a2 100644 --- a/package.json +++ b/package.json @@ -30,9 +30,9 @@ "test:end2end:server": "node --trace-warnings tests/support/end2end-server.js # MAIN! Use this to launch an end2end server!", "@comment test:end2end": "**HINT** All end2end script execute all tests, except you append a -- --spec=tests/end2end/MyTest-test.js", "test:end2end": "unset HEADLESS && npm run wdio", - "test:end2end:headless": "npm run wdio", - "test:end2end:watch": "unset HEADLESS && export npx wdio run wdio.conf.js --watch", - "test:end2end:watchheadless": "export HEADLESS=1 && export && npx wdio run wdio.conf.js --watch", + "test:end2end:headless": "export HEADLESS=1 && npm run wdio", + "test:end2end:watch": "unset HEADLESS && npm run wdio -- --watch", + "test:end2end:watchheadless": "export HEADLESS=1 && npm run wdio -- --watch", "test:fixtures:seed-minutes:unit": "npx nyc mocha --recursive tests/performance/fixtures/tests/ --require @babel/register --require tests/performance/fixtures/tests/babel", "test:program:priority-analyzer": "npx nyc mocha --recursive programs/priority-analyzer/tests/ --require @babel/register --require programs/priority-analyzer/tests/babel", "progam:priority-analyzer": "node ./node_modules/@babel/cli/bin/babel.js --presets=env programs/priority-analyzer/priority-analyzer.js", diff --git a/tests/run_e2e.sh b/tests/run_e2e.sh index 784b556fb..619dd43df 100755 --- a/tests/run_e2e.sh +++ b/tests/run_e2e.sh @@ -1,51 +1,70 @@ #!/usr/bin/env bash TEST="$1" # We will run these tests +LOGDIR="./tests/end2end/logs" +SERVERLOG="$LOGDIR/server.log" +MONGODB_HOST="localhost:3101" +MONGODB_DB="meteor" +VERSIONS_DIR="./versions" +# Ensure necessary commands are available +for cmd in npm mongodump google-chrome; do + if ! command -v $cmd &> /dev/null; then + echo "Error: $cmd could not be found" + exit 1 + fi +done + +# Function to echo and log +log() { + echo "$1" + echo "$1" >> "$SERVERLOG" +} echo Remove old log file -LOGDIR=./tests/end2end/logs mkdir -p "$LOGDIR" -SERVERLOG=$LOGDIR/server.log -rm "$SERVERLOG" +rm -f "$SERVERLOG" -echo Start end2end server -npm run test:end2end:server >"$SERVERLOG" & +log "Starting end2end server" +npm run test:end2end:server >> "$SERVERLOG" 2>&1 & +SERVER_PID=$! -COUNTER=0 -MAX_WAIT=900 +wait_for_server_start() { + local counter=0 + local max_wait=900 until grep "=> App running at" "$SERVERLOG"; do - echo App has not started yet.. Waiting for "$COUNTER" seconds +log "App has not started yet.. Waiting for $counter seconds" sleep 30 - COUNTER=$((COUNTER + 30)) - - if [ "$COUNTER" -gt "$MAX_WAIT" ]; then - echo Meteor takes too long to start, exiting. Server log: - cat "$SERVERLOG" - exit 1 - fi - if grep "=> Your application has errors." "$SERVERLOG"; then - echo Meteor reports build errors, exiting. Server log: - cat "$SERVERLOG" - exit 1 - fi + counter=$((counter + 30)) + if [ "$counter" -gt "$max_wait" ]; then + log "Meteor takes too long to start, exiting. Server log:" + cat "$SERVERLOG" + exit 1 + fi + if grep "=> Your application has errors." "$SERVERLOG"; then + log "Meteor reports build errors, exiting. Server log:" + cat "$SERVERLOG" + exit 1 + fi done +} +wait_for_server_start sleep 10 -echo Start end2end test runner -export HEADLESS=1 # evaluated by wdio.conf.js -export CHROME_LOG_FILE="$PWD/$LOGDIR"/chrome_client_console.log +log "Starting end2end test runner" +export HEADLESS=1 # evaluated by wdio.conf.js +export CHROME_LOG_FILE="$PWD/$LOGDIR/chrome_client_console.log" npm run wdio -- --spec "$TEST" WDIO_RESULT=$? +# Cleanup unset HEADLESS CHROME_LOG_FILE SPECFILE +mkdir -p tests/mongodump +mongodump -h "$MONGODB_HOST" -d "$MONGODB_DB" -o ./tests/mongodump -mkdir tests/mongodump -mongodump -h localhost:3101 -d meteor -o ./tests/mongodump - -# archive versions -mkdir versions -npm ls >./versions/npm.txt -google-chrome --version >./versions/chrome.txt -./node_modules/chromedriver/bin/chromedriver --version >./versions/chrome_driver.txt +# Archive versions +mkdir -p "$VERSIONS_DIR" +npm ls > "$VERSIONS_DIR/npm.txt" +google-chrome --version > "$VERSIONS_DIR/chrome.txt" +./node_modules/chromedriver/bin/chromedriver --version > "$VERSIONS_DIR/chrome_driver.txt" exit "$WDIO_RESULT" diff --git a/wdio.conf.js b/wdio.conf.js index b75572a42..e70b7f3b6 100644 --- a/wdio.conf.js +++ b/wdio.conf.js @@ -175,7 +175,7 @@ exports.config = { // resolved to continue. /** * Gets executed once before all workers get launched. - * @param {object} config wdio configuration object + * @param {Object} config wdio configuration object * @param {Array.} capabilities list of capabilities details */ // onPrepare: function (config, capabilities) { @@ -208,10 +208,9 @@ exports.config = { * Gets executed just before initialising the webdriver session and test * framework. It allows you to manipulate configurations depending on the * capability or spec. - * @param {object} config wdio configuration object + * @param {Object} config wdio configuration object * @param {Array.} capabilities list of capabilities details * @param {Array.} specs List of spec file paths that are to be run - * @param {string} cid worker id (e.g. 0-0) */ // beforeSession: function (config, capabilities, specs, cid) { // }, @@ -220,26 +219,24 @@ exports.config = { * all global variables like `browser`. It is the perfect place to define * custom commands. * @param {Array.} capabilities list of capabilities details - * @param {Array.} specs List of spec file paths that are to be - * run - * @param {object} browser instance of created browser/device - * session + * @param {Array.} specs List of spec file paths that are to be run + * @param {object} browser instance of created browser/device session */ before: function (capabilities, specs) { const chai = require("chai"); global.expect = chai.expect; - // before: function (capabilities, specs) { - // }, + + /** * Runs before a WebdriverIO command gets executed. - * @param {string} commandName hook command name + * @param {String} commandName hook command name * @param {Array} args arguments that command would receive */ // beforeCommand: function (commandName, args) { // }, /** * Hook that gets executed before the suite starts - * @param {object} suite suite details + * @param {Object} suite suite details */ // beforeSuite: function (suite) { // }, @@ -279,34 +276,32 @@ exports.config = { /** * Hook that gets executed after the suite has ended - * @param {object} suite suite details + * @param {Object} suite suite details */ // afterSuite: function (suite) { // }, /** * Runs after a WebdriverIO command gets executed - * @param {string} commandName hook command name + * @param {String} commandName hook command name * @param {Array} args arguments that command would receive - * @param {number} result 0 - command success, 1 - command error - * @param {object} error error object if any + * @param {Number} result 0 - command success, 1 - command error + * @param {Object} error error object if any */ // afterCommand: function (commandName, args, result, error) { // }, /** * Gets executed after all tests are done. You still have access to all global * variables from the test. - * @param {number} result 0 - test pass, 1 - test fail + * @param {Number} result 0 - test pass, 1 - test fail * @param {Array.} capabilities list of capabilities details * @param {Array.} specs List of spec file paths that ran */ - // after: function (result, capabilities, specs) { - // }, after: function (result, capabilities, specs) { server.close(); }, /** * Gets executed right after terminating the webdriver session. - * @param {object} config wdio configuration object + * @param {Object} config wdio configuration object * @param {Array.} capabilities list of capabilities details * @param {Array.} specs List of spec file paths that ran */ @@ -316,8 +311,8 @@ exports.config = { * Gets executed after all workers got shut down and the process is about to * exit. An error thrown in the onComplete hook will result in the test run * failing. - * @param {object} exitCode 0 - success, 1 - fail - * @param {object} config wdio configuration object + * @param {Object} exitCode 0 - success, 1 - fail + * @param {Object} config wdio configuration object * @param {Array.} capabilities list of capabilities details * @param {} results object containing test results */ @@ -325,8 +320,8 @@ exports.config = { // }, /** * Gets executed when a refresh happens. - * @param {string} oldSessionId session ID of the old session - * @param {string} newSessionId session ID of the new session + * @param {String} oldSessionId session ID of the old session + * @param {String} newSessionId session ID of the new session */ // onReload: function(oldSessionId, newSessionId) { // }