2024-01-12 02:53:00 -05:00
|
|
|
import * as assert from 'node:assert/strict';
|
|
|
|
import { beforeEach, describe, it } from 'node:test';
|
2023-12-05 11:22:13 -05:00
|
|
|
import { collectPackageInfo } from '../dist/index.js';
|
|
|
|
|
|
|
|
describe('collectPackageInfo', () => {
|
|
|
|
const context = {
|
|
|
|
cwd: '',
|
|
|
|
version: 'latest',
|
|
|
|
packageManager: 'npm',
|
|
|
|
dryRun: true,
|
2023-12-05 11:23:18 -05:00
|
|
|
packages: [],
|
2023-12-05 11:22:13 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
context.packages = [];
|
2023-12-05 11:23:18 -05:00
|
|
|
});
|
2023-12-05 11:22:13 -05:00
|
|
|
|
|
|
|
it('detects astro', async () => {
|
2023-12-05 11:23:18 -05:00
|
|
|
collectPackageInfo(context, { astro: '1.0.0' }, {});
|
2024-01-12 02:53:00 -05:00
|
|
|
assert.deepEqual(context.packages, [
|
2023-12-05 11:23:18 -05:00
|
|
|
{ name: 'astro', currentVersion: '1.0.0', targetVersion: 'latest' },
|
|
|
|
]);
|
2023-12-05 11:22:13 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('detects @astrojs', async () => {
|
2023-12-05 11:23:18 -05:00
|
|
|
collectPackageInfo(context, { '@astrojs/preact': '1.0.0' }, {});
|
2024-01-12 02:53:00 -05:00
|
|
|
assert.deepEqual(context.packages, [
|
2023-12-05 11:23:18 -05:00
|
|
|
{ name: '@astrojs/preact', currentVersion: '1.0.0', targetVersion: 'latest' },
|
|
|
|
]);
|
2023-12-05 11:22:13 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('supports ^ prefixes', async () => {
|
2023-12-05 11:23:18 -05:00
|
|
|
collectPackageInfo(context, { astro: '^1.0.0' }, {});
|
2024-01-12 02:53:00 -05:00
|
|
|
assert.deepEqual(context.packages, [
|
2023-12-05 11:23:18 -05:00
|
|
|
{ name: 'astro', currentVersion: '^1.0.0', targetVersion: 'latest' },
|
|
|
|
]);
|
2023-12-05 11:22:13 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('supports ~ prefixes', async () => {
|
2023-12-05 11:23:18 -05:00
|
|
|
collectPackageInfo(context, { astro: '~1.0.0' }, {});
|
2024-01-12 02:53:00 -05:00
|
|
|
assert.deepEqual(context.packages, [
|
2023-12-05 11:23:18 -05:00
|
|
|
{ name: 'astro', currentVersion: '~1.0.0', targetVersion: 'latest' },
|
|
|
|
]);
|
2023-12-05 11:22:13 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('supports prereleases', async () => {
|
2023-12-05 11:23:18 -05:00
|
|
|
collectPackageInfo(context, { astro: '1.0.0-beta.0' }, {});
|
2024-01-12 02:53:00 -05:00
|
|
|
assert.deepEqual(context.packages, [
|
2023-12-05 11:23:18 -05:00
|
|
|
{ name: 'astro', currentVersion: '1.0.0-beta.0', targetVersion: 'latest' },
|
|
|
|
]);
|
2023-12-05 11:22:13 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('ignores self', async () => {
|
2023-12-05 11:23:18 -05:00
|
|
|
collectPackageInfo(context, { '@astrojs/upgrade': '0.0.1' }, {});
|
2024-01-12 02:53:00 -05:00
|
|
|
assert.deepEqual(context.packages, []);
|
2023-12-05 11:22:13 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('ignores linked packages', async () => {
|
2023-12-05 11:23:18 -05:00
|
|
|
collectPackageInfo(context, { '@astrojs/preact': 'link:../packages/preact' }, {});
|
2024-01-12 02:53:00 -05:00
|
|
|
assert.deepEqual(context.packages, []);
|
2023-12-05 11:22:13 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('ignores workspace packages', async () => {
|
2023-12-05 11:23:18 -05:00
|
|
|
collectPackageInfo(context, { '@astrojs/preact': 'workspace:*' }, {});
|
2024-01-12 02:53:00 -05:00
|
|
|
assert.deepEqual(context.packages, []);
|
2023-12-05 11:22:13 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('ignores github packages', async () => {
|
2023-12-05 11:23:18 -05:00
|
|
|
collectPackageInfo(context, { '@astrojs/preact': 'github:withastro/astro' }, {});
|
2024-01-12 02:53:00 -05:00
|
|
|
assert.deepEqual(context.packages, []);
|
2023-12-05 11:22:13 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('ignores tag', async () => {
|
2023-12-05 11:23:18 -05:00
|
|
|
collectPackageInfo(context, { '@astrojs/preact': 'beta' }, {});
|
2024-01-12 02:53:00 -05:00
|
|
|
assert.deepEqual(context.packages, []);
|
2023-12-05 11:22:13 -05:00
|
|
|
});
|
|
|
|
});
|