@@ -3,6 +3,8 @@ import { sync as spawnSync } from 'cross-spawn'
33import { join , relative , sep } from 'path'
44import * as Paths from '../../scripts/paths'
55import * as fs from 'fs-extra'
6+ import { RawSourceMap } from 'source-map'
7+ import { relativiseSourceRoot , extractSourceMaps } from './source-maps'
68
79const TEMPLATE_EXCLUDED_ITEMS = [ 'node_modules' , 'package-lock.json' ]
810
@@ -79,7 +81,7 @@ class TestCaseRunDescriptor {
7981 if ( logUnlessStatus != null && logUnlessStatus !== result . status ) {
8082 console . log (
8183 `Output of test run in "${ this . name } " using template "${
82- this . templateName
84+ this . templateName
8385 } " (exit code: ${ result . status } ):\n\n`,
8486 result . output . trim ( ) ,
8587 )
@@ -147,8 +149,9 @@ export interface TestRunResult {
147149}
148150interface TestFileIoData {
149151 in : [ string , jest . Path , jest . ProjectConfig , jest . TransformOptions ?]
150- // out: string | jest.TransformedSource;
151152 out : string
153+ outNormalized : string
154+ outSourceMaps : RawSourceMap
152155}
153156
154157// tslint:disable-next-line:interface-over-type-literal
@@ -292,12 +295,20 @@ export function run(name: string, options: RunTestOptions = {}): TestRunResult {
292295 }
293296 if ( writeIo ) {
294297 Object . defineProperty ( res , 'ioDataFor' , {
295- value : ( relPath : string ) => require ( `${ ioDir } /${ relPath } .json` ) ,
298+ value : ( relPath : string ) => wrapIoData ( require ( `${ ioDir } /${ relPath } .json` ) , dir ) ,
296299 } )
297300 }
298301 return res as any
299302}
300303
304+ function wrapIoData ( ioData : TestFileIoData , rootDir : string ) : TestFileIoData {
305+ const res : TestFileIoData = { ...ioData }
306+ return Object . defineProperties ( res , {
307+ outNormalized : { get : ( ) => relativiseSourceRoot ( rootDir , ioData . out , '<cwd>/' ) } ,
308+ outSourceMaps : { get : ( ) => extractSourceMaps ( ioData . out ) } ,
309+ } )
310+ }
311+
301312// from https://stackoverflow.com/questions/25245716/remove-all-ansi-colors-styles-from-strings
302313function stripAnsiColors ( stringToStrip : string ) : string {
303314 return stringToStrip . replace (
0 commit comments