Apply prettier.

This commit is contained in:
Guo Xiang Tan 2018-09-11 09:16:03 +08:00
parent 51edb19aa9
commit 4ee8e77073
1 changed files with 65 additions and 42 deletions

View File

@ -9,8 +9,8 @@ const url = args[0];
console.log(`Starting Discourse Smoke Test for ${url}`);
const puppeteer = require('puppeteer');
const path = require('path');
const puppeteer = require("puppeteer");
const path = require("path");
(async () => {
const browser = await puppeteer.launch({
@ -26,7 +26,8 @@ const path = require('path');
});
const takeFailureScreenshot = function() {
const screenshotPath = `${process.env.SMOKE_TEST_SCREENSHOT_PATH || 'tmp/smoke-test-screenshots'}/smoke-test-${Date.now()}.png`;
const screenshotPath = `${process.env.SMOKE_TEST_SCREENSHOT_PATH ||
"tmp/smoke-test-screenshots"}/smoke-test-${Date.now()}.png`;
console.log(`Screenshot of failure taken at ${screenshotPath}`);
return page.screenshot({ path: screenshotPath, fullPage: true });
};
@ -34,36 +35,43 @@ const path = require('path');
const exec = (description, fn, assertion) => {
const start = +new Date();
return fn.call().then(async output => {
if (assertion) {
if (assertion.call(this, output)) {
console.log(`PASSED: ${description} - ${(+new Date()) - start}ms`);
return fn
.call()
.then(async 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`);
await takeFailureScreenshot();
console.log("SMOKE TEST FAILED");
process.exit(1);
}
} else {
console.log(`FAILED: ${description} - ${(+new Date()) - start}ms`);
await takeFailureScreenshot();
console.log("SMOKE TEST FAILED");
process.exit(1);
console.log(`PASSED: ${description} - ${+new Date() - start}ms`);
}
} else {
console.log(`PASSED: ${description} - ${(+new Date()) - start}ms`);
}
}).catch(async error => {
console.log(`ERROR (${description}): ${error.message} - ${(+new Date()) - start}ms`);
await takeFailureScreenshot();
console.log("SMOKE TEST FAILED");
process.exit(1);
});
})
.catch(async error => {
console.log(
`ERROR (${description}): ${error.message} - ${+new Date() - start}ms`
);
await takeFailureScreenshot();
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()}`));
page.on("console", msg => console.log(`PAGE LOG: ${msg.text()}`));
page.on('response', resp => {
page.on("response", resp => {
if (resp.status() !== 200) {
console.log("FAILED HTTP REQUEST TO " + resp.url() + " Status is: " + resp.status());
console.log(
"FAILED HTTP REQUEST TO " + resp.url() + " Status is: " + resp.status()
);
}
return resp;
});
@ -71,7 +79,9 @@ const path = require('path');
if (process.env.AUTH_USER && process.env.AUTH_PASSWORD) {
await exec("basic authentication", () => {
return page.setExtraHTTPHeaders({
'Authorization': `Basic ${new Buffer(`${process.env.AUTH_USER}:${process.env.AUTH_PASSWORD}`).toString('base64')}`
Authorization: `Basic ${new Buffer(
`${process.env.AUTH_USER}:${process.env.AUTH_PASSWORD}`
).toString("base64")}`
});
});
}
@ -85,7 +95,7 @@ const path = require('path');
});
await exec("go to latest page", () => {
return page.goto(path.join(url, 'latest'));
return page.goto(path.join(url, "latest"));
});
await exec("at least one topic shows up", () => {
@ -93,7 +103,7 @@ const path = require('path');
});
await exec("go to categories page", () => {
return page.goto(path.join(url, 'categories'));
return page.goto(path.join(url, "categories"));
});
await exec("can see categories on the page", () => {
@ -126,10 +136,16 @@ const path = require('path');
});
await exec("type in credentials & log in", () => {
let promise = page.type("#login-account-name", process.env.DISCOURSE_USERNAME || 'smoke_user');
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');
return page.type(
"#login-account-password",
process.env.DISCOURSE_PASSWORD || "P4ssw0rd"
);
});
promise = promise.then(() => {
@ -166,7 +182,7 @@ const path = require('path');
});
await exec("compose new topic", () => {
const date = `(${(+new Date())})`;
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`;
@ -210,16 +226,19 @@ const path = require('path');
});
await exec("composer is open", () => {
return page.waitForSelector("#reply-control .d-editor-input", { visible: true });
return page.waitForSelector("#reply-control .d-editor-input", {
visible: true
});
});
await exec("compose reply", () => {
const post = `I can even write a reply inside the smoke test ;) (${(+new Date())})`;
const post = `I can even write a reply inside the smoke test ;) (${+new Date()})`;
return page.type("#reply-control .d-editor-input", post);
});
await exec("waiting for the preview", () => {
return page.waitForXPath("//div[contains(@class, 'd-editor-preview') and contains(.//p, 'I can even write a reply')]",
return page.waitForXPath(
"//div[contains(@class, 'd-editor-preview') and contains(.//p, 'I can even write a reply')]",
{ visible: true }
);
});
@ -228,19 +247,23 @@ const path = require('path');
return page.click("#reply-control .create");
});
await assert("reply is created", () => {
let promise = page.waitForSelector(".topic-post");
await assert(
"reply is created",
() => {
let promise = page.waitForSelector(".topic-post");
promise = promise.then(() => {
return page.evaluate(() => {
return document.querySelectorAll(".topic-post").length;
promise = promise.then(() => {
return page.evaluate(() => {
return document.querySelectorAll(".topic-post").length;
});
});
});
return promise;
}, output => {
return output === 2;
});
return promise;
},
output => {
return output === 2;
}
);
}
await exec("close browser", () => {