|
| 1 | +import { describe, expect, it } from '@jest/globals'; |
| 2 | +import { spawnSync } from 'child_process'; |
| 3 | +import path from 'path'; |
| 4 | +import { fileURLToPath } from 'url'; |
| 5 | + |
| 6 | +const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 7 | + |
| 8 | +/** |
| 9 | + * Integration test for runMetricCollection.js script |
| 10 | + * |
| 11 | + * This test ensures that the script can be run without syntax errors, |
| 12 | + * which helps catch issues like: |
| 13 | + * - Missing or incorrectly exported dependencies (e.g., parquet-wasm exports) |
| 14 | + * - Import/export syntax errors |
| 15 | + * - Module resolution problems |
| 16 | + */ |
| 17 | +describe('tools/spectral/ipa/metrics/scripts/runMetricCollection.js', () => { |
| 18 | + it('should run without import/syntax errors', () => { |
| 19 | + const scriptPath = path.join(__dirname, '../../metrics/scripts/runMetricCollection.js'); |
| 20 | + |
| 21 | + // Run the script with Node.js |
| 22 | + const result = spawnSync('node', [scriptPath], { |
| 23 | + encoding: 'utf8', |
| 24 | + timeout: 10000, |
| 25 | + }); |
| 26 | + |
| 27 | + // The script will fail because required files don't exist in the test environment, |
| 28 | + // but it should NOT fail with a SyntaxError about missing exports |
| 29 | + const output = result.stdout + result.stderr; |
| 30 | + |
| 31 | + // Check that we don't have import/syntax errors |
| 32 | + expect(output).not.toMatch(/SyntaxError.*does not provide an export named/); |
| 33 | + expect(output).not.toMatch(/SyntaxError.*Unexpected token/); |
| 34 | + |
| 35 | + // We expect it to fail with ENOENT for the missing collector results file |
| 36 | + // This proves the imports worked correctly |
| 37 | + expect(output).toMatch(/ENOENT.*ipa-collector-results-combined\.log/); |
| 38 | + }); |
| 39 | +}); |
| 40 | + |
0 commit comments