2017-12-18 16:32:58 +08:00
|
|
|
const args = process.argv.slice(2);
|
|
|
|
|
|
|
|
if (args.length < 1 || args.length > 2) {
|
|
|
|
console.log("Expecting: node {smoke_test.js} {url}");
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const url = args[0];
|
|
|
|
|
|
|
|
console.log(`Starting Discourse Smoke Test for ${url}`);
|
|
|
|
|
|
|
|
const puppeteer = require('puppeteer');
|
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
(async () => {
|
|
|
|
const browser = await puppeteer.launch({
|
|
|
|
// headless: false,
|
|
|
|
// slowMo: 10,
|
|
|
|
args: ["--disable-local-storage"]
|
|
|
|
});
|
|
|
|
const page = await browser.newPage();
|
|
|
|
|
|
|
|
page.setViewport = {
|
|
|
|
width: 1366,
|
|
|
|
height: 768
|
|
|
|
};
|
|
|
|
|
|
|
|
const exec = (description, fn, assertion) => {
|
|
|
|
const start = +new Date();
|
|
|
|
|
|
|
|
return fn.call().then(output => {
|
|
|
|
if (assertion) {
|
|
|
|
if (assertion.call(this, output)) {
|
|
|
|
console.log(`PASSED: ${description} - ${(+new Date()) - start}ms`);
|
|
|
|
} else {
|
|
|
|
console.log(`FAILED: ${description} - ${(+new Date()) - start}ms`);
|
|
|
|
console.log("SMOKE TEST FAILED");
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
console.log(`PASSED: ${description} - ${(+new Date()) - start}ms`);
|
|
|
|
}
|
|
|
|
}).catch(error => {
|
|
|
|
console.log(`ERROR (${description}): ${error.message} - ${(+new Date()) - start}ms`);
|
|
|
|
console.log("SMOKE TEST FAILED");
|
|
|
|
process.exit(1);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const assert = (description, fn, assertion) => {
|
|
|
|
return exec(description, fn, assertion);
|
|
|
|
};
|
|
|
|
|
|
|
|
page.on('console', msg => console.log(`PAGE LOG: ${msg.text}`));
|
|
|
|
|
2018-01-03 14:24:06 +08:00
|
|
|
if (process.env.AUTH_USER && process.env.AUTH_PASSWORD) {
|
|
|
|
await exec("basic authentication", () => {
|
2018-01-04 21:30:04 +08:00
|
|
|
return page.setExtraHTTPHeaders({
|
|
|
|
'Authorization': `Basic ${new Buffer(`${process.env.AUTH_USER}:${process.env.AUTH_PASSWORD}`).toString('base64')}`
|
2018-01-03 14:24:06 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-12-21 10:32:14 +08:00
|
|
|
await exec("go to site", () => {
|
|
|
|
return page.goto(url);
|
|
|
|
});
|
2017-12-18 16:32:58 +08:00
|
|
|
|
|
|
|
await exec("expect a log in button in the header", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.waitForSelector("header .login-button", { visible: true });
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("go to latest page", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.goto(path.join(url, 'latest'));
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("at least one topic shows up", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.waitForSelector(".topic-list tbody tr", { visible: true });
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("go to categories page", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.goto(path.join(url, 'categories'));
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("can see categories on the page", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.waitForSelector(".category-list", { visible: true });
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("navigate to 1st topic", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.click(".main-link a.title:first-of-type");
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("at least one post body", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.waitForSelector(".topic-post", { visible: true });
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("click on the 1st user", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.click(".topic-meta-data a:first-of-type");
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("user has details", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.waitForSelector("#user-card .names", { visible: true });
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
if (!process.env.READONLY_TESTS) {
|
|
|
|
await exec("open login modal", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.click(".login-button");
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("login modal is open", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.waitForSelector(".login-modal", { visible: true });
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("type in credentials & log in", () => {
|
|
|
|
let promise = page.type("#login-account-name", process.env.DISCOURSE_USERNAME || 'smoke_user');
|
|
|
|
|
|
|
|
promise = promise.then(() => {
|
|
|
|
return page.type("#login-account-password", process.env.DISCOURSE_PASSWORD || 'P4ssw0rd');
|
|
|
|
});
|
|
|
|
|
|
|
|
promise = promise.then(() => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.click(".login-modal .btn-primary");
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
});
|
|
|
|
|
|
|
|
await exec("is logged in", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.waitForSelector(".current-user", { visible: true });
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("go home", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.click("#site-logo, #site-text-logo");
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("it shows a topic list", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.waitForSelector(".topic-list", { visible: true });
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("we have a create topic button", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.waitForSelector("#create-topic", { visible: true });
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("open composer", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.click("#create-topic");
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("the editor is visible", () => {
|
|
|
|
return page.waitForFunction(
|
2017-12-20 21:41:49 +08:00
|
|
|
"document.activeElement === document.getElementById('reply-title')"
|
2017-12-18 16:32:58 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
await exec("compose new topic", () => {
|
|
|
|
const date = `(${(+new Date())})`;
|
|
|
|
const title = `This is a new topic ${date}`;
|
|
|
|
const post = `I can write a new topic inside the smoke test! ${date} \n\n`;
|
|
|
|
|
|
|
|
let promise = page.type("#reply-title", title);
|
|
|
|
|
|
|
|
promise = promise.then(() => {
|
|
|
|
return page.type("#reply-control .d-editor-input", post);
|
|
|
|
});
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
});
|
|
|
|
|
|
|
|
await exec("updates preview", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.waitForSelector(".d-editor-preview p", { visible: true });
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("open upload modal", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.click(".d-editor-button-bar .upload");
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("upload modal is open", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
let promise = page.waitForSelector("#filename-input", { visible: true });
|
2017-12-18 16:32:58 +08:00
|
|
|
|
|
|
|
promise.then(() => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.click(".d-modal-cancel");
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
});
|
|
|
|
|
|
|
|
await exec("submit the topic", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.click(".submit-panel .create");
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("topic is created", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.waitForSelector(".fancy-title", { visible: true });
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("open the composer", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.click(".post-controls:first-of-type .create");
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("composer is open", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.waitForSelector("#reply-control .d-editor-input", { visible: true });
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("compose reply", () => {
|
|
|
|
const post = `I can even write a reply inside the smoke test ;) (${(+new Date())})`;
|
|
|
|
return page.type("#reply-control .d-editor-input", post);
|
|
|
|
});
|
|
|
|
|
|
|
|
await assert("waiting for the preview", () => {
|
|
|
|
let promise = page.waitForSelector(".d-editor-preview p",
|
2017-12-20 21:41:49 +08:00
|
|
|
{ visible: true }
|
2017-12-18 16:32:58 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
promise = promise.then(() => {
|
|
|
|
return page.evaluate(() => {
|
|
|
|
return document.querySelector(".d-editor-preview").innerText;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
}, output => {
|
|
|
|
return output.match("I can even write a reply");
|
|
|
|
});
|
|
|
|
|
|
|
|
await exec("submit the topic", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.click("#reply-control .create");
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await assert("reply is created", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
let promise = page.waitForSelector(".topic-post");
|
2017-12-18 16:32:58 +08:00
|
|
|
|
|
|
|
promise = promise.then(() => {
|
|
|
|
return page.evaluate(() => {
|
|
|
|
return document.querySelectorAll(".topic-post").length;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
}, output => {
|
|
|
|
return output === 2;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-12-23 09:29:22 +08:00
|
|
|
await exec("close browser", () => {
|
|
|
|
return browser.close();
|
|
|
|
});
|
2017-12-18 16:32:58 +08:00
|
|
|
|
|
|
|
console.log("ALL PASSED");
|
|
|
|
})();
|