|
| 1 | +import assert from 'node:assert/strict'; |
| 2 | +import { readFile } from 'node:fs/promises'; |
| 3 | +import { test } from 'node:test'; |
| 4 | + |
| 5 | +async function readJson(url) { |
| 6 | + return JSON.parse(await readFile(url, 'utf8')); |
| 7 | +} |
| 8 | + |
| 9 | +test('npm package metadata uses the public unscoped package name', async () => { |
| 10 | + const packageJson = await readJson(new URL('../package.json', import.meta.url)); |
| 11 | + const packageLock = await readJson(new URL('../package-lock.json', import.meta.url)); |
| 12 | + const rootReadme = await readFile(new URL('../../README.md', import.meta.url), 'utf8'); |
| 13 | + const jsReadme = await readFile(new URL('../README.md', import.meta.url), 'utf8'); |
| 14 | + const rustReadme = await readFile(new URL('../../rust/README.md', import.meta.url), 'utf8'); |
| 15 | + const issue163CaseStudy = await readFile( |
| 16 | + new URL('../../docs/case-studies/issue-163/README.md', import.meta.url), |
| 17 | + 'utf8', |
| 18 | + ); |
| 19 | + |
| 20 | + assert.equal(packageJson.name, 'meta-language'); |
| 21 | + assert.equal(packageLock.name, 'meta-language'); |
| 22 | + assert.equal(packageLock.packages[''].name, 'meta-language'); |
| 23 | + |
| 24 | + for (const readmeWithBadge of [rootReadme, jsReadme]) { |
| 25 | + assert.ok(readmeWithBadge.includes('npmjs.com/package/meta-language')); |
| 26 | + } |
| 27 | + |
| 28 | + for (const readmeWithImport of [rootReadme, jsReadme, rustReadme]) { |
| 29 | + assert.ok(readmeWithImport.includes("from 'meta-language'")); |
| 30 | + } |
| 31 | + |
| 32 | + for (const publicDoc of [rootReadme, jsReadme, rustReadme, issue163CaseStudy]) { |
| 33 | + assert.equal(publicDoc.includes('@link-foundation/meta-language'), false); |
| 34 | + } |
| 35 | +}); |
| 36 | + |
| 37 | +test('JavaScript workflow publishes to npm with trusted publishing provenance', async () => { |
| 38 | + const workflow = await readFile( |
| 39 | + new URL('../../.github/workflows/js.yml', import.meta.url), |
| 40 | + 'utf8', |
| 41 | + ); |
| 42 | + |
| 43 | + assert.match(workflow, /release:\s*\n\s+types:\s+\[published\]/); |
| 44 | + assert.match(workflow, /id-token:\s+write/); |
| 45 | + assert.match(workflow, /registry-url:\s+['"]https:\/\/registry\.npmjs\.org['"]/); |
| 46 | + assert.match(workflow, /working-directory:\s+js/); |
| 47 | + assert.match(workflow, /npm publish --provenance/); |
| 48 | + assert.match(workflow, /npm view meta-language@\$\{\{\s*steps\.package\.outputs\.version\s*\}\} version/); |
| 49 | +}); |
0 commit comments