From df77cdd5fed3958710faf595c71736c74540388a Mon Sep 17 00:00:00 2001 From: Muhammed Mustafa Date: Mon, 28 Nov 2022 17:27:34 +0530 Subject: [PATCH] feat(test): Added stress testing which will run added/modified tests in the PR multiple times --- tests/playwright/.gitignore | 1 + .../scripts/stressTestNewlyAddedTest.js | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/playwright/scripts/stressTestNewlyAddedTest.js diff --git a/tests/playwright/.gitignore b/tests/playwright/.gitignore index 63c301ee05..3e0dc550b2 100644 --- a/tests/playwright/.gitignore +++ b/tests/playwright/.gitignore @@ -3,6 +3,7 @@ node_modules/ /playwright-report/ /playwright-report copy/ /playwright-report-quick/ +/playwright-report-stress/ /playwright/.cache/ .env output diff --git a/tests/playwright/scripts/stressTestNewlyAddedTest.js b/tests/playwright/scripts/stressTestNewlyAddedTest.js new file mode 100644 index 0000000000..6e37eafb81 --- /dev/null +++ b/tests/playwright/scripts/stressTestNewlyAddedTest.js @@ -0,0 +1,26 @@ +// eslint-disable-next-line no-undef +const util = require('util'); +// eslint-disable-next-line no-undef +const exec = util.promisify(require('child_process').exec); +// Get items from `git diff develop' + +void (async () => { + const { stdout } = await exec(`git diff develop | grep test\\(`); + // eslint-disable-next-line no-undef + const dbType = process.env.E2E_DB_TYPE; + + // get test names which is in the form of `+ test('test name', () => {' + const testNames = stdout + .match(/\+ {2}test\('(.*)',/g) + // extract test name by removing `+ test('` and `',*` + .map(testName => testName.replace("test('", '').trimEnd().slice(0, -2).slice(1, testName.length).trim()); + console.log({ dbType, testNames }); + + // run all the tests by title using regex with exact match + const { stdout: pwStdout } = await exec( + `PLAYWRIGHT_HTML_REPORT=playwright-report-stress E2E_DB_TYPE=${dbType} npx playwright test --repeat-each=2 --workers=2 -g "${testNames.join( + '|' + )}"` + ); + console.log('pwStdout:', pwStdout); +})();