install.test.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. import { describe, it } from 'node:test';
  2. import * as assert from 'node:assert/strict';
  3. import { setup } from './utils.js';
  4. import { install } from '../dist/index.js';
  5. describe('install', () => {
  6. const fixture = setup();
  7. const ctx = {
  8. cwd: '',
  9. version: 'latest',
  10. packageManager: 'npm',
  11. dryRun: true,
  12. };
  13. it('up to date', async () => {
  14. const context = {
  15. ...ctx,
  16. packages: [
  17. {
  18. name: 'astro',
  19. currentVersion: '1.0.0',
  20. targetVersion: '1.0.0',
  21. },
  22. ],
  23. };
  24. await install(context);
  25. assert.equal(fixture.hasMessage('◼ astro is up to date on v1.0.0'), true);
  26. });
  27. it('patch', async () => {
  28. const context = {
  29. ...ctx,
  30. packages: [
  31. {
  32. name: 'astro',
  33. currentVersion: '1.0.0',
  34. targetVersion: '1.0.1',
  35. },
  36. ],
  37. };
  38. await install(context);
  39. assert.equal(fixture.hasMessage('● astro can be updated to v1.0.1'), true);
  40. });
  41. it('minor', async () => {
  42. const context = {
  43. ...ctx,
  44. packages: [
  45. {
  46. name: 'astro',
  47. currentVersion: '1.0.0',
  48. targetVersion: '1.2.0',
  49. },
  50. ],
  51. };
  52. await install(context);
  53. assert.equal(fixture.hasMessage('● astro can be updated to v1.2.0'), true);
  54. });
  55. it('major (reject)', async () => {
  56. let prompted = false;
  57. let exitCode;
  58. const context = {
  59. ...ctx,
  60. prompt: () => {
  61. prompted = true;
  62. return { proceed: false };
  63. },
  64. exit: (code) => {
  65. exitCode = code;
  66. },
  67. packages: [
  68. {
  69. name: 'astro',
  70. currentVersion: '1.0.0',
  71. targetVersion: '2.0.0',
  72. isMajor: true,
  73. changelogTitle: 'CHANGELOG',
  74. changelogURL: 'https://example.com',
  75. },
  76. ],
  77. };
  78. await install(context);
  79. assert.equal(fixture.hasMessage('▲ astro can be updated to v2.0.0'), true);
  80. assert.equal(prompted, true);
  81. assert.equal(exitCode, 0);
  82. assert.equal(fixture.hasMessage('check Be sure to follow the CHANGELOG.'), false);
  83. });
  84. it('major (accept)', async () => {
  85. let prompted = false;
  86. let exitCode;
  87. const context = {
  88. ...ctx,
  89. prompt: () => {
  90. prompted = true;
  91. return { proceed: true };
  92. },
  93. exit: (code) => {
  94. exitCode = code;
  95. },
  96. packages: [
  97. {
  98. name: 'astro',
  99. currentVersion: '1.0.0',
  100. targetVersion: '2.0.0',
  101. isMajor: true,
  102. changelogTitle: 'CHANGELOG',
  103. changelogURL: 'https://example.com',
  104. },
  105. ],
  106. };
  107. await install(context);
  108. assert.equal(fixture.hasMessage('▲ astro can be updated to v2.0.0'), true);
  109. assert.equal(prompted, true);
  110. assert.equal(exitCode, undefined);
  111. assert.equal(fixture.hasMessage('check Be sure to follow the CHANGELOG.'), true);
  112. });
  113. it('multiple major', async () => {
  114. let prompted = false;
  115. let exitCode;
  116. const context = {
  117. ...ctx,
  118. prompt: () => {
  119. prompted = true;
  120. return { proceed: true };
  121. },
  122. exit: (code) => {
  123. exitCode = code;
  124. },
  125. packages: [
  126. {
  127. name: 'a',
  128. currentVersion: '1.0.0',
  129. targetVersion: '2.0.0',
  130. isMajor: true,
  131. changelogTitle: 'CHANGELOG',
  132. changelogURL: 'https://example.com',
  133. },
  134. {
  135. name: 'b',
  136. currentVersion: '6.0.0',
  137. targetVersion: '7.0.0',
  138. isMajor: true,
  139. changelogTitle: 'CHANGELOG',
  140. changelogURL: 'https://example.com',
  141. },
  142. ],
  143. };
  144. await install(context);
  145. assert.equal(fixture.hasMessage('▲ a can be updated to v2.0.0'), true);
  146. assert.equal(fixture.hasMessage('▲ b can be updated to v7.0.0'), true);
  147. assert.equal(prompted, true);
  148. assert.equal(exitCode, undefined);
  149. const [changelog, a, b] = fixture.messages().slice(-5);
  150. assert.match(changelog, /^check/);
  151. assert.match(a, /^a/);
  152. assert.match(b, /^b/);
  153. });
  154. it('current patch minor major', async () => {
  155. let prompted = false;
  156. let exitCode;
  157. const context = {
  158. ...ctx,
  159. prompt: () => {
  160. prompted = true;
  161. return { proceed: true };
  162. },
  163. exit: (code) => {
  164. exitCode = code;
  165. },
  166. packages: [
  167. {
  168. name: 'current',
  169. currentVersion: '1.0.0',
  170. targetVersion: '1.0.0',
  171. },
  172. {
  173. name: 'patch',
  174. currentVersion: '1.0.0',
  175. targetVersion: '1.0.1',
  176. },
  177. {
  178. name: 'minor',
  179. currentVersion: '1.0.0',
  180. targetVersion: '1.2.0',
  181. },
  182. {
  183. name: 'major',
  184. currentVersion: '1.0.0',
  185. targetVersion: '3.0.0',
  186. isMajor: true,
  187. changelogTitle: 'CHANGELOG',
  188. changelogURL: 'https://example.com',
  189. },
  190. ],
  191. };
  192. await install(context);
  193. assert.equal(fixture.hasMessage('◼ current is up to date on v1.0.0'), true);
  194. assert.equal(fixture.hasMessage('● patch can be updated to v1.0.1'), true);
  195. assert.equal(fixture.hasMessage('● minor can be updated to v1.2.0'), true);
  196. assert.equal(fixture.hasMessage('▲ major can be updated to v3.0.0'), true);
  197. assert.equal(prompted, true);
  198. assert.equal(exitCode, undefined);
  199. assert.equal(fixture.hasMessage('check Be sure to follow the CHANGELOG.'), true);
  200. const [changelog, major] = fixture.messages().slice(-4);
  201. assert.match(changelog, /^check/);
  202. assert.match(major, /^major/);
  203. });
  204. });