Skip to content

Commit

Permalink
Merge pull request #261 from recca0120/fix/pest-v2-dataset
Browse files Browse the repository at this point in the history
Fix/pest v2 dataset
  • Loading branch information
recca0120 authored Jan 7, 2025
2 parents 69df083 + d4d6d27 commit 965613b
Show file tree
Hide file tree
Showing 28 changed files with 418 additions and 68 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"displayName": "PHPUnit Test Explorer",
"icon": "img/icon.png",
"publisher": "recca0120",
"version": "3.5.11",
"version": "3.5.12",
"private": true,
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion src/Observers/Printers/CollisionPrinter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFileSync } from 'node:fs';
import { EOL, TestFailed, TestFinished, TestIgnored, TeamcityEvent, TestSuiteFinished } from '../../PHPUnit';
import { EOL, TeamcityEvent, TestFailed, TestFinished, TestIgnored, TestSuiteFinished } from '../../PHPUnit';
import { Printer } from './Printer';

export class CollisionPrinter extends Printer {
Expand Down
2 changes: 1 addition & 1 deletion src/Observers/Printers/PrettyPrinter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EOL, TestFailed, TestFinished, TeamcityEvent, TestSuiteFinished } from '../../PHPUnit';
import { EOL, TeamcityEvent, TestFailed, TestFinished, TestSuiteFinished } from '../../PHPUnit';
import { Printer } from './Printer';

export class PrettyPrinter extends Printer {
Expand Down
2 changes: 1 addition & 1 deletion src/Observers/Printers/Printer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
EOL, TestConfiguration, TestDuration, TestFailed, TestFinished, TestProcesses, TestResult, TeamcityEvent,
EOL, TeamcityEvent, TestConfiguration, TestDuration, TestFailed, TestFinished, TestProcesses, TestResult,
TestResultSummary, TestRuntime, TestStarted, TestSuiteFinished, TestSuiteStarted, TestVersion,
} from '../../PHPUnit';

Expand Down
15 changes: 12 additions & 3 deletions src/Observers/TestResultObserver.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Location, Position, Range, TestItem, TestMessage, TestMessageStackFrame, TestRun } from 'vscode';
import { URI } from 'vscode-uri';
import {
EOL, TestFailed, TestFinished, TestIgnored, TestResult, TestRunnerObserver, TestStarted, TestSuiteFinished,
TestSuiteStarted,
EOL, PestTransformer, TestFailed, TestFinished, TestIgnored, TestResult, TestRunnerObserver, TestStarted,
TestSuiteFinished, TestSuiteStarted,
} from '../PHPUnit';
import { TestCase } from '../TestCollection';

Expand Down Expand Up @@ -82,7 +82,16 @@ export class TestResultObserver implements TestRunnerObserver {
private find(result: TestResult) {
if ('id' in result) {
for (const [_, testItem] of this.queue) {
if (testItem.id === result.id) {
if (result.id === testItem.id) {
return testItem;
}

if (!PestTransformer.hasPrefix(result.id)) {
continue;
}

const pestId = PestTransformer.pestId(testItem.id);
if (pestId === result.id) {
return testItem;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/PHPUnit/ProblemMatcher/PestProblemMatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ describe('Pest ProblemMatcher Text', () => {
it('pest-v2 data set', () => {
resultShouldBe(`##teamcity[testSuiteStarted name='Tests\\Unit\\ExampleTest::__pest_evaluable_it_has_emails' locationHint='file://tests/Unit/ExampleTest.php' flowId='57317']`, {
event: TeamcityEvent.testSuiteStarted,
id: 'tests/Unit/ExampleTest.php::it has emails',
id: 'Tests\\Unit\\ExampleTest::__pest_evaluable_it_has_emails',
name: 'Tests\\Unit\\ExampleTest::__pest_evaluable_it_has_emails',
file: 'tests/Unit/ExampleTest.php',
flowId: 57317,
Expand Down Expand Up @@ -524,7 +524,7 @@ describe('Pest ProblemMatcher Text', () => {

resultShouldBe(`##teamcity[testSuiteFinished name='Tests\\Unit\\ExampleTest::__pest_evaluable_it_has_emails' flowId='57317']`, {
event: TeamcityEvent.testSuiteFinished,
id: 'tests/Unit/ExampleTest.php::it has emails',
id: 'Tests\\Unit\\ExampleTest::__pest_evaluable_it_has_emails',
name: 'Tests\\Unit\\ExampleTest::__pest_evaluable_it_has_emails',
file: 'tests/Unit/ExampleTest.php',
flowId: 57317,
Expand Down
6 changes: 3 additions & 3 deletions src/PHPUnit/ProblemMatcher/ProblemMatcher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
TestFailed, TestFinished, TestIgnored, TestResult, TeamcityEvent, TestResultParser, TestStarted,
TestSuiteFinished, TestSuiteStarted,
TeamcityEvent, TestFailed, TestFinished, TestIgnored, TestResult, TestResultParser, TestStarted, TestSuiteFinished,
TestSuiteStarted,
} from '.';

export class ProblemMatcher {
Expand All @@ -24,7 +24,7 @@ export class ProblemMatcher {
}

private isResult(result?: TestResult): boolean {
return !!(result && 'event' in result && 'name' in result && 'flowId' in result);
return !!result && 'event' in result && 'name' in result && 'flowId' in result;
}

private handleStarted(testResult: TestSuiteStarted | TestStarted) {
Expand Down
2 changes: 1 addition & 1 deletion src/PHPUnit/ProblemMatcher/TestConfigurationParser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TestConfiguration, TeamcityEvent } from './types';
import { TeamcityEvent, TestConfiguration } from './types';
import { ValueParser } from './ValueParser';

export class TestConfigurationParser extends ValueParser<TestConfiguration> {
Expand Down
2 changes: 1 addition & 1 deletion src/PHPUnit/ProblemMatcher/TestDurationParser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TestDuration, TeamcityEvent } from './types';
import { TeamcityEvent, TestDuration } from './types';
import { IParser } from './ValueParser';

export class TestDurationParser implements IParser<TestDuration> {
Expand Down
2 changes: 1 addition & 1 deletion src/PHPUnit/ProblemMatcher/TestProcessesParser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TestProcesses, TeamcityEvent } from './types';
import { TeamcityEvent, TestProcesses } from './types';
import { ValueParser } from './ValueParser';

export class TestProcessesParser extends ValueParser<TestProcesses> {
Expand Down
3 changes: 2 additions & 1 deletion src/PHPUnit/TestCollection/TestDefinitionBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TestDefinition, TestParser, TestType } from '../TestParser';
import { TestParser } from '../TestParser';
import { TestDefinition, TestType } from '../types';

export class TestDefinitionBuilder {
private readonly testDefinitions: TestDefinition[] = [];
Expand Down
8 changes: 1 addition & 7 deletions src/PHPUnit/TestParser/AnnotationParser.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import { Declaration, Method } from 'php-parser';
import { Annotations } from '../types';

const lookup = ['depends', 'dataProvider', 'testdox'];

export type Annotations = {
[p: string]: unknown;
depends?: string[];
dataProvider?: string[];
testdox?: string[];
};

export class AttributeParser {
public parse(declaration: Declaration) {
const parsed = this.parseAttributes(declaration);
Expand Down
2 changes: 1 addition & 1 deletion src/PHPUnit/TestParser/PHPUnitParser.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFile } from 'fs/promises';
import { phpUnitProject } from '../__tests__/utils';
import { TestDefinition, TestType } from '../types';
import { TestParser } from './TestParser';
import { TestDefinition, TestType } from './types';

export const parse = (buffer: Buffer | string, file: string) => {
const tests: TestDefinition[] = [];
Expand Down
4 changes: 2 additions & 2 deletions src/PHPUnit/TestParser/PHPUnitParser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Class, Declaration, Method, Namespace, Node, Program } from 'php-parser';
import { Parser } from './Parser';
import { TransformerFactory } from '../Transformer';
import { TestDefinition, TestType } from './types';
import { TestDefinition, TestType } from '../types';
import { Parser } from './Parser';
import { validator } from './Validator';

export class PHPUnitParser extends Parser {
Expand Down
4 changes: 2 additions & 2 deletions src/PHPUnit/TestParser/Parser.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Call, Declaration, Identifier, Namespace, Node, Variable } from 'php-parser';
import { PHPUnitXML } from '../PHPUnitXML';
import { annotationParser, attributeParser } from './AnnotationParser';
import { TransformerFactory } from '../Transformer';
import { TestDefinition, TestType } from './types';
import { TestDefinition, TestType } from '../types';
import { annotationParser, attributeParser } from './AnnotationParser';

export abstract class Parser {
private phpUnitXML?: PHPUnitXML;
Expand Down
2 changes: 1 addition & 1 deletion src/PHPUnit/TestParser/PestParser.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { pestProject } from '../__tests__/utils';
import { PHPUnitXML } from '../PHPUnitXML';
import { TestDefinition, TestType } from '../types';
import { TestParser } from './TestParser';
import { TestDefinition, TestType } from './types';

export const parse = (buffer: Buffer | string, file: string) => {
const tests: TestDefinition[] = [];
Expand Down
4 changes: 2 additions & 2 deletions src/PHPUnit/TestParser/PestParser.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { basename, dirname, join, relative } from 'node:path';
import { Block, Call, Closure, Declaration, ExpressionStatement, Node, Program, String } from 'php-parser';
import { TransformerFactory } from '../Transformer';
import { TestDefinition, TestType } from '../types';
import { capitalize } from '../utils';
import { Parser } from './Parser';
import { TransformerFactory } from '../Transformer';
import { TestDefinition, TestType } from './types';

export class PestParser extends Parser {
private converter = TransformerFactory.factory('pest');
Expand Down
2 changes: 1 addition & 1 deletion src/PHPUnit/TestParser/TestParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { EventEmitter } from 'node:events';
import { readFile } from 'node:fs/promises';
import { Declaration, Node } from 'php-parser';
import { PHPUnitXML } from '../PHPUnitXML';
import { TestDefinition, TestType } from '../types';
import { engine } from '../utils';
import { Parser } from './Parser';
import { PestParser } from './PestParser';
import { PHPUnitParser } from './PHPUnitParser';
import { TestDefinition, TestType } from './types';

const textDecoder = new TextDecoder('utf-8');

Expand Down
1 change: 0 additions & 1 deletion src/PHPUnit/TestParser/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './TestParser';
export * from './types';
export * from './PHPUnitParser';
export * from './PestParser';
2 changes: 1 addition & 1 deletion src/PHPUnit/TestRunner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { getPhpUnitVersion, phpUnitProject, phpUnitProjectWin } from './__tests_
import { CommandBuilder } from './CommandBuilder';
import { Configuration } from './Configuration';
import { TeamcityEvent } from './ProblemMatcher';
import { TestType } from './TestParser';
import { TestRunner } from './TestRunner';
import { TestRunnerEvent } from './TestRunnerObserver';
import { TransformerFactory } from './Transformer';
import { TestType } from './types';

const PHPUNIT_VERSION: string = getPhpUnitVersion();

Expand Down
2 changes: 1 addition & 1 deletion src/PHPUnit/Transformer/PHPUnitTransformer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TestDefinition, TestType } from '../types';
import { capitalize, snakeCase, titleCase } from '../utils';
import { TestDefinition, TestType } from '../TestParser/types';
import { Transformer } from './Transformer';

export class PHPUnitTransformer extends Transformer {
Expand Down
Loading

0 comments on commit 965613b

Please sign in to comment.