From 137263b38cb03bacf1648c831af53225c8cb055e Mon Sep 17 00:00:00 2001 From: Mitya Kononchuk Date: Tue, 17 Dec 2024 03:32:15 -0800 Subject: [PATCH] Fix metro tests to run with high parallelism Summary: Changelog: Fix a bug when metro tests could not have been run in parallel, e.g. in a stress-test. Differential Revision: D67332012 --- .../src/__tests__/symbolicate-test.js | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/packages/metro-symbolicate/src/__tests__/symbolicate-test.js b/packages/metro-symbolicate/src/__tests__/symbolicate-test.js index 2c5d39ab9f..0def897cae 100644 --- a/packages/metro-symbolicate/src/__tests__/symbolicate-test.js +++ b/packages/metro-symbolicate/src/__tests__/symbolicate-test.js @@ -13,6 +13,7 @@ const symbolicate = require('../symbolicate'); const fs = require('fs'); +const os = require('os'); const path = require('path'); const {PassThrough} = require('stream'); @@ -53,9 +54,11 @@ const execute = async ( return stdout.join(''); }; +const TEMP_FILE = path.join(os.tmpdir(), 'testfile.temp.cpuprofile'); + afterAll(() => { try { - fs.unlinkSync(resolve('testfile.temp.cpuprofile')); + fs.unlinkSync(TEMP_FILE); } catch (e) {} }); @@ -400,32 +403,23 @@ describe('symbolicating an attribution file specifying unmapped offsets', () => }); test('symbolicating with a cpuprofile', async () => { - fs.copyFileSync( - resolve('testfile.cpuprofile'), - resolve('testfile.temp.cpuprofile'), - ); + fs.copyFileSync(resolve('testfile.cpuprofile'), TEMP_FILE); - await execute([ - resolve('testfile.cpuprofile.map'), - resolve('testfile.temp.cpuprofile'), - ]); + await execute([resolve('testfile.cpuprofile.map'), TEMP_FILE]); - expect(JSON.parse(read('testfile.temp.cpuprofile'))).toMatchSnapshot(); + expect(JSON.parse(read(TEMP_FILE))).toMatchSnapshot(); }); test('symbolicating with a cpuprofile ignoring a function map', async () => { - fs.copyFileSync( - resolve('testfile.cpuprofile'), - resolve('testfile.temp.cpuprofile'), - ); + fs.copyFileSync(resolve('testfile.cpuprofile'), TEMP_FILE); await execute([ '--no-function-names', resolve('testfile.cpuprofile.map'), - resolve('testfile.temp.cpuprofile'), + TEMP_FILE, ]); - expect(JSON.parse(read('testfile.temp.cpuprofile'))).toMatchSnapshot(); + expect(JSON.parse(read(TEMP_FILE))).toMatchSnapshot(); }); test('symbolicating a stack trace with a function map', async () =>