Files
core/test/package-metadata.test.ts
T
chrnx a30c2cecb3 chore(release): 26.9.0-beta.2 to staging
The plugins repository builds against Plugin { name, mount } and app.boot(),
which only develop has. Staging the version publishes it to Verdaccio under
stg and nowhere else; the npm and JSR cut stays a separate decision.

The bump also moves the exported VERSION, which was two releases behind and had
no business being. Its comment claimed it was "replaced at publish time" and
nothing ever did that — not tsup, not stage.yml, not release.yml, which only
reads the version out of package.json. VERSION is what a consumer quotes in a
bug report, so a stale one sends someone to the changelog of a release they are
not running.

Pinning it to package.json is what keeps this from being a fix with a shelf
life: the next bump that forgets it now fails the build. smoke.test.ts was
never going to catch it, because it asserts the CalVer shape and a stale
version matches that perfectly.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-09-17 22:39:49 -05:00

94 lines
3.8 KiB
TypeScript

import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { describe, expect, it } from 'vitest';
import { VERSION } from '../src/index';
interface PackageMetadata {
readonly repository?: {
readonly type?: string;
readonly url?: string;
};
readonly bugs?: {
readonly url?: string;
readonly email?: string;
};
readonly homepage?: string;
readonly author?: string;
}
interface DenoManifest {
readonly name?: string;
readonly version?: string;
readonly license?: string;
readonly exports?: Record<string, string>;
}
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', () => {
expect(packageJson.repository).toEqual({
type: 'git',
url: 'git+https://github.com/Expressive-Tea/green-tea.git',
});
});
it('links npm consumers to support and documentation', () => {
expect(packageJson.bugs).toEqual({
url: 'https://github.com/Expressive-Tea/green-tea/issues',
email: 'projects@expressive-tea.io',
});
expect(packageJson.homepage).toBe('https://green-tea.expressive-tea.io/docs/');
});
// A published package whose only contact is a GitHub URL is unreachable to anyone without
// an account, so the address is pinned here rather than left to drift back out.
it('gives npm an address to show for the package', () => {
expect(packageJson.author).toBe('green-tea contributors <projects@expressive-tea.io>');
});
});
// 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<string, unknown>);
expect(Object.keys(denoJson.exports ?? {})).toEqual(npmEntries);
});
});
// The third place the version is written, and the one nothing was watching. `VERSION` is what a
// consumer reads at runtime — a bug report, a health endpoint, a support thread all quote it — so a
// stale one sends someone to the changelog of a release they are not running.
//
// It carried a comment promising it was "replaced at publish time", and no such step existed: not in
// `tsup.config.ts`, not in `stage.yml`, not in `release.yml`, which only reads the version out of
// `package.json`. Two releases of drift went unnoticed because `smoke.test.ts` asserts the CalVer
// *shape*, which any stale version still matches. Shape was never the question.
describe('the exported VERSION agrees with package.json', () => {
it('is the version this package publishes under', () => {
expect(VERSION).toBe(packageJson.version);
});
});