75 lines
2.4 KiB
JavaScript
75 lines
2.4 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { readFileSync } from 'node:fs';
|
|
import { test } from 'node:test';
|
|
|
|
import {
|
|
compareVersions,
|
|
createUpdateManifest,
|
|
nextPatchVersion,
|
|
selectReleaseArtifact,
|
|
} from './build-release.mjs';
|
|
|
|
test('selects an explicit release artifact when configured', () => {
|
|
const artifactPath = new URL('../package.json', import.meta.url).pathname;
|
|
const previous = process.env.AGC_UPDATE_ARTIFACT;
|
|
process.env.AGC_UPDATE_ARTIFACT = artifactPath;
|
|
try {
|
|
assert.equal(selectReleaseArtifact([]), artifactPath);
|
|
} finally {
|
|
if (previous === undefined) delete process.env.AGC_UPDATE_ARTIFACT;
|
|
else process.env.AGC_UPDATE_ARTIFACT = previous;
|
|
}
|
|
});
|
|
|
|
test('does not select unsupported files', () => {
|
|
assert.equal(
|
|
selectReleaseArtifact(['/tmp/latest.json', '/tmp/readme.txt']),
|
|
null,
|
|
);
|
|
});
|
|
|
|
test('manifest contains version, download URL and integrity fields', () => {
|
|
const manifest = createUpdateManifest(
|
|
new URL('../package.json', import.meta.url).pathname,
|
|
);
|
|
assert.match(manifest.version, /^\d+\.\d+\.\d+$/u);
|
|
assert.match(
|
|
manifest.downloadUrl,
|
|
new RegExp(`/agc/${manifest.version}/package\\.json$`, 'u'),
|
|
);
|
|
assert.equal(manifest.sha256.length, 64);
|
|
assert.equal(typeof manifest.size, 'number');
|
|
});
|
|
|
|
test('manifest preserves multiline release notes', () => {
|
|
const previous = process.env.AGC_UPDATE_RELEASE_NOTES;
|
|
process.env.AGC_UPDATE_RELEASE_NOTES = '第一行\n第二行\r\n第三行';
|
|
try {
|
|
const manifest = createUpdateManifest(
|
|
new URL('../package.json', import.meta.url).pathname,
|
|
);
|
|
assert.equal(manifest.releaseNotes, '第一行\n第二行\r\n第三行');
|
|
} finally {
|
|
if (previous === undefined) delete process.env.AGC_UPDATE_RELEASE_NOTES;
|
|
else process.env.AGC_UPDATE_RELEASE_NOTES = previous;
|
|
}
|
|
});
|
|
|
|
test('next release version follows the higher local or OSS version', () => {
|
|
assert.equal(compareVersions('0.1.15', '0.1.12'), 1);
|
|
assert.equal(nextPatchVersion('0.1.12', '0.1.15'), '0.1.16');
|
|
assert.equal(nextPatchVersion('0.1.18', '0.1.15'), '0.1.19');
|
|
assert.equal(nextPatchVersion('0.1.12', null), '0.1.13');
|
|
});
|
|
|
|
test('release upload forces overwrite for versioned artifact and latest pointer', () => {
|
|
const source = readFileSync(
|
|
new URL('./release-upload.mjs', import.meta.url),
|
|
'utf8',
|
|
);
|
|
assert.equal(
|
|
(source.match(/runOssutil\(\['cp', '--force'/gu) ?? []).length,
|
|
2,
|
|
);
|
|
});
|