fix reporter-junit.spec.ts due to sharding

This commit is contained in:
Mathias Leppich 2024-05-22 19:58:40 +02:00
parent 59c625e56a
commit d3b4fada1a

View file

@ -14,10 +14,10 @@
* limitations under the License. * limitations under the License.
*/ */
import xml2js from 'xml2js';
import path from 'path';
import { test, expect } from './playwright-test-fixtures';
import fs from 'fs'; import fs from 'fs';
import path from 'path';
import xml2js from 'xml2js';
import { expect, test } from './playwright-test-fixtures';
for (const useIntermediateMergeReport of [false, true] as const) { for (const useIntermediateMergeReport of [false, true] as const) {
test.describe(`${useIntermediateMergeReport ? 'merged' : 'created'}`, () => { test.describe(`${useIntermediateMergeReport ? 'merged' : 'created'}`, () => {
@ -190,8 +190,8 @@ for (const useIntermediateMergeReport of [false, true] as const) {
expect(result.exitCode).toBe(0); expect(result.exitCode).toBe(0);
}); });
test('should report skipped due to sharding', async ({ runInlineTest }) => { test('should not report skipped due to sharding', async ({ runInlineTest }) => {
const result = await runInlineTest({ const tests = {
'a.test.js': ` 'a.test.js': `
import { test, expect } from '@playwright/test'; import { test, expect } from '@playwright/test';
test('one', async () => { test('one', async () => {
@ -210,13 +210,34 @@ for (const useIntermediateMergeReport of [false, true] as const) {
test('five', async () => { test('five', async () => {
}); });
`, `,
}, { shard: '1/3', reporter: 'junit' }); };
const xml = parseXML(result.output); {
expect(xml['testsuites']['testsuite'].length).toBe(1); const result = await runInlineTest(tests, { shard: '1/3', reporter: 'junit' });
expect(xml['testsuites']['testsuite'][0]['$']['tests']).toBe('2'); const xml = parseXML(result.output);
expect(xml['testsuites']['testsuite'][0]['$']['failures']).toBe('0'); expect(xml['testsuites']['testsuite'].length).toBe(1);
expect(xml['testsuites']['testsuite'][0]['$']['skipped']).toBe('1'); expect(xml['testsuites']['testsuite'][0]['$']['tests']).toBe('3');
expect(result.exitCode).toBe(0); expect(xml['testsuites']['testsuite'][0]['$']['failures']).toBe('0');
expect(xml['testsuites']['testsuite'][0]['$']['skipped']).toBe('1');
expect(result.exitCode).toBe(0);
}
{
const result = await runInlineTest(tests, { shard: '2/3', reporter: 'junit' });
const xml = parseXML(result.output);
expect(xml['testsuites']['testsuite'].length).toBe(1);
expect(xml['testsuites']['testsuite'][0]['$']['tests']).toBe('2');
expect(xml['testsuites']['testsuite'][0]['$']['failures']).toBe('0');
expect(xml['testsuites']['testsuite'][0]['$']['skipped']).toBe('1');
expect(result.exitCode).toBe(0);
}
{
const result = await runInlineTest(tests, { shard: '3/3', reporter: 'junit' });
const xml = parseXML(result.output);
expect(xml['testsuites']['testsuite']).toBe(undefined);
expect(xml['testsuites']['$']['tests']).toBe('0');
expect(xml['testsuites']['$']['failures']).toBe('0');
expect(xml['testsuites']['$']['skipped']).toBe('0');
expect(result.exitCode).toBe(0);
}
}); });
test('should not render projects if they dont exist', async ({ runInlineTest }) => { test('should not render projects if they dont exist', async ({ runInlineTest }) => {
@ -560,4 +581,4 @@ for (const useIntermediateMergeReport of [false, true] as const) {
expect(time).toBeGreaterThan(1); expect(time).toBeGreaterThan(1);
}); });
}); });
} }