@@ -5,14 +5,34 @@ import * as dotenv from 'dotenv';
55import { sync as globSync } from 'glob' ;
66
77import { registrySetup } from './registrySetup' ;
8+ import { readFileSync } from 'fs' ;
89
910const DEFAULT_DSN = 'https://username@domain/123' ;
1011const DEFAULT_SENTRY_ORG_SLUG = 'sentry-javascript-sdks' ;
1112const DEFAULT_SENTRY_PROJECT = 'sentry-javascript-e2e-tests' ;
1213
13- function asyncExec ( command : string , options : { env : Record < string , string | undefined > ; cwd : string } ) : Promise < void > {
14+ interface PackageJson {
15+ volta ?: {
16+ node ?: string ;
17+ } ;
18+ }
19+
20+ function getVoltaNodeVersion ( packageJsonPath : string ) : string | undefined {
21+ try {
22+ const packageJson : PackageJson = JSON . parse ( readFileSync ( packageJsonPath , 'utf8' ) ) ;
23+ return packageJson . volta ?. node ;
24+ } catch {
25+ return undefined ;
26+ }
27+ }
28+
29+ function asyncExec (
30+ command : string ,
31+ options : { env : Record < string , string | undefined > ; cwd : string ; nodeVersion ?: string } ,
32+ ) : Promise < void > {
1433 return new Promise ( ( resolve , reject ) => {
15- const process = spawn ( command , { ...options , shell : true } ) ;
34+ const finalCommand = options . nodeVersion ? `volta run --node ${ options . nodeVersion } ${ command } ` : command ;
35+ const process = spawn ( finalCommand , { ...options , shell : true } ) ;
1636
1737 process . stdout . on ( 'data' , data => {
1838 console . log ( `${ data } ` ) ;
@@ -75,12 +95,13 @@ async function run(): Promise<void> {
7595
7696 for ( const testAppPath of testAppPaths ) {
7797 const cwd = resolve ( 'test-applications' , testAppPath ) ;
98+ const nodeVersion = getVoltaNodeVersion ( resolve ( cwd , 'package.json' ) ) ;
7899
79100 console . log ( `Building ${ testAppPath } ...` ) ;
80- await asyncExec ( 'pnpm test:build' , { env, cwd } ) ;
101+ await asyncExec ( 'pnpm test:build' , { env, cwd, nodeVersion } ) ;
81102
82103 console . log ( `Testing ${ testAppPath } ...` ) ;
83- await asyncExec ( 'pnpm test:assert' , { env, cwd } ) ;
104+ await asyncExec ( 'pnpm test:assert' , { env, cwd, nodeVersion } ) ;
84105 }
85106 } catch ( error ) {
86107 console . error ( error ) ;
0 commit comments