2022-05-03 14:58:58 -04:00
|
|
|
/* eslint no-console: "off" */
|
2019-05-20 03:22:50 -04:00
|
|
|
|
2017-12-18 03:32:58 -05:00
|
|
|
const args = process.argv.slice(2);
|
|
|
|
|
|
|
|
if (args.length < 1 || args.length > 2) {
|
2024-02-27 05:25:11 -05:00
|
|
|
console.log("Expecting: node test/smoke-test.mjs {URL}");
|
2017-12-18 03:32:58 -05:00
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const url = args[0];
|
|
|
|
|
|
|
|
console.log(`Starting Discourse Smoke Test for ${url}`);
|
|
|
|
|
2024-02-27 05:25:11 -05:00
|
|
|
import { Launcher } from "chrome-launcher";
|
|
|
|
import path from "path";
|
|
|
|
import puppeteer from "puppeteer-core";
|
2017-12-18 03:32:58 -05:00
|
|
|
|
|
|
|
(async () => {
|
|
|
|
const browser = await puppeteer.launch({
|
2024-02-27 05:25:11 -05:00
|
|
|
executablePath: Launcher.getInstallations()[0],
|
2021-05-20 21:43:47 -04:00
|
|
|
// when debugging locally setting the SHOW_BROWSER env variable can be very helpful
|
2019-10-24 11:51:47 -04:00
|
|
|
headless: process.env.SHOW_BROWSER === undefined,
|
2021-12-13 04:31:49 -05:00
|
|
|
args: ["--disable-local-storage", "--no-sandbox"],
|
2017-12-18 03:32:58 -05:00
|
|
|
});
|
|
|
|
const page = await browser.newPage();
|
|
|
|
|
2018-05-27 22:58:36 -04:00
|
|
|
await page.setViewport({
|
2017-12-18 03:32:58 -05:00
|
|
|
width: 1366,
|
2022-05-03 14:58:58 -04:00
|
|
|
height: 768,
|
2018-05-27 22:58:36 -04:00
|
|
|
});
|
2017-12-18 03:32:58 -05:00
|
|
|
|
2022-05-03 14:58:58 -04:00
|
|
|
const takeFailureScreenshot = function () {
|
|
|
|
const screenshotPath = `${
|
|
|
|
process.env.SMOKE_TEST_SCREENSHOT_PATH || "tmp/smoke-test-screenshots"
|
|
|
|
}/smoke-test-${Date.now()}.png`;
|
2018-05-28 02:19:12 -04:00
|
|
|
console.log(`Screenshot of failure taken at ${screenshotPath}`);
|
|
|
|
return page.screenshot({ path: screenshotPath, fullPage: true });
|
|
|
|
};
|
|
|
|
|
2017-12-18 03:32:58 -05:00
|
|
|
const exec = (description, fn, assertion) => {
|
|
|
|
const start = +new Date();
|
|
|
|
|
2018-09-10 21:16:03 -04:00
|
|
|
return fn
|
|
|
|
.call()
|
2022-05-03 14:58:58 -04:00
|
|
|
.then(async (output) => {
|
2018-09-10 21:16:03 -04:00
|
|
|
if (assertion) {
|
|
|
|
if (assertion.call(this, output)) {
|
|
|
|
console.log(`PASSED: ${description} - ${+new Date() - start}ms`);
|
|
|
|
} else {
|
|
|
|
console.log(`FAILED: ${description} - ${+new Date() - start}ms`);
|
|
|
|
await takeFailureScreenshot();
|
|
|
|
console.log("SMOKE TEST FAILED");
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2017-12-18 03:32:58 -05:00
|
|
|
} else {
|
2018-09-10 21:16:03 -04:00
|
|
|
console.log(`PASSED: ${description} - ${+new Date() - start}ms`);
|
2017-12-18 03:32:58 -05:00
|
|
|
}
|
2018-09-10 21:16:03 -04:00
|
|
|
})
|
2022-05-03 14:58:58 -04:00
|
|
|
.catch(async (error) => {
|
2018-09-10 21:16:03 -04:00
|
|
|
console.log(
|
|
|
|
`ERROR (${description}): ${error.message} - ${+new Date() - start}ms`
|
|
|
|
);
|
|
|
|
await takeFailureScreenshot();
|
|
|
|
console.log("SMOKE TEST FAILED");
|
|
|
|
process.exit(1);
|
|
|
|
});
|
2017-12-18 03:32:58 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
const assert = (description, fn, assertion) => {
|
|
|
|
return exec(description, fn, assertion);
|
|
|
|
};
|
|
|
|
|
2022-05-03 14:58:58 -04:00
|
|
|
page.on("console", (msg) => console.log(`PAGE LOG: ${msg.text()}`));
|
2017-12-18 03:32:58 -05:00
|
|
|
|
2022-05-03 14:58:58 -04:00
|
|
|
page.on("response", (resp) => {
|
2020-05-14 15:04:09 -04:00
|
|
|
if (resp.status() !== 200 && resp.status() !== 302) {
|
2018-09-10 21:16:03 -04:00
|
|
|
console.log(
|
|
|
|
"FAILED HTTP REQUEST TO " + resp.url() + " Status is: " + resp.status()
|
|
|
|
);
|
2022-01-07 03:50:59 -05:00
|
|
|
if (resp.status() === 429) {
|
|
|
|
const headers = resp.headers();
|
|
|
|
console.log("Response headers:");
|
|
|
|
Object.keys(headers).forEach((key) => {
|
|
|
|
console.log(`${key}: ${headers[key]}`);
|
|
|
|
});
|
|
|
|
}
|
2018-05-17 02:00:43 -04:00
|
|
|
}
|
|
|
|
return resp;
|
|
|
|
});
|
|
|
|
|
2018-01-03 01:24:06 -05:00
|
|
|
if (process.env.AUTH_USER && process.env.AUTH_PASSWORD) {
|
|
|
|
await exec("basic authentication", () => {
|
2019-10-23 19:42:26 -04:00
|
|
|
return page.authenticate({
|
|
|
|
username: process.env.AUTH_USER,
|
2022-05-03 14:58:58 -04:00
|
|
|
password: process.env.AUTH_PASSWORD,
|
2018-01-03 01:24:06 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-05-03 14:58:58 -04:00
|
|
|
const login = async function () {
|
2019-11-14 12:24:43 -05:00
|
|
|
await exec("open login modal", () => {
|
|
|
|
return page.click(".login-button");
|
|
|
|
});
|
|
|
|
|
|
|
|
await exec("login modal is open", () => {
|
|
|
|
return page.waitForSelector(".login-modal", { visible: true });
|
|
|
|
});
|
|
|
|
|
|
|
|
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(() => {
|
|
|
|
return page.click(".login-modal .btn-primary");
|
|
|
|
});
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
});
|
|
|
|
|
|
|
|
await exec("is logged in", () => {
|
|
|
|
return page.waitForSelector(".current-user", { visible: true });
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-12-20 21:32:14 -05:00
|
|
|
await exec("go to site", () => {
|
|
|
|
return page.goto(url);
|
|
|
|
});
|
2017-12-18 03:32:58 -05:00
|
|
|
|
|
|
|
await exec("expect a log in button in the header", () => {
|
2020-01-07 07:58:08 -05:00
|
|
|
return page.waitForSelector("header .login-button", { visible: true });
|
2017-12-18 03:32:58 -05:00
|
|
|
});
|
|
|
|
|
2019-11-14 12:24:43 -05:00
|
|
|
if (process.env.LOGIN_AT_BEGINNING) {
|
|
|
|
await login();
|
|
|
|
}
|
|
|
|
|
2017-12-18 03:32:58 -05:00
|
|
|
await exec("go to latest page", () => {
|
2018-09-10 21:16:03 -04:00
|
|
|
return page.goto(path.join(url, "latest"));
|
2017-12-18 03:32:58 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("at least one topic shows up", () => {
|
2017-12-20 08:41:49 -05:00
|
|
|
return page.waitForSelector(".topic-list tbody tr", { visible: true });
|
2017-12-18 03:32:58 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("go to categories page", () => {
|
2018-09-10 21:16:03 -04:00
|
|
|
return page.goto(path.join(url, "categories"));
|
2017-12-18 03:32:58 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("can see categories on the page", () => {
|
2017-12-20 08:41:49 -05:00
|
|
|
return page.waitForSelector(".category-list", { visible: true });
|
2017-12-18 03:32:58 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("navigate to 1st topic", () => {
|
2017-12-20 08:41:49 -05:00
|
|
|
return page.click(".main-link a.title:first-of-type");
|
2017-12-18 03:32:58 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("at least one post body", () => {
|
2017-12-20 08:41:49 -05:00
|
|
|
return page.waitForSelector(".topic-post", { visible: true });
|
2017-12-18 03:32:58 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("click on the 1st user", () => {
|
2017-12-20 08:41:49 -05:00
|
|
|
return page.click(".topic-meta-data a:first-of-type");
|
2017-12-18 03:32:58 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("user has details", () => {
|
2020-02-13 04:58:17 -05:00
|
|
|
return page.waitForSelector(".user-card .names", { visible: true });
|
2017-12-18 03:32:58 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
if (!process.env.READONLY_TESTS) {
|
2019-11-14 12:24:43 -05:00
|
|
|
if (!process.env.LOGIN_AT_BEGINNING) {
|
|
|
|
await login();
|
|
|
|
}
|
2017-12-18 03:32:58 -05:00
|
|
|
|
2019-11-14 12:24:43 -05:00
|
|
|
await exec("go home", () => {
|
2020-01-07 07:54:01 -05:00
|
|
|
let promise = page.waitForSelector("#site-logo, #site-text-logo", {
|
2022-05-03 14:58:58 -04:00
|
|
|
visible: true,
|
2020-01-07 07:54:01 -05:00
|
|
|
});
|
2017-12-18 03:32:58 -05:00
|
|
|
|
|
|
|
promise = promise.then(() => {
|
2019-11-14 12:24:43 -05:00
|
|
|
return page.click("#site-logo, #site-text-logo");
|
2017-12-18 03:32:58 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
});
|
|
|
|
|
|
|
|
await exec("it shows a topic list", () => {
|
2017-12-20 08:41:49 -05:00
|
|
|
return page.waitForSelector(".topic-list", { visible: true });
|
2017-12-18 03:32:58 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("we have a create topic button", () => {
|
2017-12-20 08:41:49 -05:00
|
|
|
return page.waitForSelector("#create-topic", { visible: true });
|
2017-12-18 03:32:58 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("open composer", () => {
|
2017-12-20 08:41:49 -05:00
|
|
|
return page.click("#create-topic");
|
2017-12-18 03:32:58 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("the editor is visible", () => {
|
|
|
|
return page.waitForFunction(
|
2017-12-20 08:41:49 -05:00
|
|
|
"document.activeElement === document.getElementById('reply-title')"
|
2017-12-18 03:32:58 -05:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2019-05-09 02:02:45 -04:00
|
|
|
await page.evaluate(() => {
|
|
|
|
document.getElementById("reply-title").value = "";
|
|
|
|
});
|
|
|
|
|
2017-12-18 03:32:58 -05:00
|
|
|
await exec("compose new topic", () => {
|
2018-09-10 21:16:03 -04:00
|
|
|
const date = `(${+new Date()})`;
|
2017-12-18 03:32:58 -05:00
|
|
|
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 08:41:49 -05:00
|
|
|
return page.waitForSelector(".d-editor-preview p", { visible: true });
|
2017-12-18 03:32:58 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("submit the topic", () => {
|
2017-12-20 08:41:49 -05:00
|
|
|
return page.click(".submit-panel .create");
|
2017-12-18 03:32:58 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("topic is created", () => {
|
2017-12-20 08:41:49 -05:00
|
|
|
return page.waitForSelector(".fancy-title", { visible: true });
|
2017-12-18 03:32:58 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("open the composer", () => {
|
2017-12-20 08:41:49 -05:00
|
|
|
return page.click(".post-controls:first-of-type .create");
|
2017-12-18 03:32:58 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("composer is open", () => {
|
2018-09-10 21:16:03 -04:00
|
|
|
return page.waitForSelector("#reply-control .d-editor-input", {
|
2022-05-03 14:58:58 -04:00
|
|
|
visible: true,
|
2018-09-10 21:16:03 -04:00
|
|
|
});
|
2017-12-18 03:32:58 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("compose reply", () => {
|
2018-09-10 21:16:03 -04:00
|
|
|
const post = `I can even write a reply inside the smoke test ;) (${+new Date()})`;
|
2017-12-18 03:32:58 -05:00
|
|
|
return page.type("#reply-control .d-editor-input", post);
|
|
|
|
});
|
|
|
|
|
2024-02-26 11:03:49 -05:00
|
|
|
await exec("waiting for the preview", async () => {
|
|
|
|
await page.waitForSelector("div.d-editor-preview", {
|
|
|
|
visible: true,
|
|
|
|
});
|
|
|
|
return page.waitForFunction(
|
|
|
|
"document.querySelector('div.d-editor-preview').innerText.includes('I can even write a reply')"
|
2017-12-18 03:32:58 -05:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2019-10-24 12:36:27 -04:00
|
|
|
await exec("wait a little bit", () => {
|
2024-02-26 11:03:49 -05:00
|
|
|
return new Promise((resolve) => setTimeout(resolve, 5000));
|
2019-10-24 12:36:27 -04:00
|
|
|
});
|
|
|
|
|
2019-10-24 11:51:47 -04:00
|
|
|
await exec("submit the reply", () => {
|
|
|
|
let promise = page.click("#reply-control .create");
|
2019-05-21 13:01:29 -04:00
|
|
|
|
2019-10-24 11:51:47 -04:00
|
|
|
promise = promise.then(() => {
|
|
|
|
return page.waitForSelector("#reply-control.closed", {
|
2022-05-03 14:58:58 -04:00
|
|
|
visible: false,
|
2019-10-24 11:51:47 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return promise;
|
2017-12-18 03:32:58 -05:00
|
|
|
});
|
|
|
|
|
2019-10-24 11:51:47 -04:00
|
|
|
await assert("reply is created", () => {
|
|
|
|
let promise = page.waitForSelector(
|
|
|
|
".topic-post:not(.staged) #post_2 .cooked",
|
|
|
|
{
|
2022-05-03 14:58:58 -04:00
|
|
|
visible: true,
|
2019-10-24 11:51:47 -04:00
|
|
|
}
|
|
|
|
);
|
2017-12-18 03:32:58 -05:00
|
|
|
|
2019-10-24 11:51:47 -04:00
|
|
|
promise = promise.then(() => {
|
|
|
|
return page.waitForFunction(
|
|
|
|
"document.querySelector('#post_2 .cooked').innerText.includes('I can even write a reply')"
|
|
|
|
);
|
|
|
|
});
|
2017-12-18 03:32:58 -05:00
|
|
|
|
2019-10-24 11:51:47 -04:00
|
|
|
return promise;
|
|
|
|
});
|
2019-05-21 05:44:30 -04:00
|
|
|
|
2019-10-24 11:51:47 -04:00
|
|
|
await exec("wait a little bit", () => {
|
2024-02-26 11:03:49 -05:00
|
|
|
return new Promise((resolve) => setTimeout(resolve, 5000));
|
2019-10-24 11:51:47 -04:00
|
|
|
});
|
2019-05-21 05:44:30 -04:00
|
|
|
|
|
|
|
await exec("open composer to edit first post", () => {
|
2019-10-24 11:51:47 -04:00
|
|
|
let promise = page.evaluate(() => {
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
});
|
2019-05-21 05:44:30 -04:00
|
|
|
|
2019-10-24 11:51:47 -04:00
|
|
|
promise = promise.then(() => {
|
|
|
|
return page.click("#post_1 .post-controls .edit");
|
2019-05-21 05:44:30 -04:00
|
|
|
});
|
|
|
|
|
2019-10-24 11:51:47 -04:00
|
|
|
promise = promise.then(() => {
|
|
|
|
return page.waitForSelector("#reply-control .d-editor-input", {
|
2022-05-03 14:58:58 -04:00
|
|
|
visible: true,
|
2019-10-24 11:51:47 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
});
|
|
|
|
|
|
|
|
await exec("update post raw in composer", () => {
|
2024-02-26 11:03:49 -05:00
|
|
|
let promise = new Promise((resolve) => setTimeout(resolve, 5000));
|
2019-05-21 05:44:30 -04:00
|
|
|
|
|
|
|
promise = promise.then(() => {
|
2019-10-24 11:51:47 -04:00
|
|
|
return page.type(
|
|
|
|
"#reply-control .d-editor-input",
|
|
|
|
"\n\nI edited this post"
|
|
|
|
);
|
2019-05-21 05:44:30 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
});
|
|
|
|
|
|
|
|
await exec("submit the edit", () => {
|
2019-10-24 11:51:47 -04:00
|
|
|
let promise = page.click("#reply-control .create");
|
2019-05-21 05:44:30 -04:00
|
|
|
|
2019-10-24 11:51:47 -04:00
|
|
|
promise = promise.then(() => {
|
|
|
|
return page.waitForSelector("#reply-control.closed", {
|
2022-05-03 14:58:58 -04:00
|
|
|
visible: false,
|
2019-05-21 05:44:30 -04:00
|
|
|
});
|
2019-10-24 11:51:47 -04:00
|
|
|
});
|
2019-05-21 05:44:30 -04:00
|
|
|
|
2019-10-24 11:51:47 -04:00
|
|
|
return promise;
|
|
|
|
});
|
2019-05-21 05:44:30 -04:00
|
|
|
|
2019-10-24 11:51:47 -04:00
|
|
|
await assert("edit is successful", () => {
|
|
|
|
let promise = page.waitForSelector(
|
|
|
|
".topic-post:not(.staged) #post_1 .cooked",
|
|
|
|
{
|
2022-05-03 14:58:58 -04:00
|
|
|
visible: true,
|
2019-10-24 11:51:47 -04:00
|
|
|
}
|
|
|
|
);
|
2019-05-21 05:44:30 -04:00
|
|
|
|
2019-10-24 11:51:47 -04:00
|
|
|
promise = promise.then(() => {
|
|
|
|
return page.waitForFunction(
|
|
|
|
"document.querySelector('#post_1 .cooked').innerText.includes('I edited this post')"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
});
|
2017-12-18 03:32:58 -05:00
|
|
|
}
|
|
|
|
|
2017-12-22 20:29:22 -05:00
|
|
|
await exec("close browser", () => {
|
|
|
|
return browser.close();
|
|
|
|
});
|
2017-12-18 03:32:58 -05:00
|
|
|
|
|
|
|
console.log("ALL PASSED");
|
|
|
|
})();
|