|
1 | 1 | import fs from 'node:fs'; |
2 | 2 | import os from 'node:os'; |
3 | 3 | import path from 'node:path'; |
4 | | -import { collectFailures, describeResult, loadWithReact, parseProbeOutput } from '../scripts/entry-load.mjs'; |
| 4 | +import { execFileSync } from 'node:child_process'; |
| 5 | +import { EXPECTED_EXPORTS, collectFailures, describeResult, loadWithReact, parseProbeOutput, probeSource } from '../scripts/entry-load.mjs'; |
5 | 6 |
|
6 | 7 | /** |
7 | 8 | * These tests pin the failure detection, not the fixture's shape. `publint` and |
@@ -119,3 +120,43 @@ describe('loadWithReact', () => { |
119 | 120 | expect(collectFailures([{ react: '18', ...result }])).toHaveLength(1); |
120 | 121 | }); |
121 | 122 | }); |
| 123 | + |
| 124 | +/** |
| 125 | + * The tests above drive the runner with canned output, so none of them execute |
| 126 | + * the missing-export filter the probe actually ships. A green CI run does not |
| 127 | + * either: the filter only reports, so breaking it makes every load pass. These |
| 128 | + * run the generated source against a stand-in module instead of a mock. |
| 129 | + */ |
| 130 | +describe('probeSource', () => { |
| 131 | + let dir; |
| 132 | + |
| 133 | + beforeEach(() => { |
| 134 | + dir = fs.mkdtempSync(path.join(os.tmpdir(), 'reactfire-probe-')); |
| 135 | + }); |
| 136 | + |
| 137 | + afterEach(() => { |
| 138 | + fs.rmSync(dir, { recursive: true, force: true }); |
| 139 | + }); |
| 140 | + |
| 141 | + // The probe resolves its target by specifier, so a relative path stands in |
| 142 | + // for the installed package without needing a fixture install. |
| 143 | + function runProbe(exports) { |
| 144 | + fs.writeFileSync(path.join(dir, 'stand-in.mjs'), `export const ${exports.join(' = 1;\nexport const ')} = 1;\n`); |
| 145 | + fs.writeFileSync(path.join(dir, 'probe.mjs'), probeSource('esm', { name: './stand-in.mjs' })); |
| 146 | + return parseProbeOutput(execFileSync(process.execPath, [path.join(dir, 'probe.mjs')], { encoding: 'utf8' })); |
| 147 | + } |
| 148 | + |
| 149 | + it('passes when every canary is exported', () => { |
| 150 | + const result = runProbe(EXPECTED_EXPORTS); |
| 151 | + expect(result.ok).toBe(true); |
| 152 | + }); |
| 153 | + |
| 154 | + // One dropped submodule is the case the widened canary list exists for, and |
| 155 | + // the case a broken filter would wave through. |
| 156 | + it('names the missing canary when one submodule is dropped', () => { |
| 157 | + const result = runProbe(EXPECTED_EXPORTS.filter((name) => name !== 'useStorageDownloadURL')); |
| 158 | + expect(result.ok).toBe(false); |
| 159 | + expect(result.reason).toBe('missing-exports'); |
| 160 | + expect(result.missing).toEqual(['useStorageDownloadURL']); |
| 161 | + }); |
| 162 | +}); |
0 commit comments