diff --git a/test/package-metadata.test.ts b/test/package-metadata.test.ts index a5f1301..f9fbed2 100644 --- a/test/package-metadata.test.ts +++ b/test/package-metadata.test.ts @@ -16,7 +16,25 @@ interface PackageMetadata { readonly author?: string; } -const packageJson = JSON.parse(readFileSync(resolve(process.cwd(), 'package.json'), 'utf8')) as PackageMetadata; +interface DenoManifest { + readonly name?: string; + readonly version?: string; + readonly license?: string; + readonly exports?: Record; +} + +const read = (file: string): string => readFileSync(resolve(process.cwd(), file), 'utf8'); +const packageJson = JSON.parse(read('package.json')) as PackageMetadata & { version: string; license: string }; + +// `deno.json` is JSONC and carries comments. Only whole-line `//` comments are stripped, so this +// can never eat a `//` inside a string value — narrower than a general JSONC parser, and enough, +// versus pulling in a dependency to read one config file. +const denoJson = JSON.parse( + read('deno.json') + .split('\n') + .filter((line) => !line.trim().startsWith('//')) + .join('\n'), +) as DenoManifest; describe('package publication metadata', () => { it('links npm provenance to the public GitHub repository', () => { @@ -40,3 +58,20 @@ describe('package publication metadata', () => { expect(packageJson.author).toBe('green-tea contributors '); }); }); + +// npm and JSR are published from the same tag but read their identity from different files, so the +// two can drift silently: bump package.json alone and the next release ships one version to npm and +// the previous one to JSR, under the same tag. Nothing else notices, which is why this is here. +describe('JSR manifest agrees with package.json', () => { + it('publishes the same package at the same version', () => { + expect(denoJson.name).toBe('@green-tea/core'); + expect(denoJson.version).toBe(packageJson.version); + expect(denoJson.license).toBe(packageJson.license); + }); + + // A reader following a docs example should not have to care which registry they installed from. + it('offers the same entry points npm does', () => { + const npmEntries = Object.keys(JSON.parse(read('package.json')).exports as Record); + expect(Object.keys(denoJson.exports ?? {})).toEqual(npmEntries); + }); +});