don't use jest and just run test code sequentially

since a lot of tests will be interdepent and need to happen in order,
it seems easier to not use a test runner enforcing tests to be semi-independent
and instead just run the code and have some logging code to see where
a problem occurs
pull/21833/head
Bruno Windels 2018-07-09 17:43:21 +02:00
parent 61ac989847
commit b76c3a1842
3 changed files with 167 additions and 17 deletions

View File

@ -16,28 +16,53 @@ limitations under the License.
const puppeteer = require('puppeteer'); const puppeteer = require('puppeteer');
const helpers = require('./helpers'); const helpers = require('./helpers');
const assert = require('assert');
global.riotserver = 'http://localhost:8080'; global.riotserver = 'http://localhost:8080';
global.homeserver = 'http://localhost:8008'; global.homeserver = 'http://localhost:8008';
global.browser = null; global.browser = null;
jest.setTimeout(10000); async function run_tests() {
await start_session();
beforeAll(async () => { process.stdout.write(`* testing riot loads ... `);
await test_title();
process.stdout.write('done\n');
const username = 'bruno-' + helpers.rnd_int(10000);
const password = 'testtest';
process.stdout.write(`* signing up as ${username} ... `);
await do_signup(username, password, homeserver);
process.stdout.write('done\n');
await end_session();
}
async function start_session() {
global.browser = await puppeteer.launch(); global.browser = await puppeteer.launch();
}); }
afterAll(() => { function end_session() {
return browser.close(); return browser.close();
}) }
test('test page loads', async () => { function on_success() {
console.log('all tests finished successfully');
}
function on_failure(err) {
console.log('failure: ', err);
process.exit(-1);
}
async function test_title() {
const page = await browser.newPage(); const page = await browser.newPage();
await page.goto(helpers.riot_url('/')); await page.goto(helpers.riot_url('/'));
const title = await page.title(); const title = await page.title();
expect(title).toBe("Riot"); assert.strictEqual(title, "Riot");
}); };
test('test signup', async () => { async function do_signup(username, password, homeserver) {
const page = await helpers.new_page(); const page = await helpers.new_page();
const console_logs = helpers.log_console(page); const console_logs = helpers.log_console(page);
const xhr_logs = helpers.log_xhr_requests(page); const xhr_logs = helpers.log_xhr_requests(page);
@ -46,12 +71,10 @@ test('test signup', async () => {
await page.waitForSelector('#advanced', {visible: true, timeout: 500}); await page.waitForSelector('#advanced', {visible: true, timeout: 500});
await page.click('#advanced'); await page.click('#advanced');
const username = 'bruno-' + helpers.rnd_int(10000);
const password = 'testtest';
//fill out form //fill out form
await page.waitForSelector('.mx_ServerConfig', {visible: true, timeout: 500}); await page.waitForSelector('.mx_ServerConfig', {visible: true, timeout: 500});
const login_fields = await page.$$('.mx_Login_field'); const login_fields = await page.$$('.mx_Login_field');
expect(login_fields.length).toBe(7); assert.strictEqual(login_fields.length, 7);
const username_field = login_fields[2]; const username_field = login_fields[2];
const password_field = login_fields[3]; const password_field = login_fields[3];
const password_repeat_field = login_fields[4]; const password_repeat_field = login_fields[4];
@ -70,7 +93,7 @@ test('test signup', async () => {
await register_button.focus(); await register_button.focus();
//check no errors //check no errors
const error_text = await helpers.try_get_innertext(page, '.mx_Login_error'); const error_text = await helpers.try_get_innertext(page, '.mx_Login_error');
expect(error_text).toBeFalsy(); assert.strictEqual(!!error_text, false);
//submit form //submit form
await page.screenshot({path: "beforesubmit.png", fullPage: true}); await page.screenshot({path: "beforesubmit.png", fullPage: true});
await register_button.click(); await register_button.click();
@ -78,7 +101,7 @@ test('test signup', async () => {
//confirm dialog saying you cant log back in without e-mail //confirm dialog saying you cant log back in without e-mail
await page.waitForSelector('.mx_QuestionDialog', {visible: true, timeout: 500}); await page.waitForSelector('.mx_QuestionDialog', {visible: true, timeout: 500});
const continue_button = await page.$('.mx_QuestionDialog button.mx_Dialog_primary'); const continue_button = await page.$('.mx_QuestionDialog button.mx_Dialog_primary');
await helpers.print_elements('continue_button', [continue_button]); //await helpers.print_elements('continue_button', [continue_button]);
await continue_button.click(); await continue_button.click();
//wait for registration to finish so the hash gets set //wait for registration to finish so the hash gets set
//onhashchange better? //onhashchange better?
@ -97,5 +120,7 @@ test('test signup', async () => {
//await page.waitForSelector('.mx_MatrixChat', {visible: true, timeout: 3000}); //await page.waitForSelector('.mx_MatrixChat', {visible: true, timeout: 3000});
const url = page.url(); const url = page.url();
expect(url).toBe(helpers.riot_url('/#/home')); assert.strictEqual(url, helpers.riot_url('/#/home'));
}); };
run_tests().then(on_success, on_failure);

View File

@ -9,7 +9,6 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"jest": "^23.2.0",
"puppeteer": "^1.5.0" "puppeteer": "^1.5.0"
} }
} }

126
start.js Normal file
View File

@ -0,0 +1,126 @@
/*
Copyright 2018 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
const puppeteer = require('puppeteer');
const helpers = require('./helpers');
const assert = require('assert');
global.riotserver = 'http://localhost:8080';
global.homeserver = 'http://localhost:8008';
global.browser = null;
async function run_tests() {
await start_session();
process.stdout.write(`* testing riot loads ... `);
await test_title();
process.stdout.write('done\n');
const username = 'bruno-' + helpers.rnd_int(10000);
const password = 'testtest';
process.stdout.write(`* signing up as ${username} ... `);
await do_signup(username, password, homeserver);
process.stdout.write('done\n');
await end_session();
}
async function start_session() {
global.browser = await puppeteer.launch();
}
function end_session() {
return browser.close();
}
function on_success() {
console.log('all tests finished successfully');
}
function on_failure(err) {
console.log('failure: ', err);
process.exit(-1);
}
async function test_title() {
const page = await browser.newPage();
await page.goto(helpers.riot_url('/'));
const title = await page.title();
assert.strictEqual(title, "Riot");
};
async function do_signup(username, password, homeserver) {
const page = await helpers.new_page();
const console_logs = helpers.log_console(page);
const xhr_logs = helpers.log_xhr_requests(page);
await page.goto(helpers.riot_url('/#/register'));
//click 'Custom server' radio button
await page.waitForSelector('#advanced', {visible: true, timeout: 500});
await page.click('#advanced');
//fill out form
await page.waitForSelector('.mx_ServerConfig', {visible: true, timeout: 500});
const login_fields = await page.$$('.mx_Login_field');
assert.strictEqual(login_fields.length, 7);
const username_field = login_fields[2];
const password_field = login_fields[3];
const password_repeat_field = login_fields[4];
const hsurl_field = login_fields[5];
await helpers.replace_input_text(username_field, username);
await helpers.replace_input_text(password_field, password);
await helpers.replace_input_text(password_repeat_field, password);
await helpers.replace_input_text(hsurl_field, homeserver);
//wait over a second because Registration/ServerConfig have a 1000ms
//delay to internally set the homeserver url
//see Registration::render and ServerConfig::props::delayTimeMs
await helpers.delay(1200);
/// focus on the button to make sure error validation
/// has happened before checking the form is good to go
const register_button = await page.$('.mx_Login_submit');
await register_button.focus();
//check no errors
const error_text = await helpers.try_get_innertext(page, '.mx_Login_error');
assert.strictEqual(!!error_text, false);
//submit form
await page.screenshot({path: "beforesubmit.png", fullPage: true});
await register_button.click();
//confirm dialog saying you cant log back in without e-mail
await page.waitForSelector('.mx_QuestionDialog', {visible: true, timeout: 500});
const continue_button = await page.$('.mx_QuestionDialog button.mx_Dialog_primary');
//await helpers.print_elements('continue_button', [continue_button]);
await continue_button.click();
//wait for registration to finish so the hash gets set
//onhashchange better?
await helpers.delay(1000);
/*
await page.screenshot({path: "afterlogin.png", fullPage: true});
console.log('browser console logs:');
console.log(console_logs.logs());
console.log('xhr logs:');
console.log(xhr_logs.logs());
*/
//print_elements('page', await page.$('#matrixchat'));
// await navigation_promise;
//await page.waitForSelector('.mx_MatrixChat', {visible: true, timeout: 3000});
const url = page.url();
assert.strictEqual(url, helpers.riot_url('/#/home'));
};
run_tests().then(on_success, on_failure);