Skip to content

Commit 48ffccc

Browse files
AtishayMsftatisjai
andauthored
optimize test runner (#216)
* Change cwd * Optimize test runner --------- Co-authored-by: Atishay Jain (from Dev Box) <[email protected]>
1 parent 6799a95 commit 48ffccc

File tree

5 files changed

+99
-90
lines changed

5 files changed

+99
-90
lines changed

.github/workflows/plotlyTestCoverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ jobs:
138138
cd contrib_repo/apps/plotly_examples
139139
$total_tests = jq '[.suites[].specs[].tests] | length' playwright-report.json
140140
$failures = jq '[.suites[].specs[].tests[] | select(.results[].status == "failed")] | length' playwright-report.json
141-
$failures = [math]::Round($failures / 3, 2)
141+
$failures = [math]::Round($failures / 2, 2)
142142
echo "Total number of tests: $total_tests"
143143
echo "Number of test failures: $failures"
144144
echo "### Test Results" >> $env:GITHUB_STEP_SUMMARY

.github/workflows/plotlyTestCoverage_v9.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ jobs:
137137
cd contrib_repo/apps/plotly_examples
138138
$total_tests = jq '[.suites[].specs[].tests] | length' playwright-report.json
139139
$failures = jq '[.suites[].specs[].tests[] | select(.results[].status == "failed")] | length' playwright-report.json
140-
$failures = [math]::Round($failures / 3, 2)
140+
$failures = [math]::Round($failures / 2, 2)
141141
echo "Total number of tests: $total_tests"
142142
echo "Number of test failures: $failures"
143143
echo "### Test Results" >> $env:GITHUB_STEP_SUMMARY

apps/plotly_examples/playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default defineConfig({
1818
/* Fail the build on CI if you accidentally left test.only in the source code. */
1919
forbidOnly: !!process.env.CI,
2020
/* Retry on CI only */
21-
retries: process.env.CI ? 2 : 0,
21+
retries: process.env.CI ? 1 : 0,
2222
/* Use 4 parallel workers on CI. Default otherwise */
2323
workers: process.env.CI ? 4 : undefined,
2424
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,57 @@
1-
import { test, expect, Locator } from '@playwright/test';
2-
import * as dotenv from 'dotenv';
3-
import { totalChartExamplesCount, chartsListWithErrors, testMatrix } from './test-matrix';
4-
5-
6-
test.beforeEach(async ({ page }) => {
7-
//Pass base URL as part of playwright command
8-
//ex: npx cross-env BASE_URL='https://fluentchartstest-stage.azurewebsites.net/' npx playwright test
9-
//await page.goto(process.env.BASE_URL!);
10-
});
1+
/* eslint-disable no-loop-func */
2+
import { test, expect } from '@playwright/test';
3+
import { chartsListWithErrors, testMatrix } from './test-matrix';
114

125

136
for (const testConfig of testMatrix) {
147
const theme = testConfig.theme;
158
const mode = testConfig.mode;
169
const locale = testConfig.locale;
17-
//test.describe(`Declarative chart examples in ${theme} mode and ${mode} layout`, () => {
18-
for (let index = testConfig.startExampleIndex; index <= testConfig.endExampleIndex; index++) {
19-
const testLocaleName = locale ? `-${locale}` : '';
20-
test(`Declarative chart example ${index + 1}-${theme}-${mode} mode${testLocaleName}` , async ({ browser }) => {
21-
const context = await browser.newContext({ locale: locale });
22-
const page = await context.newPage();
10+
const testLocaleName = locale ? `-${locale}` : '';
11+
test.describe('', () => {
12+
let context;
13+
let page;
14+
15+
test.beforeAll(async ({ browser }) => {
16+
context = await browser.newContext({ locale });
17+
page = await context.newPage();
2318
await page.goto(process.env.BASE_URL!);
24-
const iframe = page.locator('#webpack-dev-server-client-overlay');
25-
if (await iframe.count() > 0) {
26-
await iframe.evaluate((el) => el.remove()).catch(() => {
27-
console.warn("Failed to remove overlay iframe.");
28-
});
29-
}
30-
await page.getByRole('combobox').first().click();
31-
const listbox = page.getByRole('listbox');
32-
await listbox.getByRole('option').locator(`text=${theme}`).click();
33-
const rtlSwitch = page.getByTestId('rtl_switch');
34-
const isCurrentlyRTL = await rtlSwitch.isChecked();
35-
if ((mode === 'RTL' && !isCurrentlyRTL) || (mode === 'LTR' && isCurrentlyRTL)) {
36-
await rtlSwitch.click();
37-
}
38-
const combobox = page.getByRole('combobox');
39-
await combobox.nth(1).click();
40-
const listitems = listbox.last().getByRole('option');
41-
if (!chartsListWithErrors.includes(index)) {
42-
await listitems.nth(index).scrollIntoViewIfNeeded();
43-
await listitems.nth(index).click();
44-
const chart = page.getByTestId('chart-container');
45-
await page.mouse.move(0, 0); // Move mouse to top-left corner
46-
await expect(chart).toHaveScreenshot();
47-
await combobox.last().click();
48-
} else {
49-
test.fail();
50-
}
5119
});
52-
};
20+
21+
test.afterAll(async () => {
22+
await context?.close();
23+
});
24+
//test.describe(`Declarative chart examples in ${theme} mode and ${mode} layout`, () => {
25+
for (let index = testConfig.startExampleIndex; index <= testConfig.endExampleIndex; index++) {
26+
test(`Declarative chart example ${index + 1}-${theme}-${mode} mode${testLocaleName}` , async () => {
27+
const iframe = page.locator('#webpack-dev-server-client-overlay');
28+
if (await iframe.count() > 0) {
29+
await iframe.evaluate((el) => el.remove()).catch(() => {
30+
console.warn("Failed to remove overlay iframe.");
31+
});
32+
}
33+
await page.getByRole('combobox').first().click();
34+
const listbox = page.getByRole('listbox');
35+
await listbox.getByRole('option').locator(`text=${theme}`).click();
36+
const rtlSwitch = page.getByTestId('rtl_switch');
37+
const isCurrentlyRTL = await rtlSwitch.isChecked();
38+
if ((mode === 'RTL' && !isCurrentlyRTL) || (mode === 'LTR' && isCurrentlyRTL)) {
39+
await rtlSwitch.click();
40+
}
41+
const combobox = page.getByRole('combobox');
42+
await combobox.nth(1).click();
43+
const listitems = listbox.last().getByRole('option');
44+
if (!chartsListWithErrors.includes(index)) {
45+
await listitems.nth(index).scrollIntoViewIfNeeded();
46+
await listitems.nth(index).click();
47+
const chart = page.getByTestId('chart-container');
48+
await page.mouse.move(0, 0); // Move mouse to top-left corner
49+
await expect(chart).toHaveScreenshot();
50+
await combobox.last().click();
51+
} else {
52+
test.fail();
53+
}
54+
});
55+
};
56+
});
5357
}
Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,56 @@
1-
import { test, expect, Locator } from '@playwright/test';
2-
import * as dotenv from 'dotenv';
3-
import { totalChartExamplesCount, chartsListWithErrors, testMatrix } from './test-matrix';
4-
5-
test.beforeEach(async ({ page }) => {
6-
//Pass base URL as part of playwright command
7-
//ex: npx cross-env BASE_URL='https://fluentchartstest-stage.azurewebsites.net/' npx playwright test
8-
//await page.goto('http://localhost:3000/');
9-
});
1+
/* eslint-disable no-loop-func */
2+
import { test, expect } from '@playwright/test';
3+
import { chartsListWithErrors, testMatrix } from './test-matrix';
104

115
for (const testConfig of testMatrix) {
126
const theme = testConfig.theme;
137
const mode = testConfig.mode;
148
const locale = testConfig.locale;
15-
//test.describe(`Declarative chart examples in ${theme} mode and ${mode} layout`, () => {
16-
for (let index = testConfig.startExampleIndex; index <= testConfig.endExampleIndex; index++) {
17-
const testLocaleName = locale ? `-${locale}` : '';
18-
test(`Declarative chart example ${index + 1}-${theme}-${mode} mode${testLocaleName}` , async ({ browser }) => {
19-
const context = await browser.newContext({ locale: locale });
20-
const page = await context.newPage();
9+
const testLocaleName = locale ? `-${locale}` : '';
10+
test.describe('', () => {
11+
let context;
12+
let page;
13+
14+
test.beforeAll(async ({ browser }) => {
15+
context = await browser.newContext({ locale });
16+
page = await context.newPage();
2117
await page.goto(process.env.BASE_URL!);
22-
const iframe = page.locator('#webpack-dev-server-client-overlay');
23-
if (await iframe.count() > 0) {
24-
await iframe.evaluate((el) => el.remove()).catch(() => {
25-
console.warn("Failed to remove overlay iframe.");
26-
});
27-
}
28-
await page.getByRole('combobox').first().click();
29-
const listbox = page.getByRole('listbox');
30-
await listbox.getByRole('option').locator(`text=${theme}`).click();
31-
const rtlSwitch = page.getByTestId('rtl_switch');
32-
const isCurrentlyRTL = await rtlSwitch.isChecked();
33-
if ((mode === 'RTL' && !isCurrentlyRTL) || (mode === 'LTR' && isCurrentlyRTL)) {
34-
await rtlSwitch.click();
35-
}
36-
const combobox = page.getByRole('combobox');
37-
await combobox.nth(1).click();
38-
const listitems = listbox.last().getByRole('option');
39-
if (!chartsListWithErrors.includes(index)) {
40-
await listitems.nth(index).scrollIntoViewIfNeeded();
41-
await listitems.nth(index).click();
42-
const chart = page.getByTestId('chart-container-v9');
43-
await page.mouse.move(0, 0); // Move mouse to top-left corner
44-
await expect(chart).toHaveScreenshot();
45-
await combobox.last().click();
46-
} else {
47-
test.fail();
48-
}
4918
});
50-
};
19+
20+
test.afterAll(async () => {
21+
await context?.close();
22+
});
23+
//test.describe(`Declarative chart examples in ${theme} mode and ${mode} layout`, () => {
24+
for (let index = testConfig.startExampleIndex; index <= testConfig.endExampleIndex; index++) {
25+
test(`Declarative chart example ${index + 1}-${theme}-${mode} mode${testLocaleName}` , async () => {
26+
const iframe = page.locator('#webpack-dev-server-client-overlay');
27+
if (await iframe.count() > 0) {
28+
await iframe.evaluate((el) => el.remove()).catch(() => {
29+
console.warn("Failed to remove overlay iframe.");
30+
});
31+
}
32+
await page.getByRole('combobox').first().click();
33+
const listbox = page.getByRole('listbox');
34+
await listbox.getByRole('option').locator(`text=${theme}`).click();
35+
const rtlSwitch = page.getByTestId('rtl_switch');
36+
const isCurrentlyRTL = await rtlSwitch.isChecked();
37+
if ((mode === 'RTL' && !isCurrentlyRTL) || (mode === 'LTR' && isCurrentlyRTL)) {
38+
await rtlSwitch.click();
39+
}
40+
const combobox = page.getByRole('combobox');
41+
await combobox.nth(1).click();
42+
const listitems = listbox.last().getByRole('option');
43+
if (!chartsListWithErrors.includes(index)) {
44+
await listitems.nth(index).scrollIntoViewIfNeeded();
45+
await listitems.nth(index).click();
46+
const chart = page.getByTestId('chart-container-v9');
47+
await page.mouse.move(0, 0); // Move mouse to top-left corner
48+
await expect(chart).toHaveScreenshot();
49+
await combobox.last().click();
50+
} else {
51+
test.fail();
52+
}
53+
});
54+
};
55+
});
5156
}

0 commit comments

Comments
 (0)