|
| 1 | +import * as fs from 'node:fs'; |
| 2 | +import * as path from 'node:path'; |
| 3 | +import * as semver from 'semver'; |
| 4 | +import { describe, expect, it } from 'vitest'; |
| 5 | + |
| 6 | +import packageJson from '../package.json'; |
| 7 | + |
| 8 | +const packageRoot = path.resolve(__dirname, '..'); |
| 9 | + |
| 10 | +// `exports` mixes shapes (`"./package.json"` is a bare string), so it does not fit one index signature. |
| 11 | +const exportsMap = packageJson.exports as unknown as Record<string, { import?: Record<string, string> }>; |
| 12 | + |
| 13 | +/** |
| 14 | + * A mismatch between the `exports` map and the build output is invisible: the build and lint both |
| 15 | + * pass, and the package is broken only for whoever installs it. Rollup infers its output layout from |
| 16 | + * the module graph, so an unrelated change can relocate these files. |
| 17 | + */ |
| 18 | +describe('Remix 3 exports', () => { |
| 19 | + const subpaths = ['./v3', './v3/client', './v3/node']; |
| 20 | + |
| 21 | + it.each(subpaths)('%s is declared in the exports map', subpath => { |
| 22 | + expect(packageJson.exports).toHaveProperty([subpath]); |
| 23 | + }); |
| 24 | + |
| 25 | + it.each(subpaths)('%s only exposes an import condition', subpath => { |
| 26 | + // Remix 3's asset server rejects CommonJS outright, so a `require` condition could never load. |
| 27 | + expect(Object.keys(exportsMap[subpath] ?? {})).toEqual(['import']); |
| 28 | + }); |
| 29 | + |
| 30 | + it.each(subpaths)('%s points at files that exist in the build output', subpath => { |
| 31 | + const targets = Object.values(exportsMap[subpath]?.import ?? {}); |
| 32 | + |
| 33 | + expect(targets.length).toBeGreaterThan(0); |
| 34 | + |
| 35 | + for (const target of targets) { |
| 36 | + expect(fs.existsSync(path.join(packageRoot, target)), `${subpath} -> ${target} is missing`).toBe(true); |
| 37 | + } |
| 38 | + }); |
| 39 | + |
| 40 | + describe('the Remix 3 peer range', () => { |
| 41 | + const range = packageJson.peerDependencies.remix; |
| 42 | + |
| 43 | + // Asserted by behaviour, so the range can change after Remix 3 reaches GA without failing here. |
| 44 | + it('accepts release candidates', () => { |
| 45 | + // `3.x` does not match `3.0.0-rc.1`: semver ranges exclude prereleases unless they name one. |
| 46 | + expect(semver.satisfies('3.0.0-rc.1', range)).toBe(true); |
| 47 | + expect(semver.satisfies('3.0.0-rc.2', range)).toBe(true); |
| 48 | + }); |
| 49 | + |
| 50 | + it('accepts stable 3.x', () => { |
| 51 | + expect(semver.satisfies('3.0.0', range)).toBe(true); |
| 52 | + expect(semver.satisfies('3.4.2', range)).toBe(true); |
| 53 | + }); |
| 54 | + |
| 55 | + it('rejects the next major', () => { |
| 56 | + expect(semver.satisfies('4.0.0', range)).toBe(false); |
| 57 | + }); |
| 58 | + }); |
| 59 | + |
| 60 | + it('marks every peer dependency optional', () => { |
| 61 | + // A Remix 3 app must not have the Remix 2 packages or React installed on its behalf. |
| 62 | + for (const name of Object.keys(packageJson.peerDependencies)) { |
| 63 | + expect(packageJson.peerDependenciesMeta, `${name} should be optional`).toHaveProperty([name, 'optional'], true); |
| 64 | + } |
| 65 | + }); |
| 66 | +}); |
0 commit comments