From c2eb586f27ac887e540a3502e12892323900c40d Mon Sep 17 00:00:00 2001 From: Gabriel Grubba <70247653+Grubba27@users.noreply.github.com> Date: Wed, 3 Apr 2024 15:35:40 -0300 Subject: [PATCH 1/2] ci: updates on the ci --- packages/test-in-console/puppeteerRunner.js | 23 +++++++++++++++++++-- packages/tinytest/tinytest.js | 18 ++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/packages/test-in-console/puppeteerRunner.js b/packages/test-in-console/puppeteerRunner.js index 3400986b7f..3181b06bc3 100644 --- a/packages/test-in-console/puppeteerRunner.js +++ b/packages/test-in-console/puppeteerRunner.js @@ -5,11 +5,30 @@ let testNumber = 0; async function runNextUrl(browser) { const page = await browser.newPage(); - page.on('console', msg => { + page.on('console', async msg => { // this is a way to make sure the travis does not timeout // if the test is running for too long without any output to the console (10 minutes) if (msg._text !== undefined) console.log(msg._text); - else console.log(`Test number: ${ testNumber }`); + else { + // sometimes if the test is running in the client we have id: current-client-test with + // the name of the test + const element = await page.$('#current-client-test'); + if (element) { + const currentClientTest = await page.evaluate(element => element.textContent, element); + console.log(`Currently running on the client test: ${ currentClientTest }`) + return; + } + // If we get here is because we have not yet started the test on the client + const currentServerTest = + await page.evaluate(async () => await __Tinytest._getCurrentRunningTestOnServer()); + + if (currentServerTest !== '') { + console.log(`Currently running on the server test: ${ currentServerTest }`); + return; + } + // we were not able to find the name of the test, this is a way to make sure the test is still running + console.log(`Test number: ${ testNumber }`); + } testNumber++; }); diff --git a/packages/tinytest/tinytest.js b/packages/tinytest/tinytest.js index b1315adc59..5bae48ea57 100644 --- a/packages/tinytest/tinytest.js +++ b/packages/tinytest/tinytest.js @@ -531,6 +531,9 @@ export class TestRun { _runTest(test, onComplete, stop_at_offset) { var startTime = (+new Date); + if (Meteor.isServer){ + Tinytest._currentRunningTestNameOnServer = test.name; + } return test.run(event => { /* onEvent */ @@ -671,6 +674,7 @@ export class TestRun { /******************************************************************************/ export const Tinytest = {}; +globalThis.__Tinytest = Tinytest; Tinytest.addAsync = function (name, func, options) { TestManager.addCase(new TestCase(name, func), options); @@ -701,6 +705,20 @@ Tinytest._runTests = function (onReport, onComplete, pathPrefix) { testRun.run(onComplete); }; +Tinytest._currentRunningTestNameOnServer = "" + +Meteor.methods({ + 'tinytest/getCurrentRunningTestName'() { + return Tinytest._currentRunningTestNameOnServer; + } +}) + +// Get current running test from server; +Tinytest._getCurrentRunningTestOnServer = function () { + return Meteor.callAsync('tinytest/getCurrentRunningTestName'); +} + + // Run just one test case, and stop the debugger at a particular // error, all as indicated by 'cookie', which will have come from a // failure event output by _runTests. From 60e2dd67bb1ddbd076db1166a23258425175dc6f Mon Sep 17 00:00:00 2001 From: Gabriel Grubba <70247653+Grubba27@users.noreply.github.com> Date: Wed, 3 Apr 2024 16:04:06 -0300 Subject: [PATCH 2/2] Update to get testname in the client --- packages/test-in-console/puppeteerRunner.js | 14 ++++---------- packages/tinytest/tinytest.js | 12 ++++++------ 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/packages/test-in-console/puppeteerRunner.js b/packages/test-in-console/puppeteerRunner.js index 3181b06bc3..d0a59ae9c9 100644 --- a/packages/test-in-console/puppeteerRunner.js +++ b/packages/test-in-console/puppeteerRunner.js @@ -10,11 +10,10 @@ async function runNextUrl(browser) { // if the test is running for too long without any output to the console (10 minutes) if (msg._text !== undefined) console.log(msg._text); else { - // sometimes if the test is running in the client we have id: current-client-test with - // the name of the test - const element = await page.$('#current-client-test'); - if (element) { - const currentClientTest = await page.evaluate(element => element.textContent, element); + testNumber++; + const currentClientTest = + await page.evaluate(() => __Tinytest._getCurrentRunningTestOnClient()); + if (currentClientTest !== '') { console.log(`Currently running on the client test: ${ currentClientTest }`) return; } @@ -29,7 +28,6 @@ async function runNextUrl(browser) { // we were not able to find the name of the test, this is a way to make sure the test is still running console.log(`Test number: ${ testNumber }`); } - testNumber++; }); if (!process.env.URL) { @@ -42,10 +40,6 @@ async function runNextUrl(browser) { async function poll() { if (await isDone(page)) { let failCount = await getFailCount(page); - console.log(` - The number of tests from Test number may be different because - of the way the test is written. causing the test to fail or - to run more than once. in the console. Test number total: ${ testNumber }`); console.log(`Tests complete with ${ failCount } failures`); console.log(`Tests complete with ${ await getPassCount(page) } passes`); if (failCount > 0) { diff --git a/packages/tinytest/tinytest.js b/packages/tinytest/tinytest.js index 5bae48ea57..3427db1c86 100644 --- a/packages/tinytest/tinytest.js +++ b/packages/tinytest/tinytest.js @@ -531,9 +531,7 @@ export class TestRun { _runTest(test, onComplete, stop_at_offset) { var startTime = (+new Date); - if (Meteor.isServer){ - Tinytest._currentRunningTestNameOnServer = test.name; - } + Tinytest._currentRunningTestName = test.name; return test.run(event => { /* onEvent */ @@ -705,19 +703,21 @@ Tinytest._runTests = function (onReport, onComplete, pathPrefix) { testRun.run(onComplete); }; -Tinytest._currentRunningTestNameOnServer = "" +Tinytest._currentRunningTestName = "" Meteor.methods({ 'tinytest/getCurrentRunningTestName'() { - return Tinytest._currentRunningTestNameOnServer; + return Tinytest._currentRunningTestName; } }) -// Get current running test from server; Tinytest._getCurrentRunningTestOnServer = function () { return Meteor.callAsync('tinytest/getCurrentRunningTestName'); } +Tinytest._getCurrentRunningTestOnClient = function () { + return Tinytest._currentRunningTestName; +} // Run just one test case, and stop the debugger at a particular // error, all as indicated by 'cookie', which will have come from a