|
| 1 | +/** |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + * |
| 7 | + * @format |
| 8 | + */ |
| 9 | + |
| 10 | +const fs = require('fs'); |
| 11 | +const path = require('path'); |
| 12 | + |
| 13 | +function readOutcomes() { |
| 14 | + const baseDir = '/tmp'; |
| 15 | + let outcomes = {}; |
| 16 | + fs.readdirSync(baseDir).forEach(file => { |
| 17 | + const fullPath = path.join(baseDir, file); |
| 18 | + if (fullPath.endsWith('outcome') && fs.statSync(fullPath).isDirectory) { |
| 19 | + fs.readdirSync(fullPath).forEach(subFile => { |
| 20 | + const subFullPath = path.join(fullPath, subFile); |
| 21 | + if (subFullPath.endsWith('outcome')) { |
| 22 | + const [library, status] = String(fs.readFileSync(subFullPath, 'utf8')) |
| 23 | + .trim() |
| 24 | + .split(':'); |
| 25 | + const platform = subFile.includes('android') ? 'Android' : 'iOS'; |
| 26 | + console.log( |
| 27 | + `[${platform}] ${library} completed with status ${status}`, |
| 28 | + ); |
| 29 | + outcomes[library.trim()] = { |
| 30 | + platform, |
| 31 | + status: status.trim(), |
| 32 | + }; |
| 33 | + } |
| 34 | + }); |
| 35 | + } else if (fullPath.endsWith('outcome')) { |
| 36 | + const [library, status] = String(fs.readFileSync(fullPath, 'utf8')) |
| 37 | + .trim() |
| 38 | + .split(':'); |
| 39 | + const platform = file.includes('android') ? 'Android' : 'iOS'; |
| 40 | + console.log(`[${platform}] ${library} completed with status ${status}`); |
| 41 | + outcomes[library.trim()] = { |
| 42 | + platform, |
| 43 | + status: status.trim(), |
| 44 | + }; |
| 45 | + } |
| 46 | + }); |
| 47 | + return outcomes; |
| 48 | +} |
| 49 | + |
| 50 | +function printFailures(outcomes) { |
| 51 | + console.log('Printing failures...'); |
| 52 | + let failures = 0; |
| 53 | + Object.entries(outcomes).forEach(([library, value]) => { |
| 54 | + if (value.status !== 'success') { |
| 55 | + console.log( |
| 56 | + `❌ [${value.platform}] ${library} failed with status ${value.status}`, |
| 57 | + ); |
| 58 | + failures++; |
| 59 | + } |
| 60 | + }); |
| 61 | + return failures > 0; |
| 62 | +} |
| 63 | + |
| 64 | +function collectResults() { |
| 65 | + const outcomes = readOutcomes(); |
| 66 | + const failures = printFailures(outcomes); |
| 67 | + if (failures) { |
| 68 | + process.exit(1); |
| 69 | + } |
| 70 | + console.log('✅ All tests passed!'); |
| 71 | +} |
| 72 | +module.exports = { |
| 73 | + collectResults, |
| 74 | +}; |
0 commit comments