|
1 | 1 | import fs from 'fs';
|
2 |
| -import { createHash } from 'crypto'; |
3 | 2 | import { vi } from 'vitest';
|
| 3 | +import { createHash } from 'crypto'; |
4 | 4 | import { DbgpSession } from '../lib/dbgp-session';
|
5 | 5 | import { CDPServer } from '../lib/cdp-server';
|
6 | 6 | import { XdebugCDPBridge } from '../lib/xdebug-cdp-bridge';
|
@@ -364,6 +364,7 @@ describe('XdebugCDPBridge', () => {
|
364 | 364 | vi.spyOn(cdpServer, 'sendMessage').mockImplementation((message) => {
|
365 | 365 | if (message.method === 'Debugger.scriptParsed') {
|
366 | 366 | script = message;
|
| 367 | + |
367 | 368 | resolve();
|
368 | 369 | }
|
369 | 370 | return original(message);
|
@@ -409,4 +410,98 @@ describe('XdebugCDPBridge', () => {
|
409 | 410 | 'AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA'
|
410 | 411 | );
|
411 | 412 | });
|
| 413 | + |
| 414 | + it('ignores files from excluded path', async () => { |
| 415 | + bridge = new XdebugCDPBridge(dbgpSession, cdpServer, { |
| 416 | + knownScriptUrls: [], |
| 417 | + getPHPFile: (file) => php.readFileAsText(file), |
| 418 | + breakOnFirstLine: true, |
| 419 | + }); |
| 420 | + |
| 421 | + const excludedPath = '/internal/shared'; |
| 422 | + |
| 423 | + const file = `${fixtures}/test.php`; |
| 424 | + |
| 425 | + php.writeFile(file, fs.readFileSync(file).toString()); |
| 426 | + |
| 427 | + bridge.start(); |
| 428 | + |
| 429 | + let script; |
| 430 | + let sourceMap; |
| 431 | + |
| 432 | + await php.runStream({ scriptPath: file }); |
| 433 | + |
| 434 | + await new Promise<void>((resolve) => { |
| 435 | + const original = cdpServer.sendMessage.bind(cdpServer); |
| 436 | + vi.spyOn(cdpServer, 'sendMessage').mockImplementation((message) => { |
| 437 | + if (message.method === 'Debugger.scriptParsed') { |
| 438 | + script = message; |
| 439 | + resolve(); |
| 440 | + } |
| 441 | + return original(message); |
| 442 | + }); |
| 443 | + }); |
| 444 | + |
| 445 | + sourceMap = JSON.parse( |
| 446 | + Buffer.from( |
| 447 | + script!.params.sourceMapURL.split(',')[1], |
| 448 | + 'base64' |
| 449 | + ).toString('utf8') |
| 450 | + ); |
| 451 | + |
| 452 | + expect(sourceMap).toEqual( |
| 453 | + expect.objectContaining({ |
| 454 | + sources: expect.arrayContaining([ |
| 455 | + expect.stringContaining(excludedPath), |
| 456 | + ]), |
| 457 | + }), |
| 458 | + ); |
| 459 | + |
| 460 | + bridge.stop(); |
| 461 | + |
| 462 | + php.exit(); |
| 463 | + |
| 464 | + php = new PHP( |
| 465 | + await loadNodeRuntime(RecommendedPHPVersion, { withXdebug: true }) |
| 466 | + ); |
| 467 | + |
| 468 | + dbgpSession = new DbgpSession(); |
| 469 | + cdpServer = new CDPServer(); |
| 470 | + bridge = new XdebugCDPBridge(dbgpSession, cdpServer, { |
| 471 | + knownScriptUrls: [], |
| 472 | + getPHPFile: (file) => php.readFileAsText(file), |
| 473 | + breakOnFirstLine: true, |
| 474 | + excludedPaths: [excludedPath], |
| 475 | + }); |
| 476 | + |
| 477 | + bridge.start(); |
| 478 | + |
| 479 | + await php.runStream({ scriptPath: file }); |
| 480 | + |
| 481 | + await new Promise<void>((resolve) => { |
| 482 | + const original = cdpServer.sendMessage.bind(cdpServer); |
| 483 | + vi.spyOn(cdpServer, 'sendMessage').mockImplementation((message) => { |
| 484 | + if (message.method === 'Debugger.scriptParsed') { |
| 485 | + script = message; |
| 486 | + resolve(); |
| 487 | + } |
| 488 | + return original(message); |
| 489 | + }); |
| 490 | + }); |
| 491 | + |
| 492 | + sourceMap = JSON.parse( |
| 493 | + Buffer.from( |
| 494 | + script!.params.sourceMapURL.split(',')[1], |
| 495 | + 'base64' |
| 496 | + ).toString('utf8') |
| 497 | + ); |
| 498 | + |
| 499 | + expect(sourceMap).toEqual( |
| 500 | + expect.objectContaining({ |
| 501 | + sources: expect.arrayContaining([ |
| 502 | + expect.stringContaining(file), |
| 503 | + ]), |
| 504 | + }), |
| 505 | + ); |
| 506 | + }); |
412 | 507 | });
|
0 commit comments