Skip to content

Commit

Permalink
use default puppeteer chromium
Browse files Browse the repository at this point in the history
  • Loading branch information
mymindstorm committed Jun 26, 2024
1 parent ab7e15e commit 3d37bea
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions scripts/test-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,28 @@ declare global {
}
}
interface TestDisplay {
[key: string]: TestDisplay | StrippedTestResults
[key: string]: TestDisplay | StrippedTestResults;
}

const colors = {
reset: "\x1b[0m",
green: "\x1b[32m",
red: "\x1b[31m",
}
};

async function runTests() {
const puppeteerArgs: string[] = [
`--load-extension=${path.resolve(__dirname, "../test/chrome")}`,
// for CI
"--no-sandbox",
"--lang=en-US,en"
"--lang=en-US,en",
];

const browser = await puppeteer.launch({
ignoreDefaultArgs: ["--disable-extensions"],
args: puppeteerArgs,
// chrome extensions don't work in headless
headless: false,
executablePath: process.env.PUPPETEER_EXEC_PATH,
});
const mochaPage = await browser.newPage();
await mochaPage.goto(
Expand All @@ -57,27 +56,29 @@ async function runTests() {

// by setting this env var, console logging works for both components and testing
if (process.env.ENABLE_CONSOLE) {
mochaPage.on("console", consoleMessage => console.log(consoleMessage.text()));
mochaPage.on("console", (consoleMessage) =>
console.log(consoleMessage.text())
);
}

const results: {
testResults: MochaTestResults;
} = await mochaPage.evaluate(() => {
return new Promise((resolve: (value: {
testResults: MochaTestResults;
}) => void) => {
window.addEventListener("testsComplete", () => {
resolve({
testResults: window.__mocha_test_results__,
return new Promise(
(resolve: (value: { testResults: MochaTestResults }) => void) => {
window.addEventListener("testsComplete", () => {
resolve({
testResults: window.__mocha_test_results__,
});
});
});

if (window.__mocha_test_results__.completed) {
resolve({
testResults: window.__mocha_test_results__,
});
if (window.__mocha_test_results__.completed) {
resolve({
testResults: window.__mocha_test_results__,
});
}
}
});
);
});

let failedTest = false;
Expand All @@ -86,7 +87,7 @@ async function runTests() {
for (const test of results.testResults.tests) {
let tmp: TestDisplay = {};
test.path.reduce((acc, current, index) => {
return acc[current] = test.path.length - 1 === index ? test : {}
return (acc[current] = test.path.length - 1 === index ? test : {});
}, tmp);
display = merge(display, tmp);
}
Expand All @@ -103,7 +104,7 @@ async function runTests() {
case "failed":
console.log(`${colors.red}${test.title}${colors.reset}`);
if (test.err) {
console.log(test.err)
console.log(test.err);
}
failedTest = true;
break;
Expand All @@ -112,18 +113,18 @@ async function runTests() {
break;
}
} else {
console.log(key)
console.log(key);
console.group();
printDisplayTests(display[key]);
}
}
console.groupEnd();
}
};
printDisplayTests(display);
process.exit(failedTest ? 1 : 0);
}

runTests().catch(e => {
runTests().catch((e) => {
console.error(e);
process.exit(1);
});

0 comments on commit 3d37bea

Please sign in to comment.