Skip to content

Commit febb9de

Browse files
committed
windows path
1 parent e1ba720 commit febb9de

5 files changed

Lines changed: 55 additions & 45 deletions

File tree

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ module.exports = {
170170
// A map from regular expressions to paths to transformers
171171
// transform: undefined,
172172
transform: {
173-
'^.+.tsx?$': ['ts-jest', { isolatedModules: true }],
173+
'^.+.tsx?$': ['ts-jest'],
174174
},
175175

176176
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation

src/PHPUnitLinkProvider.test.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { relative } from 'path';
12
import { DocumentLink, Position, Range } from 'vscode';
2-
import { URI } from 'vscode-uri';
33
import { phpUnitProject } from './PHPUnit/__tests__/utils';
44
import { PHPUnitLinkProvider } from './PHPUnitLinkProvider';
55

@@ -29,6 +29,9 @@ class TextDocument {
2929
}
3030

3131
describe('PHPUnitLinkProvider', () => {
32+
const root = phpUnitProject('');
33+
const normalizePath = (file: string) => relative(root, file).replace(/\\/g, '/');
34+
3235
const text = `❌ FAILED Calculator (Tests\Calculator) > Sum item method not call
3336
Mockery\Exception\InvalidCountException: Method test(<Any Arguments>) from Mockery_0_App_Item_App_Item should be called
3437
exactly 1 times but called 0 times.
@@ -43,28 +46,25 @@ Mockery\Exception\InvalidCountException: Method test(<Any Arguments>) from Mocke
4346
8. ${phpUnitProject('vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/MockeryPHPUnitIntegration.php')}:61
4447
9. ${phpUnitProject('vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/MockeryPHPUnitIntegrationAssertPostConditions.php')}:19`;
4548

46-
const formatTarget = (uri: URI) => {
47-
return `${uri.fsPath}:${uri.fragment.replace(/^L/, '')}`;
48-
};
49-
5049
let provider: PHPUnitLinkProvider;
5150
beforeEach(() => provider = new PHPUnitLinkProvider());
5251

5352
it('get links', () => {
5453
const document = new TextDocument(text);
5554

56-
const links = provider.provideDocumentLinks(document as any, {} as any) as DocumentLink[];
55+
const links = (provider.provideDocumentLinks(document as any, {} as any) as DocumentLink[])
56+
.map((link) => [normalizePath(link.target!.fsPath), link.target!.fragment]);
5757

58-
expect(links.map((link) => formatTarget(link.target!))).toEqual([
59-
`${phpUnitProject('vendor/mockery/mockery/library/Mockery/CountValidator/Exact.php')}:32`,
60-
`${phpUnitProject('vendor/mockery/mockery/library/Mockery/Expectation.php')}:739`,
61-
`${phpUnitProject('vendor/mockery/mockery/library/Mockery/ExpectationDirector.php')}:202`,
62-
`${phpUnitProject('vendor/mockery/mockery/library/Mockery/Container.php')}:583`,
63-
`${phpUnitProject('vendor/mockery/mockery/library/Mockery/Container.php')}:519`,
64-
`${phpUnitProject('vendor/mockery/mockery/library/Mockery.php')}:176`,
65-
`${phpUnitProject('vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/MockeryPHPUnitIntegration.php')}:49`,
66-
`${phpUnitProject('vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/MockeryPHPUnitIntegration.php')}:61`,
67-
`${phpUnitProject('vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/MockeryPHPUnitIntegrationAssertPostConditions.php')}:19`,
58+
expect(links).toEqual([
59+
['vendor/mockery/mockery/library/Mockery/CountValidator/Exact.php', 'L32'],
60+
['vendor/mockery/mockery/library/Mockery/Expectation.php', 'L739'],
61+
['vendor/mockery/mockery/library/Mockery/ExpectationDirector.php', 'L202'],
62+
['vendor/mockery/mockery/library/Mockery/Container.php', 'L583'],
63+
['vendor/mockery/mockery/library/Mockery/Container.php', 'L519'],
64+
['vendor/mockery/mockery/library/Mockery.php', 'L176'],
65+
['vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/MockeryPHPUnitIntegration.php', 'L49'],
66+
['vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/MockeryPHPUnitIntegration.php', 'L61'],
67+
['vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/MockeryPHPUnitIntegrationAssertPostConditions.php', 'L19'],
6868
]);
6969
});
7070
});

src/PHPUnitLinkProvider.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { CancellationToken, DocumentLink, DocumentLinkProvider, ProviderResult, Range, TextDocument } from 'vscode';
1+
import {
2+
CancellationToken, DocumentLink, DocumentLinkProvider, Position, ProviderResult, Range, TextDocument,
3+
} from 'vscode';
24
import { URI } from 'vscode-uri';
35

46
export class PHPUnitLinkProvider implements DocumentLinkProvider {
5-
private regex = /(\/[^\s:]+\.php):(\d+)/g;
7+
private regex = /((?:[A-Z]:)?(?:\.{0,2}[\\/])?[^\s:]+\.php):(\d+)(?::(\d+))?/gi;
68

79
provideDocumentLinks(document: TextDocument, _token: CancellationToken): ProviderResult<DocumentLink[]> {
810
const links: DocumentLink[] = [];
@@ -12,13 +14,13 @@ export class PHPUnitLinkProvider implements DocumentLinkProvider {
1214
let match: RegExpExecArray | null;
1315

1416
while ((match = this.regex.exec(line.text)) !== null) {
15-
const [fullMatch, filePath, lineNumberStr] = match;
16-
const lineNumber = parseInt(lineNumberStr, 10);
17+
const [fullMatch, filePath, lineStr, colStr] = match;
18+
const lineNumber = parseInt(lineStr, 10);
1719

18-
const start = line.range.start.translate(0, match.index);
19-
const end = start.translate(0, fullMatch.length);
20-
const range = new Range(start, end);
2120
const targetUri = URI.file(filePath).with({ fragment: `L${lineNumber}` });
21+
const start = new Position(lineIndex, match.index);
22+
const end = new Position(lineIndex, match.index + fullMatch.length);
23+
const range = new Range(start, end);
2224

2325
links.push(new DocumentLink(range, targetUri));
2426
}

src/extension.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ describe('Extension Test', () => {
185185
expect(commands.registerCommand).toHaveBeenCalledWith('phpunit.run-file', expect.any(Function));
186186
expect(commands.registerCommand).toHaveBeenCalledWith('phpunit.run-test-at-cursor', expect.any(Function));
187187
expect(commands.registerCommand).toHaveBeenCalledWith('phpunit.rerun', expect.any(Function));
188-
expect(context.subscriptions.push).toHaveBeenCalledTimes(9);
188+
expect(context.subscriptions.push).toHaveBeenCalledTimes(10);
189189
});
190190

191191
it('should run all tests', async () => {

tsconfig.json

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
{
2-
"compilerOptions": {
3-
"module": "commonjs",
4-
"target": "ES2020",
5-
"lib": ["ES2020", "DOM"],
6-
"sourceMap": true,
7-
"rootDir": "src",
8-
"strict": true,
9-
/* enable all strict type-checking options */ /* Additional Checks */
10-
"noImplicitReturns": true,
11-
/* Report error when not all code paths in function return a value. */ "noFallthroughCasesInSwitch": true,
12-
/* Report errors for fallthrough cases in switch statement. */ "noUnusedParameters": true,
13-
/* Report errors on unused parameters. */ "skipLibCheck": true
14-
},
15-
"exclude": [
16-
".vscode-test",
17-
"node_modules",
18-
"**/__mocks__/*",
19-
"**/__tests__/fixtures/**/*",
20-
"**/*.test.[tj]s?(x)"
21-
]
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "ES2020",
5+
"lib": [
6+
"ES2020",
7+
"DOM"
8+
],
9+
"sourceMap": true,
10+
"rootDir": "src",
11+
"strict": true,
12+
/* enable all strict type-checking options */
13+
/* Additional Checks */
14+
"noImplicitReturns": true,
15+
/* Report error when not all code paths in function return a value. */
16+
"noFallthroughCasesInSwitch": true,
17+
/* Report errors for fallthrough cases in switch statement. */
18+
"noUnusedParameters": true,
19+
/* Report errors on unused parameters. */
20+
"skipLibCheck": true,
21+
"isolatedModules": true
22+
},
23+
"exclude": [
24+
".vscode-test",
25+
"node_modules",
26+
"**/__mocks__/*",
27+
"**/__tests__/fixtures/**/*",
28+
"**/*.test.[tj]s?(x)"
29+
]
2230
}

0 commit comments

Comments
 (0)