@neurodevs/meta-node 0.14.29 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/build/__tests__/AbstractPackageTest.d.ts +4 -0
  2. package/build/__tests__/AbstractPackageTest.js +11 -1
  3. package/build/__tests__/AbstractPackageTest.js.map +1 -1
  4. package/build/__tests__/impl/GitAutocloner.test.js +9 -9
  5. package/build/__tests__/impl/GitAutocloner.test.js.map +1 -1
  6. package/build/__tests__/impl/GitAutocommit.test.d.ts +11 -0
  7. package/build/__tests__/impl/GitAutocommit.test.js +49 -0
  8. package/build/__tests__/impl/GitAutocommit.test.js.map +1 -0
  9. package/build/__tests__/impl/ImplAutomodule.test.js +1 -1
  10. package/build/__tests__/impl/ImplAutomodule.test.js.map +1 -1
  11. package/build/__tests__/impl/NpmAutopackage.test.d.ts +1 -3
  12. package/build/__tests__/impl/NpmAutopackage.test.js +38 -64
  13. package/build/__tests__/impl/NpmAutopackage.test.js.map +1 -1
  14. package/build/__tests__/impl/NpmPropagationCoordinator.test.d.ts +18 -0
  15. package/build/__tests__/impl/NpmPropagationCoordinator.test.js +73 -0
  16. package/build/__tests__/impl/NpmPropagationCoordinator.test.js.map +1 -0
  17. package/build/__tests__/impl/NpmReleasePropagator.test.d.ts +17 -0
  18. package/build/__tests__/impl/NpmReleasePropagator.test.js +115 -0
  19. package/build/__tests__/impl/NpmReleasePropagator.test.js.map +1 -0
  20. package/build/__tests__/impl/UiAutomodule.test.js +1 -1
  21. package/build/__tests__/impl/UiAutomodule.test.js.map +1 -1
  22. package/build/impl/GitAutocommit.d.ts +15 -0
  23. package/build/impl/GitAutocommit.js +27 -0
  24. package/build/impl/GitAutocommit.js.map +1 -0
  25. package/build/impl/NpmAutopackage.d.ts +1 -9
  26. package/build/impl/NpmAutopackage.js +11 -48
  27. package/build/impl/NpmAutopackage.js.map +1 -1
  28. package/build/impl/NpmPropagationCoordinator.d.ts +23 -0
  29. package/build/impl/NpmPropagationCoordinator.js +59 -0
  30. package/build/impl/NpmPropagationCoordinator.js.map +1 -0
  31. package/build/impl/NpmReleasePropagator.d.ts +41 -0
  32. package/build/impl/NpmReleasePropagator.js +78 -0
  33. package/build/impl/NpmReleasePropagator.js.map +1 -0
  34. package/build/index.d.ts +12 -0
  35. package/build/index.js +15 -0
  36. package/build/index.js.map +1 -1
  37. package/build/scripts/runNpmReleasePropagator.d.ts +1 -0
  38. package/build/scripts/runNpmReleasePropagator.js +8 -0
  39. package/build/scripts/runNpmReleasePropagator.js.map +1 -0
  40. package/build/testDoubles/Autocommit/FakeAutocommit.d.ts +11 -0
  41. package/build/testDoubles/Autocommit/FakeAutocommit.js +18 -0
  42. package/build/testDoubles/Autocommit/FakeAutocommit.js.map +1 -0
  43. package/build/testDoubles/PropagationCoordinator/FakePropagationCoordinator.d.ts +11 -0
  44. package/build/testDoubles/PropagationCoordinator/FakePropagationCoordinator.js +18 -0
  45. package/build/testDoubles/PropagationCoordinator/FakePropagationCoordinator.js.map +1 -0
  46. package/build/testDoubles/ReleasePropagator/FakeReleasePropagator.d.ts +8 -0
  47. package/build/testDoubles/ReleasePropagator/FakeReleasePropagator.js +15 -0
  48. package/build/testDoubles/ReleasePropagator/FakeReleasePropagator.js.map +1 -0
  49. package/package.json +3 -3
  50. package/src/__tests__/AbstractPackageTest.ts +27 -1
  51. package/src/__tests__/impl/GitAutocloner.test.ts +13 -9
  52. package/src/__tests__/impl/GitAutocommit.test.ts +60 -0
  53. package/src/__tests__/impl/ImplAutomodule.test.ts +1 -1
  54. package/src/__tests__/impl/NpmAutopackage.test.ts +60 -91
  55. package/src/__tests__/impl/NpmPropagationCoordinator.test.ts +93 -0
  56. package/src/__tests__/impl/NpmReleasePropagator.test.ts +151 -0
  57. package/src/__tests__/impl/UiAutomodule.test.ts +1 -1
  58. package/src/impl/GitAutocommit.ts +40 -0
  59. package/src/impl/NpmAutopackage.ts +20 -64
  60. package/src/impl/NpmPropagationCoordinator.ts +94 -0
  61. package/src/impl/NpmReleasePropagator.ts +135 -0
  62. package/src/index.ts +24 -0
  63. package/src/scripts/runNpmReleasePropagator.ts +9 -0
  64. package/src/testDoubles/Autocommit/FakeAutocommit.ts +26 -0
  65. package/src/testDoubles/PropagationCoordinator/FakePropagationCoordinator.ts +26 -0
  66. package/src/testDoubles/ReleasePropagator/FakeReleasePropagator.ts +23 -0
@@ -0,0 +1,60 @@
1
+ import { exec as execSync } from 'node:child_process'
2
+ import { promisify } from 'node:util'
3
+
4
+ import {
5
+ callsToExec,
6
+ fakeExec,
7
+ resetCallsToExec,
8
+ } from '@neurodevs/fake-node-core'
9
+ import AbstractModuleTest, { test, assert } from '@neurodevs/node-tdd'
10
+
11
+ import GitAutocommit, { Autocommit } from '../../impl/GitAutocommit.js'
12
+
13
+ const exec = promisify(execSync)
14
+
15
+ export default class GitAutocommitTest extends AbstractModuleTest {
16
+ private static instance: Autocommit
17
+
18
+ private static readonly commitMessage = this.generateId()
19
+ private static readonly currentWorkingDir = this.generateId()
20
+
21
+ protected static async beforeEach() {
22
+ await super.beforeEach()
23
+
24
+ this.setFakeExec()
25
+
26
+ this.instance = await this.GitAutocommit()
27
+ }
28
+
29
+ @test()
30
+ protected static async createsInstance() {
31
+ assert.isTruthy(this.instance, 'Failed to create instance!')
32
+ }
33
+
34
+ @test()
35
+ protected static async callsExecThreeTimes() {
36
+ assert.isEqualDeep(callsToExec, [
37
+ { command: 'git add .', options: { cwd: this.currentWorkingDir } },
38
+ {
39
+ command: `git commit -m "${this.commitMessage}"`,
40
+ options: { cwd: this.currentWorkingDir },
41
+ },
42
+ { command: 'git push', options: { cwd: this.currentWorkingDir } },
43
+ ])
44
+ }
45
+
46
+ private static setFakeExec() {
47
+ GitAutocommit.exec = fakeExec as unknown as typeof exec
48
+ resetCallsToExec()
49
+ }
50
+
51
+ private static async GitAutocommit(
52
+ commitMessage?: string,
53
+ workingDir?: string
54
+ ) {
55
+ return GitAutocommit.Create(
56
+ commitMessage ?? this.commitMessage,
57
+ workingDir ?? this.currentWorkingDir
58
+ )
59
+ }
60
+ }
@@ -121,7 +121,7 @@ export default class ImplAutomoduleTest extends AbstractAutomoduleTest {
121
121
  await this.run()
122
122
 
123
123
  assert.isEqualDeep(
124
- callsToExec[0],
124
+ callsToExec[0]?.command,
125
125
  'yarn version --minor --no-git-tag-version',
126
126
  'Did not bump minor version!'
127
127
  )
@@ -1,7 +1,6 @@
1
1
  import { ChildProcess, exec as execSync } from 'child_process'
2
2
  import { readFile, writeFile } from 'fs/promises'
3
3
  import { mkdir } from 'fs/promises'
4
- import path from 'path'
5
4
  import { promisify } from 'util'
6
5
  import {
7
6
  callsToChdir,
@@ -31,10 +30,12 @@ import {
31
30
  } from '@neurodevs/fake-node-core'
32
31
  import { test, assert } from '@neurodevs/node-tdd'
33
32
 
33
+ import GitAutocommit from '../../impl/GitAutocommit.js'
34
34
  import NpmAutopackage, {
35
35
  Autopackage,
36
36
  AutopackageOptions,
37
37
  } from '../../impl/NpmAutopackage.js'
38
+ import FakeAutocommit from '../../testDoubles/Autocommit/FakeAutocommit.js'
38
39
  import AbstractPackageTest from '../AbstractPackageTest.js'
39
40
 
40
41
  const exec = promisify(execSync)
@@ -53,6 +54,8 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
53
54
  this.fakeReadFile()
54
55
  this.fakeWriteFile()
55
56
 
57
+ this.setFakeAutocommit()
58
+
56
59
  this.fakeFetchForRepoNotFound()
57
60
 
58
61
  process.env.GITHUB_TOKEN = this.githubToken
@@ -127,7 +130,7 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
127
130
  await this.run()
128
131
 
129
132
  assert.isEqual(
130
- callsToExec[0],
133
+ callsToExec[0]?.command,
131
134
  `git clone https://github.com/${this.gitNamespace}/${this.name}.git`,
132
135
  'Did not call git clone!'
133
136
  )
@@ -149,7 +152,7 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
149
152
  await this.run()
150
153
 
151
154
  assert.isEqual(
152
- callsToExec[1],
155
+ callsToExec[1]?.command,
153
156
  `git fetch origin`,
154
157
  'Did not call git fetch origin!'
155
158
  )
@@ -160,7 +163,7 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
160
163
  await this.run()
161
164
 
162
165
  assert.isEqual(
163
- callsToExec[2],
166
+ callsToExec[2]?.command,
164
167
  `git reset --hard origin/main`,
165
168
  'Did not call git reset hard!'
166
169
  )
@@ -171,7 +174,7 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
171
174
  await this.run()
172
175
 
173
176
  assert.isEqual(
174
- callsToExec[4],
177
+ callsToExec[4]?.command,
175
178
  this.createModuleCmd,
176
179
  'Did not call "spruce create.module"!'
177
180
  )
@@ -182,12 +185,8 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
182
185
  await this.run()
183
186
 
184
187
  assert.isEqualDeep(
185
- callsToExec.slice(5, 8),
186
- [
187
- 'git add .',
188
- `git commit -m "patch: create package (@neurodevs/meta-node: ${this.metaNodeVersion})"`,
189
- 'git push',
190
- ],
188
+ FakeAutocommit.callsToConstructor[0]?.commitMessage,
189
+ `patch: create package (@neurodevs/meta-node: ${this.metaNodeVersion})`,
191
190
  'Did not commit create package changes!'
192
191
  )
193
192
  }
@@ -255,12 +254,8 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
255
254
  await this.run()
256
255
 
257
256
  assert.isEqualDeep(
258
- callsToExec.slice(8, 11),
259
- [
260
- 'git add .',
261
- `git commit -m "patch: update package.json (@neurodevs/meta-node: ${this.metaNodeVersion})"`,
262
- 'git push',
263
- ],
257
+ FakeAutocommit.callsToConstructor[1]?.commitMessage,
258
+ `patch: update package.json (@neurodevs/meta-node: ${this.metaNodeVersion})`,
264
259
  'Did not commit update package changes!'
265
260
  )
266
261
  }
@@ -285,12 +280,8 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
285
280
  await this.run()
286
281
 
287
282
  assert.isEqualDeep(
288
- callsToExec.slice(11, 14),
289
- [
290
- 'git add .',
291
- `git commit -m "patch: add build dir to gitignore (@neurodevs/meta-node: ${this.metaNodeVersion})"`,
292
- 'git push',
293
- ],
283
+ FakeAutocommit.callsToConstructor[2]?.commitMessage,
284
+ `patch: add build dir to gitignore (@neurodevs/meta-node: ${this.metaNodeVersion})`,
294
285
  'Did not commit .gitignore changes!'
295
286
  )
296
287
  }
@@ -300,7 +291,7 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
300
291
  await this.run()
301
292
 
302
293
  assert.isEqual(
303
- callsToExec[14],
294
+ callsToExec[5]?.command,
304
295
  this.setupVscodeCmd,
305
296
  'Did not call "spruce setup.vscode"!'
306
297
  )
@@ -311,12 +302,8 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
311
302
  await this.run()
312
303
 
313
304
  assert.isEqualDeep(
314
- callsToExec.slice(15, 18),
315
- [
316
- 'git add .',
317
- `git commit -m "patch: setup vscode (@neurodevs/meta-node: ${this.metaNodeVersion})"`,
318
- 'git push',
319
- ],
305
+ FakeAutocommit.callsToConstructor[3]?.commitMessage,
306
+ `patch: setup vscode (@neurodevs/meta-node: ${this.metaNodeVersion})`,
320
307
  'Did not commit vscode changes!'
321
308
  )
322
309
  }
@@ -337,12 +324,8 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
337
324
  await this.run()
338
325
 
339
326
  assert.isEqualDeep(
340
- callsToExec.slice(18, 21),
341
- [
342
- 'git add .',
343
- `git commit -m "patch: update vscode tasks.json (@neurodevs/meta-node: ${this.metaNodeVersion})"`,
344
- 'git push',
345
- ],
327
+ FakeAutocommit.callsToConstructor[4]?.commitMessage,
328
+ `patch: update vscode tasks.json (@neurodevs/meta-node: ${this.metaNodeVersion})`,
346
329
  'Did not commit updated vscode tasks.json changes!'
347
330
  )
348
331
  }
@@ -352,7 +335,7 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
352
335
  await this.run()
353
336
 
354
337
  assert.isEqual(
355
- callsToExec[23],
338
+ callsToExec[8]?.command,
356
339
  this.yarnInstallDevDepsCommand,
357
340
  'Did not install default devDependencies!'
358
341
  )
@@ -363,12 +346,8 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
363
346
  await this.run()
364
347
 
365
348
  assert.isEqualDeep(
366
- callsToExec.slice(24, 27),
367
- [
368
- 'git add .',
369
- `git commit -m "patch: install default devDependencies (@neurodevs/meta-node: ${this.metaNodeVersion})"`,
370
- 'git push',
371
- ],
349
+ FakeAutocommit.callsToConstructor[5]?.commitMessage,
350
+ `patch: install default devDependencies (@neurodevs/meta-node: ${this.metaNodeVersion})`,
372
351
  'Did not commit install devDependencies changes!'
373
352
  )
374
353
  }
@@ -407,12 +386,8 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
407
386
  await this.run()
408
387
 
409
388
  assert.isEqualDeep(
410
- callsToExec.slice(27, 30),
411
- [
412
- 'git add .',
413
- `git commit -m "patch: install AbstractPackageTest (@neurodevs/meta-node: ${this.metaNodeVersion})"`,
414
- 'git push',
415
- ],
389
+ FakeAutocommit.callsToConstructor[6]?.commitMessage,
390
+ `patch: install AbstractPackageTest (@neurodevs/meta-node: ${this.metaNodeVersion})`,
416
391
  'Did not commit install AbstractPackageTest changes!'
417
392
  )
418
393
  }
@@ -421,7 +396,11 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
421
396
  protected static async lastlyOpensVscodeAtEnd() {
422
397
  await this.run()
423
398
 
424
- assert.isEqual(callsToExec[30], 'code .', 'Did not open vscode at end!')
399
+ assert.isEqual(
400
+ callsToExec[9]?.command,
401
+ 'code .',
402
+ 'Did not open vscode at end!'
403
+ )
425
404
  }
426
405
 
427
406
  @test()
@@ -448,8 +427,8 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
448
427
 
449
428
  assert.isEqual(
450
429
  callsToExec.filter(
451
- (cmd) =>
452
- cmd ===
430
+ (call) =>
431
+ call?.command ===
453
432
  `git clone https://github.com/${this.gitNamespace}/${this.name}.git`
454
433
  ).length,
455
434
  1,
@@ -462,7 +441,8 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
462
441
  await this.createAndRunAutopackage()
463
442
 
464
443
  assert.isEqual(
465
- callsToExec.filter((cmd) => cmd === this.createModuleCmd).length,
444
+ callsToExec.filter((call) => call?.command === this.createModuleCmd)
445
+ .length,
466
446
  1,
467
447
  'Did not call spruce create.module once!'
468
448
  )
@@ -473,7 +453,8 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
473
453
  await this.createAndRunAutopackage()
474
454
 
475
455
  assert.isEqual(
476
- callsToExec.filter((cmd) => cmd === this.setupVscodeCmd).length,
456
+ callsToExec.filter((call) => call?.command === this.setupVscodeCmd)
457
+ .length,
477
458
  1,
478
459
  'Did not call spruce setup.vscode once!'
479
460
  )
@@ -484,10 +465,10 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
484
465
  await this.createAndRunAutopackage()
485
466
 
486
467
  assert.isEqual(
487
- callsToExec.filter(
488
- (cmd) =>
489
- cmd ===
490
- `git commit -m "patch: create package (@neurodevs/meta-node: ${this.metaNodeVersion})"`
468
+ FakeAutocommit.callsToConstructor.filter(
469
+ (call) =>
470
+ call?.commitMessage ===
471
+ `patch: create package (@neurodevs/meta-node: ${this.metaNodeVersion})`
491
472
  ).length,
492
473
  1,
493
474
  'Did not commit create package changes once!'
@@ -499,10 +480,10 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
499
480
  await this.createAndRunAutopackage()
500
481
 
501
482
  assert.isEqual(
502
- callsToExec.filter(
503
- (cmd) =>
504
- cmd ===
505
- `git commit -m "patch: update package.json (@neurodevs/meta-node: ${this.metaNodeVersion})"`
483
+ FakeAutocommit.callsToConstructor.filter(
484
+ (call) =>
485
+ call?.commitMessage ===
486
+ `patch: update package.json (@neurodevs/meta-node: ${this.metaNodeVersion})`
506
487
  ).length,
507
488
  1,
508
489
  'Did not commit update package changes once!'
@@ -514,10 +495,10 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
514
495
  await this.createAndRunAutopackage()
515
496
 
516
497
  assert.isEqual(
517
- callsToExec.filter(
518
- (cmd) =>
519
- cmd ===
520
- `git commit -m "patch: add build dir to gitignore (@neurodevs/meta-node: ${this.metaNodeVersion})"`
498
+ FakeAutocommit.callsToConstructor.filter(
499
+ (call) =>
500
+ call?.commitMessage ===
501
+ `patch: add build dir to gitignore (@neurodevs/meta-node: ${this.metaNodeVersion})`
521
502
  ).length,
522
503
  1,
523
504
  'Did not commit gitignore changes once!'
@@ -529,10 +510,10 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
529
510
  await this.createAndRunAutopackage()
530
511
 
531
512
  assert.isEqual(
532
- callsToExec.filter(
533
- (cmd) =>
534
- cmd ===
535
- `git commit -m "patch: setup vscode (@neurodevs/meta-node: ${this.metaNodeVersion})"`
513
+ FakeAutocommit.callsToConstructor.filter(
514
+ (call) =>
515
+ call?.commitMessage ===
516
+ `patch: setup vscode (@neurodevs/meta-node: ${this.metaNodeVersion})`
536
517
  ).length,
537
518
  1,
538
519
  'Did not commit vscode changes once!'
@@ -571,7 +552,7 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
571
552
  await this.createAndRunAutopackage()
572
553
 
573
554
  assert.isFalse(
574
- callsToExec.includes('code .'),
555
+ callsToExec.some((call) => call?.command === 'code .'),
575
556
  'Should not open vscode if not cloned!'
576
557
  )
577
558
  }
@@ -585,7 +566,7 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
585
566
  await this.createAndRunAutopackage()
586
567
 
587
568
  const calls = callsToExec.filter(
588
- (cmd) => cmd === this.yarnInstallDevDepsCommand
569
+ (call) => call?.command === this.yarnInstallDevDepsCommand
589
570
  )
590
571
 
591
572
  assert.isEqual(
@@ -608,7 +589,7 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
608
589
  await this.createAndRunAutopackage()
609
590
 
610
591
  const calls = callsToExec.filter(
611
- (cmd) => cmd === this.yarnInstallDevDepsCommand
592
+ (call) => call?.command === this.yarnInstallDevDepsCommand
612
593
  )
613
594
 
614
595
  assert.isEqual(
@@ -709,9 +690,6 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
709
690
  private static readonly checkGenerateIdVersionCmd = `yarn info @neurodevs/generate-id version --silent`
710
691
  private static readonly checkNodeTddVersionCmd = `yarn info @neurodevs/node-tdd version --silent`
711
692
 
712
- private static readonly yarnGlobalDirCmd = 'yarn global dir'
713
- private static readonly fakeGlobalRoot = this.generateId()
714
-
715
693
  private static orderJsonKeys(
716
694
  json: Record<string, unknown>,
717
695
  keyOrder: string[]
@@ -744,20 +722,7 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
744
722
  NpmAutopackage.exec = fakeExec as unknown as typeof exec
745
723
  resetCallsToExec()
746
724
 
747
- setFakeExecResult(this.yarnGlobalDirCmd, {
748
- stdout: this.fakeGlobalRoot,
749
- } as unknown as ChildProcess)
750
-
751
- setFakeReadFileResult(
752
- path.join(
753
- this.fakeGlobalRoot,
754
- 'node_modules',
755
- '@neurodevs',
756
- 'meta-node',
757
- 'package.json'
758
- ),
759
- JSON.stringify({ version: this.metaNodeVersion })
760
- )
725
+ this.setFakeMetaNodeVersion()
761
726
  }
762
727
 
763
728
  private static fakeFetch() {
@@ -794,6 +759,11 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
794
759
  resetCallsToWriteFile()
795
760
  }
796
761
 
762
+ private static setFakeAutocommit() {
763
+ GitAutocommit.Class = FakeAutocommit
764
+ FakeAutocommit.resetTestDouble()
765
+ }
766
+
797
767
  private static fakeFetchForRepoNotFound() {
798
768
  const fakeResponse = new Response(null, {
799
769
  status: 404,
@@ -813,7 +783,6 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
813
783
  private static readonly author = this.generateId()
814
784
 
815
785
  private static readonly githubToken = this.generateId()
816
- private static readonly metaNodeVersion = this.generateId()
817
786
  private static readonly randomId = this.generateId()
818
787
 
819
788
  private static get reposUrl() {
@@ -0,0 +1,93 @@
1
+ import { readFile } from 'node:fs/promises'
2
+
3
+ import {
4
+ fakeReadFile,
5
+ resetCallsToReadFile,
6
+ setFakeReadFileResult,
7
+ } from '@neurodevs/fake-node-core'
8
+ import AbstractModuleTest, { test, assert } from '@neurodevs/node-tdd'
9
+
10
+ import NpmPropagationCoordinator, {
11
+ PropagationCoordinator,
12
+ } from '../../impl/NpmPropagationCoordinator.js'
13
+ import NpmReleasePropagator from '../../impl/NpmReleasePropagator.js'
14
+ import FakeReleasePropagator from '../../testDoubles/ReleasePropagator/FakeReleasePropagator.js'
15
+
16
+ export default class NpmPropagationCoordinatorTest extends AbstractModuleTest {
17
+ private static instance: PropagationCoordinator
18
+
19
+ private static readonly packageScope = this.generateId()
20
+ private static readonly packageName = this.generateId()
21
+ private static readonly scopedName = `${this.packageScope}/${this.packageName}`
22
+ private static readonly packageVersion = '7.8.9'
23
+ private static readonly repoPath = `${this.generateId()}/${this.packageName}`
24
+
25
+ private static readonly repoPaths = [
26
+ this.generateId(),
27
+ this.generateId(),
28
+ this.generateId(),
29
+ this.repoPath,
30
+ ]
31
+
32
+ private static readonly pkgJsons = [
33
+ { dependencies: { [this.repoPath]: '^1.2.3' } },
34
+ { devDependencies: { [this.repoPath]: '^4.5.6' } },
35
+ {},
36
+ { name: this.scopedName, version: this.packageVersion },
37
+ ]
38
+
39
+ protected static async beforeEach() {
40
+ await super.beforeEach()
41
+
42
+ this.setFakeReadFile()
43
+ this.setFakeReleasePropagator()
44
+
45
+ this.instance = this.NpmPropagationCoordinator()
46
+ }
47
+
48
+ @test()
49
+ protected static async createsInstance() {
50
+ assert.isTruthy(this.instance, 'Failed to create instance!')
51
+ }
52
+
53
+ @test()
54
+ protected static async propagatesToCorrectRepoPaths() {
55
+ await this.run()
56
+
57
+ assert.isEqualDeep(
58
+ FakeReleasePropagator.callsToConstructor[0],
59
+ {
60
+ packageName: this.scopedName,
61
+ packageVersion: this.packageVersion,
62
+ repoPaths: [this.repoPaths[0], this.repoPaths[1]],
63
+ },
64
+ 'Incorrect repo paths propagated to!'
65
+ )
66
+ }
67
+
68
+ private static async run() {
69
+ await this.instance.run()
70
+ }
71
+
72
+ private static setFakeReadFile() {
73
+ NpmPropagationCoordinator.readFile =
74
+ fakeReadFile as unknown as typeof readFile
75
+ resetCallsToReadFile()
76
+
77
+ this.repoPaths.forEach((repoPath, i) => {
78
+ setFakeReadFileResult(
79
+ `${repoPath}/package.json`,
80
+ JSON.stringify(this.pkgJsons[i], null, 4)
81
+ )
82
+ })
83
+ }
84
+
85
+ private static setFakeReleasePropagator() {
86
+ NpmReleasePropagator.Class = FakeReleasePropagator
87
+ FakeReleasePropagator.resetTestDouble()
88
+ }
89
+
90
+ private static NpmPropagationCoordinator() {
91
+ return NpmPropagationCoordinator.Create(this.repoPath, this.repoPaths)
92
+ }
93
+ }
@@ -0,0 +1,151 @@
1
+ import { exec as execSync } from 'node:child_process'
2
+ import { readFile } from 'node:fs/promises'
3
+ import { promisify } from 'node:util'
4
+ import {
5
+ callsToExec,
6
+ fakeExec,
7
+ fakeReadFile,
8
+ resetCallsToExec,
9
+ resetCallsToReadFile,
10
+ setFakeReadFileResult,
11
+ } from '@neurodevs/fake-node-core'
12
+ import { test, assert } from '@neurodevs/node-tdd'
13
+
14
+ import GitAutocommit from '../../impl/GitAutocommit.js'
15
+ import NpmReleasePropagator, {
16
+ ReleasePropagator,
17
+ ReleasePropagatorOptions,
18
+ } from '../../impl/NpmReleasePropagator.js'
19
+ import { FakeAutocommit } from '../../index.js'
20
+ import AbstractPackageTest from '../AbstractPackageTest.js'
21
+
22
+ const exec = promisify(execSync)
23
+
24
+ export default class NpmReleasePropagatorTest extends AbstractPackageTest {
25
+ private static instance: ReleasePropagator
26
+
27
+ private static readonly packageName = this.generateId()
28
+ private static readonly packageVersion = this.generateId()
29
+ private static readonly repoPaths = [this.generateId(), this.generateId()]
30
+
31
+ protected static async beforeEach() {
32
+ await super.beforeEach()
33
+
34
+ this.setFakeExec()
35
+ this.setFakeReadFile()
36
+ this.setFakeAutocommit()
37
+
38
+ this.instance = this.NpmReleasePropagator()
39
+ }
40
+
41
+ @test()
42
+ protected static async createsInstance() {
43
+ assert.isTruthy(this.instance, 'Failed to create instance!')
44
+ }
45
+
46
+ @test()
47
+ protected static async runInstallsReleaseForEachRepoPath() {
48
+ await this.run()
49
+
50
+ const expectedCalls = [
51
+ {
52
+ command: `yarn add ${this.packageName}@${this.packageVersion}`,
53
+ options: { cwd: this.repoPaths[0] },
54
+ },
55
+ {
56
+ command: `yarn add -D ${this.packageName}@${this.packageVersion}`,
57
+ options: { cwd: this.repoPaths[1] },
58
+ },
59
+ ]
60
+
61
+ assert.isEqualDeep(
62
+ [callsToExec[0], callsToExec[2]],
63
+ expectedCalls,
64
+ 'Did not install release in each repo path!'
65
+ )
66
+ }
67
+
68
+ @test()
69
+ protected static async runThrowsIfRepoDoesNotHavePreviousRelease() {
70
+ const missingPackageName = this.generateId()
71
+
72
+ this.instance = this.NpmReleasePropagator({
73
+ packageName: missingPackageName,
74
+ })
75
+
76
+ await assert.doesThrowAsync(async () => {
77
+ await this.run()
78
+ }, `Cannot propagate release for ${missingPackageName} because it is not listed in either dependencies or devDependencies! Please install it in the target repository before running propagation.`)
79
+ }
80
+
81
+ @test()
82
+ protected static async commitsChangesToGit() {
83
+ await this.run()
84
+
85
+ assert.isEqualDeep(
86
+ FakeAutocommit.callsToConstructor,
87
+ [
88
+ {
89
+ commitMessage: `patch: propagate ${this.packageName}@${this.packageVersion} (@neurodevs/meta-node: ${this.metaNodeVersion})`,
90
+ cwd: this.repoPaths[0],
91
+ },
92
+ {
93
+ commitMessage: `patch: propagate ${this.packageName}@${this.packageVersion} (@neurodevs/meta-node: ${this.metaNodeVersion})`,
94
+ cwd: this.repoPaths[1],
95
+ },
96
+ ],
97
+ 'Did not commit changes to git for each repo path!'
98
+ )
99
+ }
100
+
101
+ private static async run() {
102
+ await this.instance.run()
103
+ }
104
+
105
+ private static setFakeExec() {
106
+ NpmReleasePropagator.exec = fakeExec as unknown as typeof exec
107
+ resetCallsToExec()
108
+
109
+ this.setFakeMetaNodeVersion()
110
+ }
111
+
112
+ private static setFakeReadFile() {
113
+ NpmReleasePropagator.readFile =
114
+ fakeReadFile as unknown as typeof readFile
115
+ resetCallsToReadFile()
116
+
117
+ setFakeReadFileResult(
118
+ `${this.repoPaths[0]}/package.json`,
119
+ JSON.stringify({
120
+ dependencies: {
121
+ [this.packageName]: this.generateId(),
122
+ },
123
+ })
124
+ )
125
+
126
+ setFakeReadFileResult(
127
+ `${this.repoPaths[1]}/package.json`,
128
+ JSON.stringify({
129
+ devDependencies: {
130
+ [this.packageName]: this.generateId(),
131
+ },
132
+ })
133
+ )
134
+ }
135
+
136
+ private static setFakeAutocommit() {
137
+ GitAutocommit.Class = FakeAutocommit
138
+ FakeAutocommit.resetTestDouble()
139
+ }
140
+
141
+ private static NpmReleasePropagator(
142
+ options?: Partial<ReleasePropagatorOptions>
143
+ ) {
144
+ return NpmReleasePropagator.Create({
145
+ packageName: this.packageName,
146
+ packageVersion: this.packageVersion,
147
+ repoPaths: this.repoPaths,
148
+ ...options,
149
+ })
150
+ }
151
+ }
@@ -119,7 +119,7 @@ export default class UiAutomoduleTest extends AbstractAutomoduleTest {
119
119
  await this.run()
120
120
 
121
121
  assert.isEqualDeep(
122
- callsToExec[0],
122
+ callsToExec[0]?.command,
123
123
  'yarn version --minor --no-git-tag-version',
124
124
  'Did not bump minor version!'
125
125
  )