mirror of
				https://github.com/microsoft/playwright.git
				synced 2025-06-26 21:40:17 +00:00 
			
		
		
		
	feat(testrunner): support sourcemaps (#3459)
This commit is contained in:
		
							parent
							
								
									4dde2882e7
								
							
						
					
					
						commit
						f45791dd8b
					
				@ -78,6 +78,7 @@
 | 
			
		||||
    "pirates": "^4.0.1",
 | 
			
		||||
    "pixelmatch": "^4.0.2",
 | 
			
		||||
    "socksv5": "0.0.6",
 | 
			
		||||
    "source-map-support": "^0.5.19",
 | 
			
		||||
    "text-diff": "^1.0.1",
 | 
			
		||||
    "ts-loader": "^6.1.2",
 | 
			
		||||
    "typescript": "^3.8.3",
 | 
			
		||||
 | 
			
		||||
@ -19,8 +19,28 @@ const path = require('path');
 | 
			
		||||
const fs = require('fs');
 | 
			
		||||
const pirates = require('pirates');
 | 
			
		||||
const babel = require('@babel/core');
 | 
			
		||||
const version = 0;
 | 
			
		||||
const sourceMapSupport = require('source-map-support');
 | 
			
		||||
 | 
			
		||||
const version = 1;
 | 
			
		||||
const cacheDir = path.join(os.tmpdir(), 'playwright-transform-cache');
 | 
			
		||||
/** @type {Map<string, string>} */
 | 
			
		||||
const sourceMaps = new Map();
 | 
			
		||||
 | 
			
		||||
sourceMapSupport.install({
 | 
			
		||||
  environment: 'node',
 | 
			
		||||
  handleUncaughtExceptions: false,
 | 
			
		||||
  retrieveSourceMap(source) {
 | 
			
		||||
    if (!sourceMaps.has(source))
 | 
			
		||||
      return null;
 | 
			
		||||
    const sourceMapPath = sourceMaps.get(source);
 | 
			
		||||
    if (!fs.existsSync(sourceMapPath))
 | 
			
		||||
      return null;
 | 
			
		||||
    return {
 | 
			
		||||
      map: JSON.parse(fs.readFileSync(sourceMapPath, 'utf-8')),
 | 
			
		||||
      url: source
 | 
			
		||||
    };
 | 
			
		||||
  }
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @param {string} content 
 | 
			
		||||
@ -38,6 +58,8 @@ function installTransform() {
 | 
			
		||||
  return pirates.addHook((code, filename) => {
 | 
			
		||||
    const cachePath = calculateCachePath(code, filename);
 | 
			
		||||
    const codePath = cachePath + '.js';
 | 
			
		||||
    const sourceMapPath = cachePath + '.map';
 | 
			
		||||
    sourceMaps.set(filename, sourceMapPath);
 | 
			
		||||
    if (fs.existsSync(codePath))
 | 
			
		||||
      return fs.readFileSync(codePath, 'utf8');
 | 
			
		||||
    
 | 
			
		||||
@ -45,12 +67,14 @@ function installTransform() {
 | 
			
		||||
      presets: [
 | 
			
		||||
        ['@babel/preset-env', {targets: {node: 'current'}}],
 | 
			
		||||
        '@babel/preset-typescript'],
 | 
			
		||||
      sourceMaps: true,
 | 
			
		||||
    });
 | 
			
		||||
    if (result.code) {
 | 
			
		||||
      fs.mkdirSync(path.dirname(cachePath), {recursive: true});
 | 
			
		||||
      if (result.map)
 | 
			
		||||
        fs.writeFileSync(sourceMapPath, JSON.stringify(result.map), 'utf8');  
 | 
			
		||||
      fs.writeFileSync(codePath, result.code, 'utf8');
 | 
			
		||||
    }
 | 
			
		||||
    // TODO(einbinder) sourcemaps
 | 
			
		||||
    return result.code;
 | 
			
		||||
  }, {
 | 
			
		||||
    exts: ['.ts']
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user