mirror of
				https://github.com/microsoft/playwright.git
				synced 2025-06-26 21:40:17 +00:00 
			
		
		
		
	This patch re-implements matching and reporting for test runner. Among other improvements: - test failures now show a short snippet from test - test failures now explicitly say what received and what was expected - `expect.toBe()` now does text diff when gets strings as input - `expect.toEqual` now does object diff
		
			
				
	
	
		
			33 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			33 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
const path = require('path');
 | 
						|
 | 
						|
module.exports = {
 | 
						|
  getCallerLocation: function(filename) {
 | 
						|
    const error = new Error();
 | 
						|
    const stackFrames = error.stack.split('\n').slice(1);
 | 
						|
    // Find first stackframe that doesn't point to this file.
 | 
						|
    for (let frame of stackFrames) {
 | 
						|
      frame = frame.trim();
 | 
						|
      if (!frame.startsWith('at '))
 | 
						|
        return null;
 | 
						|
      if (frame.endsWith(')')) {
 | 
						|
        const from = frame.indexOf('(');
 | 
						|
        frame = frame.substring(from + 1, frame.length - 1);
 | 
						|
      } else {
 | 
						|
        frame = frame.substring('at '.length);
 | 
						|
      }
 | 
						|
 | 
						|
      const match = frame.match(/^(.*):(\d+):(\d+)$/);
 | 
						|
      if (!match)
 | 
						|
        return null;
 | 
						|
      const filePath = match[1];
 | 
						|
      const lineNumber = parseInt(match[2], 10);
 | 
						|
      const columnNumber = parseInt(match[3], 10);
 | 
						|
      if (filePath === __filename || filePath === filename)
 | 
						|
        continue;
 | 
						|
      const fileName = filePath.split(path.sep).pop();
 | 
						|
      return { fileName, filePath, lineNumber, columnNumber };
 | 
						|
    }
 | 
						|
    return null;
 | 
						|
  },
 | 
						|
};
 |