2024-01-12 02:53:00 -05:00
|
|
|
import * as assert from 'node:assert/strict';
|
2023-11-27 18:00:59 -05:00
|
|
|
import { describe, it } from 'node:test';
|
|
|
|
import { install } from '../dist/index.js';
|
|
|
|
import { setup } from './utils.js';
|
|
|
|
|
|
|
|
describe('install', () => {
|
|
|
|
const fixture = setup();
|
|
|
|
const ctx = {
|
|
|
|
cwd: '',
|
|
|
|
version: 'latest',
|
|
|
|
packageManager: 'npm',
|
|
|
|
dryRun: true,
|
2023-11-27 18:02:46 -05:00
|
|
|
};
|
2023-11-27 18:00:59 -05:00
|
|
|
|
|
|
|
it('up to date', async () => {
|
|
|
|
const context = {
|
|
|
|
...ctx,
|
|
|
|
packages: [
|
|
|
|
{
|
|
|
|
name: 'astro',
|
|
|
|
currentVersion: '1.0.0',
|
|
|
|
targetVersion: '1.0.0',
|
2023-11-27 18:02:46 -05:00
|
|
|
},
|
|
|
|
],
|
2023-11-27 18:00:59 -05:00
|
|
|
};
|
|
|
|
await install(context);
|
2024-01-12 02:53:00 -05:00
|
|
|
assert.equal(fixture.hasMessage('◼ astro is up to date on v1.0.0'), true);
|
2023-11-27 18:00:59 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('patch', async () => {
|
|
|
|
const context = {
|
|
|
|
...ctx,
|
|
|
|
packages: [
|
|
|
|
{
|
|
|
|
name: 'astro',
|
|
|
|
currentVersion: '1.0.0',
|
|
|
|
targetVersion: '1.0.1',
|
2023-11-27 18:02:46 -05:00
|
|
|
},
|
|
|
|
],
|
2023-11-27 18:00:59 -05:00
|
|
|
};
|
|
|
|
await install(context);
|
2024-01-12 02:53:00 -05:00
|
|
|
assert.equal(fixture.hasMessage('● astro can be updated to v1.0.1'), true);
|
2023-11-27 18:00:59 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('minor', async () => {
|
|
|
|
const context = {
|
|
|
|
...ctx,
|
|
|
|
packages: [
|
|
|
|
{
|
|
|
|
name: 'astro',
|
|
|
|
currentVersion: '1.0.0',
|
|
|
|
targetVersion: '1.2.0',
|
2023-11-27 18:02:46 -05:00
|
|
|
},
|
|
|
|
],
|
2023-11-27 18:00:59 -05:00
|
|
|
};
|
|
|
|
await install(context);
|
2024-01-12 02:53:00 -05:00
|
|
|
assert.equal(fixture.hasMessage('● astro can be updated to v1.2.0'), true);
|
2023-11-27 18:00:59 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('major (reject)', async () => {
|
|
|
|
let prompted = false;
|
|
|
|
let exitCode;
|
|
|
|
const context = {
|
|
|
|
...ctx,
|
2023-11-27 18:02:46 -05:00
|
|
|
prompt: () => {
|
2023-11-27 18:00:59 -05:00
|
|
|
prompted = true;
|
2023-11-27 18:02:46 -05:00
|
|
|
return { proceed: false };
|
2023-11-27 18:00:59 -05:00
|
|
|
},
|
|
|
|
exit: (code) => {
|
|
|
|
exitCode = code;
|
|
|
|
},
|
|
|
|
packages: [
|
|
|
|
{
|
|
|
|
name: 'astro',
|
|
|
|
currentVersion: '1.0.0',
|
|
|
|
targetVersion: '2.0.0',
|
|
|
|
isMajor: true,
|
|
|
|
changelogTitle: 'CHANGELOG',
|
2023-11-27 18:02:46 -05:00
|
|
|
changelogURL: 'https://example.com',
|
|
|
|
},
|
|
|
|
],
|
2023-11-27 18:00:59 -05:00
|
|
|
};
|
|
|
|
await install(context);
|
2024-01-12 02:53:00 -05:00
|
|
|
assert.equal(fixture.hasMessage('▲ astro can be updated to v2.0.0'), true);
|
|
|
|
assert.equal(prompted, true);
|
|
|
|
assert.equal(exitCode, 0);
|
|
|
|
assert.equal(fixture.hasMessage('check Be sure to follow the CHANGELOG.'), false);
|
2023-11-27 18:00:59 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('major (accept)', async () => {
|
|
|
|
let prompted = false;
|
|
|
|
let exitCode;
|
|
|
|
const context = {
|
|
|
|
...ctx,
|
2023-11-27 18:02:46 -05:00
|
|
|
prompt: () => {
|
2023-11-27 18:00:59 -05:00
|
|
|
prompted = true;
|
2023-11-27 18:02:46 -05:00
|
|
|
return { proceed: true };
|
2023-11-27 18:00:59 -05:00
|
|
|
},
|
|
|
|
exit: (code) => {
|
|
|
|
exitCode = code;
|
|
|
|
},
|
|
|
|
packages: [
|
|
|
|
{
|
|
|
|
name: 'astro',
|
|
|
|
currentVersion: '1.0.0',
|
|
|
|
targetVersion: '2.0.0',
|
|
|
|
isMajor: true,
|
|
|
|
changelogTitle: 'CHANGELOG',
|
2023-11-27 18:02:46 -05:00
|
|
|
changelogURL: 'https://example.com',
|
|
|
|
},
|
|
|
|
],
|
2023-11-27 18:00:59 -05:00
|
|
|
};
|
|
|
|
await install(context);
|
2024-01-12 02:53:00 -05:00
|
|
|
assert.equal(fixture.hasMessage('▲ astro can be updated to v2.0.0'), true);
|
|
|
|
assert.equal(prompted, true);
|
|
|
|
assert.equal(exitCode, undefined);
|
|
|
|
assert.equal(fixture.hasMessage('check Be sure to follow the CHANGELOG.'), true);
|
2023-11-27 18:00:59 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('multiple major', async () => {
|
|
|
|
let prompted = false;
|
|
|
|
let exitCode;
|
|
|
|
const context = {
|
|
|
|
...ctx,
|
2023-11-27 18:02:46 -05:00
|
|
|
prompt: () => {
|
2023-11-27 18:00:59 -05:00
|
|
|
prompted = true;
|
2023-11-27 18:02:46 -05:00
|
|
|
return { proceed: true };
|
2023-11-27 18:00:59 -05:00
|
|
|
},
|
|
|
|
exit: (code) => {
|
|
|
|
exitCode = code;
|
|
|
|
},
|
|
|
|
packages: [
|
|
|
|
{
|
|
|
|
name: 'a',
|
|
|
|
currentVersion: '1.0.0',
|
|
|
|
targetVersion: '2.0.0',
|
|
|
|
isMajor: true,
|
|
|
|
changelogTitle: 'CHANGELOG',
|
2023-11-27 18:02:46 -05:00
|
|
|
changelogURL: 'https://example.com',
|
2023-11-27 18:00:59 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'b',
|
|
|
|
currentVersion: '6.0.0',
|
|
|
|
targetVersion: '7.0.0',
|
|
|
|
isMajor: true,
|
|
|
|
changelogTitle: 'CHANGELOG',
|
2023-11-27 18:02:46 -05:00
|
|
|
changelogURL: 'https://example.com',
|
|
|
|
},
|
|
|
|
],
|
2023-11-27 18:00:59 -05:00
|
|
|
};
|
|
|
|
await install(context);
|
2024-01-12 02:53:00 -05:00
|
|
|
assert.equal(fixture.hasMessage('▲ a can be updated to v2.0.0'), true);
|
|
|
|
assert.equal(fixture.hasMessage('▲ b can be updated to v7.0.0'), true);
|
|
|
|
assert.equal(prompted, true);
|
|
|
|
assert.equal(exitCode, undefined);
|
2023-11-27 18:00:59 -05:00
|
|
|
const [changelog, a, b] = fixture.messages().slice(-5);
|
2024-01-12 02:53:00 -05:00
|
|
|
assert.match(changelog, /^check/);
|
|
|
|
assert.match(a, /^a/);
|
|
|
|
assert.match(b, /^b/);
|
2023-11-27 18:00:59 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('current patch minor major', async () => {
|
|
|
|
let prompted = false;
|
|
|
|
let exitCode;
|
|
|
|
const context = {
|
|
|
|
...ctx,
|
2023-11-27 18:02:46 -05:00
|
|
|
prompt: () => {
|
2023-11-27 18:00:59 -05:00
|
|
|
prompted = true;
|
2023-11-27 18:02:46 -05:00
|
|
|
return { proceed: true };
|
2023-11-27 18:00:59 -05:00
|
|
|
},
|
|
|
|
exit: (code) => {
|
|
|
|
exitCode = code;
|
|
|
|
},
|
|
|
|
packages: [
|
|
|
|
{
|
|
|
|
name: 'current',
|
|
|
|
currentVersion: '1.0.0',
|
|
|
|
targetVersion: '1.0.0',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'patch',
|
|
|
|
currentVersion: '1.0.0',
|
|
|
|
targetVersion: '1.0.1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'minor',
|
|
|
|
currentVersion: '1.0.0',
|
|
|
|
targetVersion: '1.2.0',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'major',
|
|
|
|
currentVersion: '1.0.0',
|
|
|
|
targetVersion: '3.0.0',
|
|
|
|
isMajor: true,
|
|
|
|
changelogTitle: 'CHANGELOG',
|
2023-11-27 18:02:46 -05:00
|
|
|
changelogURL: 'https://example.com',
|
|
|
|
},
|
|
|
|
],
|
2023-11-27 18:00:59 -05:00
|
|
|
};
|
|
|
|
await install(context);
|
2024-01-12 02:53:00 -05:00
|
|
|
assert.equal(fixture.hasMessage('◼ current is up to date on v1.0.0'), true);
|
|
|
|
assert.equal(fixture.hasMessage('● patch can be updated to v1.0.1'), true);
|
|
|
|
assert.equal(fixture.hasMessage('● minor can be updated to v1.2.0'), true);
|
|
|
|
assert.equal(fixture.hasMessage('▲ major can be updated to v3.0.0'), true);
|
|
|
|
assert.equal(prompted, true);
|
|
|
|
assert.equal(exitCode, undefined);
|
|
|
|
assert.equal(fixture.hasMessage('check Be sure to follow the CHANGELOG.'), true);
|
2023-11-27 18:00:59 -05:00
|
|
|
const [changelog, major] = fixture.messages().slice(-4);
|
2024-01-12 02:53:00 -05:00
|
|
|
assert.match(changelog, /^check/);
|
2024-01-12 02:54:11 -05:00
|
|
|
assert.match(major, /^major/);
|
2023-11-27 18:00:59 -05:00
|
|
|
});
|
|
|
|
});
|