Skip to content

Commit

Permalink
chore(tests): Improve e2e test running script
Browse files Browse the repository at this point in the history
  • Loading branch information
bubonicfred committed Jun 25, 2024
1 parent ccc4da9 commit 6bcd0e7
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 57 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
81 changes: 50 additions & 31 deletions tests/run_e2e.sh
Original file line number Diff line number Diff line change
@@ -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"
41 changes: 18 additions & 23 deletions wdio.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.<Object>} capabilities list of capabilities details
*/
// onPrepare: function (config, capabilities) {
Expand Down Expand Up @@ -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.<Object>} capabilities list of capabilities details
* @param {Array.<String>} 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) {
// },
Expand All @@ -220,26 +219,24 @@ exports.config = {
* all global variables like `browser`. It is the perfect place to define
* custom commands.
* @param {Array.<Object>} capabilities list of capabilities details
* @param {Array.<String>} specs List of spec file paths that are to be
* run
* @param {object} browser instance of created browser/device
* session
* @param {Array.<String>} 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) {
// },
Expand Down Expand Up @@ -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.<Object>} capabilities list of capabilities details
* @param {Array.<String>} 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.<Object>} capabilities list of capabilities details
* @param {Array.<String>} specs List of spec file paths that ran
*/
Expand All @@ -316,17 +311,17 @@ 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.<Object>} capabilities list of capabilities details
* @param {<Object>} results object containing test results
*/
// onComplete: function(exitCode, config, capabilities, results) {
// },
/**
* 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) {
// }
Expand Down

0 comments on commit 6bcd0e7

Please sign in to comment.