From b59512d2b81335b7f1f563ddb25b5e5056f3a6fb Mon Sep 17 00:00:00 2001 From: David Jay Date: Wed, 18 Jan 2017 12:12:49 -0500 Subject: [PATCH 01/12] Allowing e2e to run with only node_env=test. --- .env-e2e | 3 +++ package.json | 1 + scripts/pree2e.sh | 8 ++++---- 3 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 .env-e2e diff --git a/.env-e2e b/.env-e2e new file mode 100644 index 000000000..eefd18d51 --- /dev/null +++ b/.env-e2e @@ -0,0 +1,3 @@ +TALK_SESSION_SECRET=imasecretlookatme +TALK_ROOT_URL=http://localhost:3000 +TALK_MONGO_URL=mongodb://localhost/test diff --git a/package.json b/package.json index e6e211d07..78d8a2c7d 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "test-watch": "TEST_MODE=unit NODE_ENV=test mocha --compilers js:babel-core/register --recursive -w tests", "pree2e": "NODE_ENV=test scripts/pree2e.sh", "e2e": "NODE_ENV=test nightwatch", + "poste2e": "kill -15 $(ps aux | grep './bin/cli -c .env-e2e serve --jobs' | awk '{print $2}')", "embed-start": "NODE_ENV=development npm run build && ./bin/cli serve --jobs", "postinstall": "npm run build" }, diff --git a/scripts/pree2e.sh b/scripts/pree2e.sh index 0487a9187..4e12d7e9b 100755 --- a/scripts/pree2e.sh +++ b/scripts/pree2e.sh @@ -4,12 +4,12 @@ selenium-standalone install # Creating Admin Test User -./bin/cli-users create --flag_mode --email "admin@test.com" --password "test" --name "Admin Test User" --role "admin" +./bin/cli-users create --flag_mode --email "admin@test.com" --password "testtest" --name "AdminTestUser" --role "admin" # Creating Moderator Test User -./bin/cli-users create --flag_mode --email "moderator@test.com" --password "test" --name "Moderator Test User" --role "moderator" +./bin/cli-users create --flag_mode --email "moderator@test.com" --password "testtest" --name "ModeratorTestUser" --role "moderator" # Creating Commenter Test User -./bin/cli-users create --flag_mode --email "commenter@test.com" --password "test" --name "commenter@test.com" +./bin/cli-users create --flag_mode --email "commenter@test.com" --password "testtest" --name "commenter@test.com" -npm start & +./bin/cli -c .env-e2e serve --jobs & From 074630e628122bb7b7765971857cb32964576f55 Mon Sep 17 00:00:00 2001 From: David Jay Date: Wed, 18 Jan 2017 12:43:09 -0500 Subject: [PATCH 02/12] Updating usernames and passwords to new standards. --- scripts/pree2e.sh | 2 +- tests/e2e/globals.js | 6 +++--- tests/e2e/tests/EmbedStreamTests.js | 4 ++-- tests/e2e/tests/Visitor/SignUpTest.js | 6 ++---- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/scripts/pree2e.sh b/scripts/pree2e.sh index 4e12d7e9b..17da70f87 100755 --- a/scripts/pree2e.sh +++ b/scripts/pree2e.sh @@ -10,6 +10,6 @@ selenium-standalone install ./bin/cli-users create --flag_mode --email "moderator@test.com" --password "testtest" --name "ModeratorTestUser" --role "moderator" # Creating Commenter Test User -./bin/cli-users create --flag_mode --email "commenter@test.com" --password "testtest" --name "commenter@test.com" +./bin/cli-users create --flag_mode --email "commenter@test.com" --password "testtest" --name "CommenterTestUser" ./bin/cli -c .env-e2e serve --jobs & diff --git a/tests/e2e/globals.js b/tests/e2e/globals.js index 22ad3cb4b..0f73e1d4a 100644 --- a/tests/e2e/globals.js +++ b/tests/e2e/globals.js @@ -4,15 +4,15 @@ module.exports = { users: { admin: { email: 'admin@test.com', - pass: 'test' + pass: 'testtest' }, moderator: { email: 'moderator@test.com', - pass: 'test' + pass: 'testtest' }, commenter: { email: 'commenter@test.com', - pass: 'test' + pass: 'testtest' } }, }; diff --git a/tests/e2e/tests/EmbedStreamTests.js b/tests/e2e/tests/EmbedStreamTests.js index d572c2695..78c78680e 100644 --- a/tests/e2e/tests/EmbedStreamTests.js +++ b/tests/e2e/tests/EmbedStreamTests.js @@ -5,8 +5,8 @@ const mockComment = 'This is a test comment.'; const mockReply = 'This is a test reply'; const mockUser = { email: `${new Date().getTime()}@test.com`, - name: 'Test User', - pw: 'testtesttest' + name: 'testuser', + pw: 'testtest' }; module.exports = { diff --git a/tests/e2e/tests/Visitor/SignUpTest.js b/tests/e2e/tests/Visitor/SignUpTest.js index 9399b47ca..d37823ebf 100644 --- a/tests/e2e/tests/Visitor/SignUpTest.js +++ b/tests/e2e/tests/Visitor/SignUpTest.js @@ -1,5 +1,3 @@ -const uuid = require('uuid'); - module.exports = { '@tags': ['signup', 'visitor'], before: client => { @@ -14,8 +12,8 @@ module.exports = { embedStreamPage .signUp({ - email: `visitor_${uuid.v4()}@test.com`, - displayName: 'Visitor', + email: `visitor_${Date.now()}@test.com`, + displayName: 'visitor', pass: 'testtest' }); }, From edf9ced454d3bd5bdeef38d54865ea40fd9c87a2 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Wed, 25 Jan 2017 11:11:33 -0700 Subject: [PATCH 03/12] Added PID support --- .env-e2e | 3 --- bin/cli | 48 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- scripts/poste2e.sh | 10 ++++++++++ scripts/pree2e.sh | 9 +++++---- util.js | 19 +++++++++++++----- 6 files changed, 78 insertions(+), 13 deletions(-) delete mode 100644 .env-e2e create mode 100755 scripts/poste2e.sh diff --git a/.env-e2e b/.env-e2e deleted file mode 100644 index eefd18d51..000000000 --- a/.env-e2e +++ /dev/null @@ -1,3 +0,0 @@ -TALK_SESSION_SECRET=imasecretlookatme -TALK_ROOT_URL=http://localhost:3000 -TALK_MONGO_URL=mongodb://localhost/test diff --git a/bin/cli b/bin/cli index c5c61fbf6..107d0a9ba 100755 --- a/bin/cli +++ b/bin/cli @@ -7,6 +7,8 @@ const program = require('commander'); const pkg = require('../package.json'); const dotenv = require('dotenv'); +const fs = require('fs'); +const util = require('../util'); //============================================================================== // Setting up the program command line arguments. @@ -15,6 +17,7 @@ const dotenv = require('dotenv'); program .version(pkg.version) .option('-c, --config [path]', 'Specify the configuration file to load') + .option('--pid [path]', 'Specify a path to output the current PID to') .parse(process.argv); if (program.config) { @@ -27,6 +30,40 @@ if (program.config) { } } +// If the `--pid` flag is used, put the current pid there. +if (program.pid) { + let pidPath = program.pid; + + if (!/\//.test(pidPath)) { + if (!/\.pid/.test(pidPath)) { + pidPath += '.pid'; + } + pidPath = `/tmp/${pidPath}`; + } + + fs.writeFile(pidPath, `${process.pid.toString()}\n`, (err) => { + if (err) { + console.error(`Can't write PID file: ${err}`); + throw err; + } + + // Add the cleanup for the fs onto the shutdown. + util.onshutdown([ + () => new Promise((resolve, reject) => { + + // Remove the pid file. + fs.unlink(pidPath, (err) => { + if (err) { + return reject(err); + } + + return resolve(); + }); + }) + ]); + }); +} + // Perform rewrites to the runtime environment variables based on the contents // of the process.env.REWRITE_ENV if it exists. This is done here as it is the // entrypoint for the entire application. @@ -43,4 +80,15 @@ program // If there is no command listed, output help. if (!process.argv.slice(2).length) { program.outputHelp(); + return; } + +// The ensures that the child process that is created here is always cleaned up +// properly when the parent process dies. +util.onshutdown([ + (signal) => { + if ((program.runningCommand.killed === false) && (program.runningCommand.exitCode === null)) { + program.runningCommand.kill(signal); + } + } +]); diff --git a/package.json b/package.json index c0cf30802..26cd2d5d4 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "test-watch": "TEST_MODE=unit NODE_ENV=test mocha --compilers js:babel-core/register --recursive -w tests", "pree2e": "NODE_ENV=test scripts/pree2e.sh", "e2e": "NODE_ENV=test nightwatch", - "poste2e": "kill -15 $(ps aux | grep './bin/cli -c .env-e2e serve --jobs' | awk '{print $2}')", + "poste2e": "NODE_ENV=test scripts/poste2e.sh", "embed-start": "NODE_ENV=development npm run build && ./bin/cli serve --jobs", "postinstall": "npm run build" }, diff --git a/scripts/poste2e.sh b/scripts/poste2e.sh new file mode 100755 index 000000000..1a8279da1 --- /dev/null +++ b/scripts/poste2e.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# If there is a PID file from the e2e tests... +if [ -e /tmp/talk-e2e.pid ] +then + + # Then kill the running talk server. + kill $(cat /tmp/talk-e2e.pid) + +fi diff --git a/scripts/pree2e.sh b/scripts/pree2e.sh index 17da70f87..267a2617f 100755 --- a/scripts/pree2e.sh +++ b/scripts/pree2e.sh @@ -4,12 +4,13 @@ selenium-standalone install # Creating Admin Test User -./bin/cli-users create --flag_mode --email "admin@test.com" --password "testtest" --name "AdminTestUser" --role "admin" +./bin/cli users create --flag_mode --email "admin@test.com" --password "testtest" --name "AdminTestUser" --role "admin" # Creating Moderator Test User -./bin/cli-users create --flag_mode --email "moderator@test.com" --password "testtest" --name "ModeratorTestUser" --role "moderator" +./bin/cli users create --flag_mode --email "moderator@test.com" --password "testtest" --name "ModeratorTestUser" --role "moderator" # Creating Commenter Test User -./bin/cli-users create --flag_mode --email "commenter@test.com" --password "testtest" --name "CommenterTestUser" +./bin/cli users create --flag_mode --email "commenter@test.com" --password "testtest" --name "CommenterTestUser" -./bin/cli -c .env-e2e serve --jobs & +# Start the server and write the PID to a file to be killed later. +./bin/cli --pid /tmp/talk-e2e.pid serve --jobs & diff --git a/util.js b/util.js index b081078e7..261b66f85 100644 --- a/util.js +++ b/util.js @@ -1,3 +1,4 @@ +const debug = require('debug')('talk:util'); const util = module.exports = {}; /** @@ -11,10 +12,16 @@ util.toshutdown = []; * Calls all the shutdown functions and then ends the process. * @param {Number} [defaultCode=0] default return code upon sucesfull shutdown. */ -util.shutdown = (defaultCode = 0) => { +util.shutdown = (defaultCode = 0, signal = null) => { + + if (signal) { + debug(`Reached ${signal} signal`); + } + Promise - .all(util.toshutdown.map((func) => func ? func() : null).filter((func) => func)) + .all(util.toshutdown.map((func) => func ? func(signal) : null).filter((func) => func)) .then(() => { + debug('Shutdown complete, now exiting'); process.exit(defaultCode); }) .catch((err) => { @@ -32,6 +39,8 @@ util.shutdown = (defaultCode = 0) => { */ util.onshutdown = (jobs) => { + debug(`${jobs.length} jobs registered`); + // Add the new jobs to shutdown to the object reference. util.toshutdown = util.toshutdown.concat(jobs); }; @@ -39,6 +48,6 @@ util.onshutdown = (jobs) => { // Attach to the SIGTERM + SIGINT handles to ensure a clean shutdown in the // event that we have an external event. SIGUSR2 is called when the app is asked // to be 'killed', same procedure here. -process.on('SIGTERM', () => util.shutdown()); -process.on('SIGINT', () => util.shutdown()); -process.once('SIGUSR2', () => util.shutdown()); +process.on('SIGTERM', () => util.shutdown(0, 'SIGTERM')); +process.on('SIGINT', () => util.shutdown(0, 'SIGINT')); +process.once('SIGUSR2', () => util.shutdown(0, 'SIGUSR2')); From 91402a3e8b8fd9bd83c627f07006341d7f515bb9 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Wed, 25 Jan 2017 11:57:40 -0700 Subject: [PATCH 04/12] Moved PID into util.js --- bin/cli | 32 +------------------------------- util.js | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/bin/cli b/bin/cli index 107d0a9ba..002288648 100755 --- a/bin/cli +++ b/bin/cli @@ -7,7 +7,6 @@ const program = require('commander'); const pkg = require('../package.json'); const dotenv = require('dotenv'); -const fs = require('fs'); const util = require('../util'); //============================================================================== @@ -32,36 +31,7 @@ if (program.config) { // If the `--pid` flag is used, put the current pid there. if (program.pid) { - let pidPath = program.pid; - - if (!/\//.test(pidPath)) { - if (!/\.pid/.test(pidPath)) { - pidPath += '.pid'; - } - pidPath = `/tmp/${pidPath}`; - } - - fs.writeFile(pidPath, `${process.pid.toString()}\n`, (err) => { - if (err) { - console.error(`Can't write PID file: ${err}`); - throw err; - } - - // Add the cleanup for the fs onto the shutdown. - util.onshutdown([ - () => new Promise((resolve, reject) => { - - // Remove the pid file. - fs.unlink(pidPath, (err) => { - if (err) { - return reject(err); - } - - return resolve(); - }); - }) - ]); - }); + util.pid(program.pid); } // Perform rewrites to the runtime environment variables based on the contents diff --git a/util.js b/util.js index 261b66f85..585cfdcb7 100644 --- a/util.js +++ b/util.js @@ -1,4 +1,6 @@ const debug = require('debug')('talk:util'); +const fs = require('fs'); + const util = module.exports = {}; /** @@ -45,6 +47,43 @@ util.onshutdown = (jobs) => { util.toshutdown = util.toshutdown.concat(jobs); }; +/** + * Register a PID file to be maintained for the lifespan of the process. + * @param {String} path path to the PID file to create + */ +util.pid = (path) => { + if (!/\//.test(path)) { + if (!/\.pid/.test(path)) { + path += '.pid'; + } + path = `/tmp/${path}`; + } + + const pid = `${process.pid.toString()}\n`; + + fs.writeFile(path, pid, (err) => { + if (err) { + console.error(`Can't write PID file: ${err}`); + throw err; + } + + // Add the cleanup for the fs onto the shutdown. + util.onshutdown([ + () => new Promise((resolve, reject) => { + + // Remove the pid file. + fs.unlink(path, (err) => { + if (err) { + return reject(err); + } + + return resolve(); + }); + }) + ]); + }); +}; + // Attach to the SIGTERM + SIGINT handles to ensure a clean shutdown in the // event that we have an external event. SIGUSR2 is called when the app is asked // to be 'killed', same procedure here. From 2e34f726ebc967658e712d6cee31df98a77de3be Mon Sep 17 00:00:00 2001 From: David Jay Date: Thu, 26 Jan 2017 14:41:03 -0500 Subject: [PATCH 05/12] Updating tests to reflect graphql changes. --- nightwatch.conf.js | 12 ++++++------ scripts/pree2e.sh | 4 ++-- test/e2e/mocks.js | 14 ++++++++------ test/e2e/pages/embedStreamPage.js | 4 ++-- test/e2e/tests/EmbedStreamTests.js | 2 +- test/e2e/tests/Visitor/SignUpTest.js | 2 +- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/nightwatch.conf.js b/nightwatch.conf.js index fb6c5f9c7..c2653e714 100644 --- a/nightwatch.conf.js +++ b/nightwatch.conf.js @@ -1,20 +1,20 @@ require('babel-core/register'); module.exports = { - 'src_folders': './tests/e2e/tests', - 'output_folder': './tests/e2e/reports', - 'page_objects_path': './tests/e2e/pages', - 'globals_path': './tests/e2e/globals', + 'src_folders': './test/e2e/tests', + 'output_folder': './test/e2e/reports', + 'page_objects_path': './test/e2e/pages', + 'globals_path': './test/e2e/globals', 'custom_commands_path' : '', 'custom_assertions_path' : '', 'selenium': { 'start_process': true, 'server_path': 'node_modules/selenium-standalone/.selenium/selenium-server/2.53.1-server.jar', - 'log_path': './tests/e2e/reports', + 'log_path': './test/e2e/reports', 'host': '127.0.0.1', 'port': 6666, 'cli_args': { - 'webdriver.chrome.driver': 'node_modules/selenium-standalone/.selenium/chromedriver/2.25-x64-chromedriver' + 'webdriver.chrome.driver': 'node_modules/selenium-standalone/.selenium/chromedriver/2.27-x64-chromedriver' } }, 'test_settings': { diff --git a/scripts/pree2e.sh b/scripts/pree2e.sh index 267a2617f..f9caae85d 100755 --- a/scripts/pree2e.sh +++ b/scripts/pree2e.sh @@ -4,10 +4,10 @@ selenium-standalone install # Creating Admin Test User -./bin/cli users create --flag_mode --email "admin@test.com" --password "testtest" --name "AdminTestUser" --role "admin" +./bin/cli users create --flag_mode --email "admin@test.com" --password "testtest" --name "AdminTestUser" --role "ADMIN" # Creating Moderator Test User -./bin/cli users create --flag_mode --email "moderator@test.com" --password "testtest" --name "ModeratorTestUser" --role "moderator" +./bin/cli users create --flag_mode --email "moderator@test.com" --password "testtest" --name "ModeratorTestUser" --role "MODERATOR" # Creating Commenter Test User ./bin/cli users create --flag_mode --email "commenter@test.com" --password "testtest" --name "CommenterTestUser" diff --git a/test/e2e/mocks.js b/test/e2e/mocks.js index a4f430cd5..e46077308 100644 --- a/test/e2e/mocks.js +++ b/test/e2e/mocks.js @@ -1,8 +1,8 @@ -const Comments = require('../../models/comment'); -const Users = require('../../models/user'); -const Actions = require('../../models/action'); -const Assets = require('../../models/asset'); -const Settings = require('../../models/setting'); +const Comments = require('../../services/comments'); +const Users = require('../../services/users'); +const Actions = require('../../services/actions'); +const Assets = require('../../services/assets'); +const Settings = require('../../services/settings'); const globals = require('./globals'); /* Create an array of comments */ @@ -22,4 +22,6 @@ module.exports.users = (users) => Users.createLocalUsers(users); module.exports.actions = (actions) => Actions.create(actions); /* Update a setting */ -module.exports.settings = (setting) => Settings.init().then(() => Settings.updateSettings(setting)); +module.exports.settings = (setting) => Settings.init().then(() => { + Settings.updateSettings(setting); +}); diff --git a/test/e2e/pages/embedStreamPage.js b/test/e2e/pages/embedStreamPage.js index 164449ff0..bdf2f9440 100644 --- a/test/e2e/pages/embedStreamPage.js +++ b/test/e2e/pages/embedStreamPage.js @@ -127,10 +127,10 @@ module.exports = { selector: '.comment .coral-plugin-flags-popup' }, flagCommentOption: { - selector: '.comment .coral-plugin-flags-popup .coral-plugin-flags-popup-radio-label[for="comments"]' + selector: '.comment .coral-plugin-flags-popup .coral-plugin-flags-popup-radio-label[for="COMMENTS"]' }, flagUsernameOption: { - selector: '.comment .coral-plugin-flags-popup .coral-plugin-flags-popup-radio-label[for="user"]' + selector: '.comment .coral-plugin-flags-popup .coral-plugin-flags-popup-radio-label[for="USERS"]' }, flagOtherOption: { selector: '.comment .coral-plugin-flags-popup .coral-plugin-flags-popup-radio-label[for="other"]' diff --git a/test/e2e/tests/EmbedStreamTests.js b/test/e2e/tests/EmbedStreamTests.js index abe76fed3..93bb54399 100644 --- a/test/e2e/tests/EmbedStreamTests.js +++ b/test/e2e/tests/EmbedStreamTests.js @@ -170,7 +170,7 @@ module.exports = { // Verify that comment count is correct client.waitForElementVisible('.coral-plugin-comment-count-text', 2000) - .assert.containsText('.coral-plugin-comment-count-text', '1 Comment'); + .assert.containsText('.coral-plugin-comment-count-text', '2 Comments'); done(); }); }, diff --git a/test/e2e/tests/Visitor/SignUpTest.js b/test/e2e/tests/Visitor/SignUpTest.js index d37823ebf..d19ca1d8c 100644 --- a/test/e2e/tests/Visitor/SignUpTest.js +++ b/test/e2e/tests/Visitor/SignUpTest.js @@ -13,7 +13,7 @@ module.exports = { embedStreamPage .signUp({ email: `visitor_${Date.now()}@test.com`, - displayName: 'visitor', + displayName: `visitor${Date.now()}`, pass: 'testtest' }); }, From fa985acd14372f93553b83d3713dd210dde4a4f9 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 26 Jan 2017 14:45:02 -0700 Subject: [PATCH 06/12] Update circle.yml --- circle.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/circle.yml b/circle.yml index 160bc7bb9..6009a88e6 100644 --- a/circle.yml +++ b/circle.yml @@ -21,6 +21,8 @@ test: override: # Run the tests using the junit reporter. - MOCHA_FILE=$CIRCLE_TEST_REPORTS/junit/test-results.xml NPM_PACKAGE_CONFIG_MOCHA_REPORTER=mocha-junit-reporter npm run test + # Run the e2e test suite + - npm run e2e deployment: release: From b8ff2b676370179a1192cd9a6dcafd11ac525151 Mon Sep 17 00:00:00 2001 From: David Jay Date: Thu, 26 Jan 2017 16:51:03 -0500 Subject: [PATCH 07/12] Resetting chrome version to 2.25 in nightwatch. --- nightwatch.conf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nightwatch.conf.js b/nightwatch.conf.js index c2653e714..3b6b356b6 100644 --- a/nightwatch.conf.js +++ b/nightwatch.conf.js @@ -14,7 +14,7 @@ module.exports = { 'host': '127.0.0.1', 'port': 6666, 'cli_args': { - 'webdriver.chrome.driver': 'node_modules/selenium-standalone/.selenium/chromedriver/2.27-x64-chromedriver' + 'webdriver.chrome.driver': 'node_modules/selenium-standalone/.selenium/chromedriver/2.25-x64-chromedriver' } }, 'test_settings': { From d829d2541f6636d3c939c1c8eb1afa492aa444dd Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Fri, 27 Jan 2017 11:20:45 -0700 Subject: [PATCH 08/12] Added new env var for e2e reports --- circle.yml | 2 +- nightwatch.conf.js | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/circle.yml b/circle.yml index 6009a88e6..c511715a5 100644 --- a/circle.yml +++ b/circle.yml @@ -22,7 +22,7 @@ test: # Run the tests using the junit reporter. - MOCHA_FILE=$CIRCLE_TEST_REPORTS/junit/test-results.xml NPM_PACKAGE_CONFIG_MOCHA_REPORTER=mocha-junit-reporter npm run test # Run the e2e test suite - - npm run e2e + - E2E_REPORT_PATH=$CIRCLE_TEST_REPORTS/e2e npm run e2e deployment: release: diff --git a/nightwatch.conf.js b/nightwatch.conf.js index 3b6b356b6..2e0cc5020 100644 --- a/nightwatch.conf.js +++ b/nightwatch.conf.js @@ -1,8 +1,13 @@ require('babel-core/register'); +let E2E_REPORT_PATH = './test/e2e/reports'; +if (process.env.E2E_REPORT_PATH && process.env.E2E_REPORT_PATH.length > 0) { + E2E_REPORT_PATH = process.env.E2E_REPORT_PATH; +} + module.exports = { 'src_folders': './test/e2e/tests', - 'output_folder': './test/e2e/reports', + 'output_folder': E2E_REPORT_PATH, 'page_objects_path': './test/e2e/pages', 'globals_path': './test/e2e/globals', 'custom_commands_path' : '', @@ -10,7 +15,7 @@ module.exports = { 'selenium': { 'start_process': true, 'server_path': 'node_modules/selenium-standalone/.selenium/selenium-server/2.53.1-server.jar', - 'log_path': './test/e2e/reports', + 'log_path': E2E_REPORT_PATH, 'host': '127.0.0.1', 'port': 6666, 'cli_args': { @@ -36,7 +41,7 @@ module.exports = { 'enabled': true, 'on_failure': true, 'on_error': true, - 'path': './tests/e2e/reports' + 'path': E2E_REPORT_PATH }, 'exclude': [ './tests/e2e/tests/EmbedStreamTests.js' @@ -47,7 +52,3 @@ module.exports = { } } }; - -// "chromeOptions" : { -// "args" : ["start-fullscreen"] -// } From fcf22ef4f98b1c711203d5287f646e7a3b78ac69 Mon Sep 17 00:00:00 2001 From: David Jay Date: Fri, 27 Jan 2017 14:07:34 -0500 Subject: [PATCH 09/12] Adding selenium settings and fixing bug in moderation approval. --- client/coral-admin/src/components/ModerationList.js | 12 ++++++------ package.json | 2 +- scripts/pree2e.sh | 2 +- selenium.config.js | 9 +++++++++ 4 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 selenium.config.js diff --git a/client/coral-admin/src/components/ModerationList.js b/client/coral-admin/src/components/ModerationList.js index 8ce3ec4a4..c1df40d31 100644 --- a/client/coral-admin/src/components/ModerationList.js +++ b/client/coral-admin/src/components/ModerationList.js @@ -8,10 +8,10 @@ import SuspendUserModal from './SuspendUserModal'; // Each action has different meaning and configuration const menuOptionsMap = { - 'reject': {status: 'rejected', icon: 'close', key: 'r'}, - 'approve': {status: 'accepted', icon: 'done', key: 't'}, - 'flag': {status: 'flagged', icon: 'flag', filter: 'Untouched'}, - 'ban': {status: 'banned', icon: 'not interested'} + 'reject': {status: 'REJECTED', icon: 'close', key: 'r'}, + 'approve': {status: 'ACCEPTED', icon: 'done', key: 't'}, + 'flag': {status: 'FLAGGED', icon: 'flag', filter: 'Untouched'}, + 'ban': {status: 'BANNED', icon: 'not interested'} }; // Renders a comment list and allow performing actions @@ -135,9 +135,9 @@ export default class ModerationList extends React.Component { } else if (action.item_type === 'USERS') { // If a user bio or name is rejected, bring up a dialog before suspending them. - if (menuOption === 'rejected') { + if (menuOption === 'REJECTED') { this.setState({suspendUserModal: action}); - } else if (menuOption === 'accepted') { + } else if (menuOption === 'ACCEPTED') { this.props.userStatusUpdate('ACTIVE', action.item_id); } } diff --git a/package.json b/package.json index 41b11e848..641d85757 100644 --- a/package.json +++ b/package.json @@ -154,7 +154,7 @@ "redux-mock-store": "^1.2.1", "redux-thunk": "^2.1.0", "regenerator": "^0.8.46", - "selenium-standalone": "latest", + "selenium-standalone": "^5.11.2", "style-loader": "^0.13.1", "supertest": "^2.0.1", "timeago.js": "^2.0.3", diff --git a/scripts/pree2e.sh b/scripts/pree2e.sh index f9caae85d..80aed9253 100755 --- a/scripts/pree2e.sh +++ b/scripts/pree2e.sh @@ -1,7 +1,7 @@ #!/bin/bash # install selenium -selenium-standalone install +selenium-standalone install --config=./selenium.config.js # Creating Admin Test User ./bin/cli users create --flag_mode --email "admin@test.com" --password "testtest" --name "AdminTestUser" --role "ADMIN" diff --git a/selenium.config.js b/selenium.config.js new file mode 100644 index 000000000..b43c31ef0 --- /dev/null +++ b/selenium.config.js @@ -0,0 +1,9 @@ +module.exports = { + drivers: { + chrome: { + version: '2.25', + arch: process.arch, + baseURL: 'https://chromedriver.storage.googleapis.com' + }, + }, +}; From 9d15a0448a4d0c0ec475b0c11e0df24289e68bd9 Mon Sep 17 00:00:00 2001 From: David Jay Date: Fri, 27 Jan 2017 15:21:18 -0500 Subject: [PATCH 10/12] Adding settings init to pree2e script. --- scripts/pree2e.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/pree2e.sh b/scripts/pree2e.sh index 80aed9253..6210c09f0 100755 --- a/scripts/pree2e.sh +++ b/scripts/pree2e.sh @@ -3,6 +3,9 @@ # install selenium selenium-standalone install --config=./selenium.config.js +#Init settings +./bin/cli settings init + # Creating Admin Test User ./bin/cli users create --flag_mode --email "admin@test.com" --password "testtest" --name "AdminTestUser" --role "ADMIN" From 1da61784b420e0574318855782f2868113497d58 Mon Sep 17 00:00:00 2001 From: David Jay Date: Fri, 27 Jan 2017 16:10:47 -0500 Subject: [PATCH 11/12] Fixing bugs around settings in e2e. --- test/e2e/mocks.js | 5 ++--- test/e2e/pages/adminPage.js | 3 ++- test/e2e/tests/01_EmbedStreamTest.js | 16 ++++++++++++---- test/e2e/tests/EmbedStreamTests.js | 1 - 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/test/e2e/mocks.js b/test/e2e/mocks.js index e46077308..07693651d 100644 --- a/test/e2e/mocks.js +++ b/test/e2e/mocks.js @@ -22,6 +22,5 @@ module.exports.users = (users) => Users.createLocalUsers(users); module.exports.actions = (actions) => Actions.create(actions); /* Update a setting */ -module.exports.settings = (setting) => Settings.init().then(() => { - Settings.updateSettings(setting); -}); +module.exports.settings = (setting) => Settings.init().then(() => + Settings.update(setting)); diff --git a/test/e2e/pages/adminPage.js b/test/e2e/pages/adminPage.js index e359715ac..3cc00d5fc 100644 --- a/test/e2e/pages/adminPage.js +++ b/test/e2e/pages/adminPage.js @@ -10,7 +10,8 @@ const embedStreamCommands = { return this .waitForElementVisible('@moderationList') .waitForElementVisible('@approveButton') - .click('@approveButton'); + .click('@approveButton') + .waitForElementNotPresent('@approveButton'); } }; diff --git a/test/e2e/tests/01_EmbedStreamTest.js b/test/e2e/tests/01_EmbedStreamTest.js index 35f4171c7..87e94923e 100644 --- a/test/e2e/tests/01_EmbedStreamTest.js +++ b/test/e2e/tests/01_EmbedStreamTest.js @@ -1,10 +1,18 @@ +const mocks = require('../mocks'); + module.exports = { '@tags': ['embedStream'], before: client => { - const embedStreamPage = client.page.embedStreamPage(); - embedStreamPage - .navigate() - .ready(); + client.perform((client, done) => { + mocks.settings({moderation: 'PRE'}) + .then(() => { + const embedStreamPage = client.page.embedStreamPage(); + embedStreamPage + .navigate() + .ready(); + done(); + }); + }); }, 'Login as commenter': client => { const embedStreamPage = client.page.embedStreamPage(); diff --git a/test/e2e/tests/EmbedStreamTests.js b/test/e2e/tests/EmbedStreamTests.js index 93bb54399..63acf0f0d 100644 --- a/test/e2e/tests/EmbedStreamTests.js +++ b/test/e2e/tests/EmbedStreamTests.js @@ -29,7 +29,6 @@ module.exports = { .frame('coralStreamIframe') // Register and Log In - .waitForElementVisible('#commentBox', 1000) .waitForElementVisible('#coralSignInButton', 2000) .click('#coralSignInButton') .waitForElementVisible('#coralRegister', 1000) From b674ff45c0ff063daba2a9ea3a5e4e31fdb90b0b Mon Sep 17 00:00:00 2001 From: David Jay Date: Fri, 27 Jan 2017 17:29:23 -0500 Subject: [PATCH 12/12] Addressing errors with replies in e2e. --- client/coral-embed-stream/src/Comment.js | 2 +- .../graphql/fragments/commentView.graphql | 1 + client/coral-plugin-commentbox/CommentBox.js | 2 -- .../CommentContent.js | 2 +- test/e2e/tests/EmbedStreamTests.js | 36 +++++++++---------- 5 files changed, 19 insertions(+), 24 deletions(-) diff --git a/client/coral-embed-stream/src/Comment.js b/client/coral-embed-stream/src/Comment.js index 93c89ffb0..529420941 100644 --- a/client/coral-embed-stream/src/Comment.js +++ b/client/coral-embed-stream/src/Comment.js @@ -87,7 +87,7 @@ class Comment extends React.Component { return (

diff --git a/client/coral-framework/graphql/fragments/commentView.graphql b/client/coral-framework/graphql/fragments/commentView.graphql index b54c00e67..fb8051155 100644 --- a/client/coral-framework/graphql/fragments/commentView.graphql +++ b/client/coral-framework/graphql/fragments/commentView.graphql @@ -2,6 +2,7 @@ fragment commentView on Comment { id body created_at + status user { id name: displayName diff --git a/client/coral-plugin-commentbox/CommentBox.js b/client/coral-plugin-commentbox/CommentBox.js index 258681a08..41c8f75fb 100644 --- a/client/coral-plugin-commentbox/CommentBox.js +++ b/client/coral-plugin-commentbox/CommentBox.js @@ -75,8 +75,6 @@ class CommentBox extends Component { } else if (postedComment.status === 'PREMOD') { addNotification('success', lang.t('comment-post-notif-premod')); } else { - - // appendItemArray(parent_id || id, related, commentId, !parent_id, parent_type); addNotification('success', 'Your comment has been posted.'); } diff --git a/client/coral-plugin-commentcontent/CommentContent.js b/client/coral-plugin-commentcontent/CommentContent.js index 542776c63..2dab237dd 100644 --- a/client/coral-plugin-commentcontent/CommentContent.js +++ b/client/coral-plugin-commentcontent/CommentContent.js @@ -1,5 +1,5 @@ import React from 'react'; -const name = 'coral-plugin-replies'; +const name = 'coral-plugin-content'; const Content = ({body, styles}) => { const textbreaks = body.split('\n'); diff --git a/test/e2e/tests/EmbedStreamTests.js b/test/e2e/tests/EmbedStreamTests.js index 63acf0f0d..7343c3d0a 100644 --- a/test/e2e/tests/EmbedStreamTests.js +++ b/test/e2e/tests/EmbedStreamTests.js @@ -1,7 +1,7 @@ const mongoose = require('../../helpers/mongoose'); const mocks = require('../mocks'); -const mockComment = 'This is a test comment.'; +const mockComment = 'I read the comments'; const mockReply = 'This is a test reply'; const mockUser = { email: `${new Date().getTime()}@test.com`, @@ -46,10 +46,10 @@ module.exports = { // Post a comment .setValue('.coral-plugin-commentbox-textarea', mockComment) .click('.coral-plugin-commentbox-button') - .waitForElementVisible('.comment', 1000) + .waitForElementVisible('.coral-plugin-content-text', 1000) // Verify that it appears - .assert.containsText('.comment', mockComment); + .assert.containsText('.coral-plugin-content-text', mockComment); done(); }) .catch((err) => { @@ -103,8 +103,8 @@ module.exports = { .click('.coral-plugin-replies-reply-button') .waitForElementVisible('#replyText') .setValue('#replyText', mockReply) - .click('.coral-plugin-replies-textarea button') - .waitForElementVisible('.reply', 2000) + .click('.coral-plugin-replies-textarea .coral-plugin-commentbox-button') + .waitForElementVisible('.reply', 20000) // Verify that it appears .assert.containsText('.reply', mockReply); @@ -121,22 +121,18 @@ module.exports = { mocks.settings({moderation: 'PRE'}) // Add a mock user - .then(() => { - return mocks.users([{ - displayName: 'Baby Blue', - email: 'whale@tale.sea', - password: 'krill' - }]); - }) + .then(() => mocks.users([{ + displayName: 'Baby Blue', + email: 'whale@tale.sea', + password: 'krill' + }])) // Add a mock preapproved comment by that user - .then((user) => { - return mocks.comments([{ - body: 'Whales are not fish.', - status: 'accepted', - author_id: user.id - }]); - }) + .then((user) => mocks.comments([{ + body: 'Whales are not fish.', + status: 'accepted', + author_id: user.id + }])) .then(() => { // Load Page @@ -169,7 +165,7 @@ module.exports = { // Verify that comment count is correct client.waitForElementVisible('.coral-plugin-comment-count-text', 2000) - .assert.containsText('.coral-plugin-comment-count-text', '2 Comments'); + .assert.containsText('.coral-plugin-comment-count-text', '4 Comments'); done(); }); },