aboutsummaryrefslogtreecommitdiff
path: root/packages/upgrade/test/install.test.js
diff options
context:
space:
mode:
authorGravatar github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> 2025-06-05 14:25:23 +0000
committerGravatar github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> 2025-06-05 14:25:23 +0000
commite586d7d704d475afe3373a1de6ae20d504f79d6d (patch)
tree7e3fa24807cebd48a86bd40f866d792181191ee9 /packages/upgrade/test/install.test.js
downloadastro-latest.tar.gz
astro-latest.tar.zst
astro-latest.zip
Sync from a8e1c0a7402940e0fc5beef669522b315052df1blatest
Diffstat (limited to 'packages/upgrade/test/install.test.js')
-rw-r--r--packages/upgrade/test/install.test.js212
1 files changed, 212 insertions, 0 deletions
diff --git a/packages/upgrade/test/install.test.js b/packages/upgrade/test/install.test.js
new file mode 100644
index 000000000..c4d56dfbe
--- /dev/null
+++ b/packages/upgrade/test/install.test.js
@@ -0,0 +1,212 @@
+import * as assert from 'node:assert/strict';
+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,
+ };
+
+ it('up to date', async () => {
+ const context = {
+ ...ctx,
+ packages: [
+ {
+ name: 'astro',
+ currentVersion: '1.0.0',
+ targetVersion: '1.0.0',
+ },
+ ],
+ };
+ await install(context);
+ assert.equal(fixture.hasMessage('◼ astro is up to date on v1.0.0'), true);
+ });
+
+ it('patch', async () => {
+ const context = {
+ ...ctx,
+ packages: [
+ {
+ name: 'astro',
+ currentVersion: '1.0.0',
+ targetVersion: '1.0.1',
+ },
+ ],
+ };
+ await install(context);
+ assert.equal(fixture.hasMessage('● astro can be updated from v1.0.0 to v1.0.1'), true);
+ });
+
+ it('minor', async () => {
+ const context = {
+ ...ctx,
+ packages: [
+ {
+ name: 'astro',
+ currentVersion: '1.0.0',
+ targetVersion: '1.2.0',
+ },
+ ],
+ };
+ await install(context);
+ assert.equal(fixture.hasMessage('● astro can be updated from v1.0.0 to v1.2.0'), true);
+ });
+
+ it('major (reject)', async () => {
+ let prompted = false;
+ let exitCode;
+ const context = {
+ ...ctx,
+ prompt: () => {
+ prompted = true;
+ return { proceed: false };
+ },
+ exit: (code) => {
+ exitCode = code;
+ },
+ packages: [
+ {
+ name: 'astro',
+ currentVersion: '1.0.0',
+ targetVersion: '2.0.0',
+ isMajor: true,
+ changelogTitle: 'CHANGELOG',
+ changelogURL: 'https://example.com',
+ },
+ ],
+ };
+ await install(context);
+ assert.equal(fixture.hasMessage('▲ astro can be updated from v1.0.0 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);
+ });
+
+ it('major (accept)', async () => {
+ let prompted = false;
+ let exitCode;
+ const context = {
+ ...ctx,
+ prompt: () => {
+ prompted = true;
+ return { proceed: true };
+ },
+ exit: (code) => {
+ exitCode = code;
+ },
+ packages: [
+ {
+ name: 'astro',
+ currentVersion: '1.0.0',
+ targetVersion: '2.0.0',
+ isMajor: true,
+ changelogTitle: 'CHANGELOG',
+ changelogURL: 'https://example.com',
+ },
+ ],
+ };
+ await install(context);
+ assert.equal(fixture.hasMessage('▲ astro can be updated from v1.0.0 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);
+ });
+
+ it('multiple major', async () => {
+ let prompted = false;
+ let exitCode;
+ const context = {
+ ...ctx,
+ prompt: () => {
+ prompted = true;
+ return { proceed: true };
+ },
+ exit: (code) => {
+ exitCode = code;
+ },
+ packages: [
+ {
+ name: 'a',
+ currentVersion: '1.0.0',
+ targetVersion: '2.0.0',
+ isMajor: true,
+ changelogTitle: 'CHANGELOG',
+ changelogURL: 'https://example.com',
+ },
+ {
+ name: 'b',
+ currentVersion: '6.0.0',
+ targetVersion: '7.0.0',
+ isMajor: true,
+ changelogTitle: 'CHANGELOG',
+ changelogURL: 'https://example.com',
+ },
+ ],
+ };
+ await install(context);
+ assert.equal(fixture.hasMessage('▲ a can be updated from v1.0.0 to v2.0.0'), true);
+ assert.equal(fixture.hasMessage('▲ b can be updated from v6.0.0 to v7.0.0'), true);
+ assert.equal(prompted, true);
+ assert.equal(exitCode, undefined);
+ const [changelog, a, b] = fixture.messages().slice(-5);
+ assert.match(changelog, /^check/);
+ assert.match(a, /^a/);
+ assert.match(b, /^b/);
+ });
+
+ it('current patch minor major', async () => {
+ let prompted = false;
+ let exitCode;
+ const context = {
+ ...ctx,
+ prompt: () => {
+ prompted = true;
+ return { proceed: true };
+ },
+ 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',
+ changelogURL: 'https://example.com',
+ },
+ ],
+ };
+ await install(context);
+ assert.equal(fixture.hasMessage('◼ current is up to date on v1.0.0'), true);
+ assert.equal(fixture.hasMessage('● patch can be updated from v1.0.0 to v1.0.1'), true);
+ assert.equal(fixture.hasMessage('● minor can be updated from v1.0.0 to v1.2.0'), true);
+ assert.equal(fixture.hasMessage('▲ major can be updated from v1.0.0 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);
+ const [changelog, major] = fixture.messages().slice(-4);
+ assert.match(changelog, /^check/);
+ assert.match(major, /^major/);
+ });
+});