Skip to content

Commit

Permalink
Merge pull request #288 from recca0120/feat/group-name
Browse files Browse the repository at this point in the history
Feat/group name
  • Loading branch information
recca0120 authored Feb 24, 2025
2 parents 21e3839 + 2b447e5 commit c89aa06
Show file tree
Hide file tree
Showing 34 changed files with 294 additions and 286 deletions.
2 changes: 1 addition & 1 deletion src/PHPUnit/PHPUnitXML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ export class PHPUnitXML {
private readonly cached: Map<string, any> = new Map();

load(text: string | Buffer | Uint8Array, file: string) {
this.element = new Element(parser.parse(text.toString()));
this._file = file;
this.setRoot(dirname(file));
this.element = new Element(parser.parse(text.toString()));

return this;
}
Expand Down
8 changes: 4 additions & 4 deletions src/PHPUnit/ProblemMatcher/TestResultSummaryParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ export class TestResultSummaryParser implements IParser<TestResultSummary> {

return [...text.matchAll(pattern)].reduce(
(result: any, match) => {
const groups = match.groups!;
const [name, count] = groups.name
? [groups.name, groups.count]
: [groups.name2, groups.count2];
const matched = match.groups!;
const [name, count] = matched.name
? [matched.name, matched.count]
: [matched.name2, matched.count2];
result[this.normalize(name)] = parseInt(count, 10);

return result;
Expand Down
6 changes: 3 additions & 3 deletions src/PHPUnit/ProblemMatcher/TestVersionParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export class TestVersionParser implements IParser<TestVersion> {
}

parse(text: string) {
const groups = text.match(this.pattern)!.groups!;
const matched = text.match(this.pattern)!.groups!;

return {
event: TeamcityEvent.testVersion,
phpunit: groups.phpunit,
paratest: groups.paratest,
phpunit: matched.phpunit,
paratest: matched.paratest,
text,
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/PHPUnit/ProblemMatcher/ValueParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export abstract class ValueParser<T> implements IParser<T> {
}

parse(text: string) {
const groups = text.match(this.pattern)!.groups!;
const matched = text.match(this.pattern)!.groups!;

return {
event: this.event,
[this.name.toLowerCase()]: groups[this.name],
[this.name.toLowerCase()]: matched[this.name],
text,
} as T;
}
Expand Down
8 changes: 4 additions & 4 deletions src/PHPUnit/TestCollection/TestCollection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ describe('TestCollection', () => {
return testCollection;
};

const shouldBe = async (collection: TestCollection, group: any) => {
const shouldBe = async (collection: TestCollection, testsuites: any) => {
const phpUnitXML = new PHPUnitXML();
phpUnitXML.setRoot(phpUnitProject(''));
for (const [name, files] of Object.entries(group)) {
for (const [testsuite, files] of Object.entries(testsuites)) {
const expected: TestDefinition[] = [];
for (const uri of (files as URI[])) {
const testParser = new TestParser(phpUnitXML);
testParser.on(TestType.method, (testDefinition) => expected.push(testDefinition));
testParser.on(TestType.class, (testDefinition) => expected.push(testDefinition));
testParser.on(TestType.namespace, (testDefinition) => expected.push(testDefinition));

await testParser.parseFile(uri.fsPath);
await testParser.parseFile(uri.fsPath, testsuite);
}
const actual: TestDefinition[] = [];
collection.items().get(name)?.items().forEach((item) => actual.push(...item));
collection.items().get(testsuite)?.items().forEach((item) => actual.push(...item));
expect(actual).toEqual(expected);
}
};
Expand Down
32 changes: 17 additions & 15 deletions src/PHPUnit/TestCollection/TestCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PHPUnitXML, TestDefinition, TestParser, TestSuite } from '../index';
import { TestDefinitionBuilder } from './TestDefinitionBuilder';

export interface File<T> {
group: string;
testsuite: string;
uri: URI;
tests: T[];
}
Expand Down Expand Up @@ -99,17 +99,17 @@ export class TestCollection {
}

async change(uri: URI) {
const group = this.getGroup(uri);
if (!group) {
const testsuite = this.parseTestsuite(uri);
if (!testsuite) {
return this;
}

const files = this.items();
const testDefinitions = await this.parseTests(uri);
const testDefinitions = await this.parseTests(uri, testsuite);
if (testDefinitions.length === 0) {
this.delete(uri);
}
files.get(group)!.set(uri, testDefinitions);
files.get(testsuite)!.set(uri, testDefinitions);

return this;
}
Expand Down Expand Up @@ -147,9 +147,9 @@ export class TestCollection {
return undefined;
}

protected async parseTests(uri: URI) {
protected async parseTests(uri: URI, testsuite: string) {
const { testParser, testDefinitionBuilder } = this.createTestParser();
await testParser.parseFile(uri.fsPath);
await testParser.parseFile(uri.fsPath, testsuite);

return testDefinitionBuilder.get();
}
Expand All @@ -162,34 +162,36 @@ export class TestCollection {
}

protected deleteFile(file: File<TestDefinition>) {
return this.items().get(file.group)?.delete(file.uri);
return this.items().get(file.testsuite)?.delete(file.uri);
}

private* gatherFiles() {
for (const [group, files] of this.items()) {
for (const [testsuite, files] of this.items()) {
for (const [uri, tests] of files) {
yield { group, uri, tests };
yield { testsuite, uri, tests };
}
}
}

private getGroup(uri: URI) {
private parseTestsuite(uri: URI) {
const testSuites = this.phpUnitXML.getTestSuites();
const group = testSuites.find(item => {
const testsuite = testSuites.find(item => {
return ['directory', 'file'].includes(item.tag) && this.match(item, uri);
});
if (!group) {

if (!testsuite) {
return;
}

const exclude = testSuites.find((item) => {
return item.name === group.name && item.tag === 'exclude' && this.match(item, uri);
return item.name === testsuite.name && item.tag === 'exclude' && this.match(item, uri);
});

if (exclude) {
return;
}

return group.name;
return testsuite.name;
}

private match(testSuite: TestSuite, uri: URI) {
Expand Down
Loading

0 comments on commit c89aa06

Please sign in to comment.