forked from yarnpkg/berry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.test.ts
956 lines (840 loc) Β· 29 KB
/
install.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
import {Filename, xfs, ppath, npath} from '@yarnpkg/fslib';
import {tests, misc} from 'pkg-tests-core';
describe(`Commands`, () => {
describe(`install`, () => {
test(
`it should print regular messages as JSON items when using --json`,
makeTemporaryEnv({}, async ({path, run, source}) => {
const {stdout} = await run(`install`, `--json`);
expect(misc.parseJsonStream(stdout)).toEqual([{
data: `Yarn 0.0.0`,
displayName: `YN0000`,
indent: `Β· `,
name: 0,
type: `info`,
}, {
data: `β Resolution step`,
displayName: `YN0000`,
indent: ``,
name: null,
type: `info`,
}, {
data: `β Completed`,
displayName: `YN0000`,
indent: ``,
name: null,
type: `info`,
}, {
data: `β Fetch step`,
displayName: `YN0000`,
indent: ``,
name: null,
type: `info`,
}, {
data: `β Completed`,
displayName: `YN0000`,
indent: ``,
name: null,
type: `info`,
}, {
data: `β Link step`,
displayName: `YN0000`,
indent: ``,
name: null,
type: `info`,
}, {
data: `β Completed`,
displayName: `YN0000`,
indent: ``,
name: null,
type: `info`,
}, {
data: `Done`,
displayName: `YN0000`,
indent: `Β· `,
name: 0,
type: `info`,
}]);
}),
);
test(
`it should print the logs to the standard output when using --inline-builds`,
makeTemporaryEnv({
dependencies: {
[`no-deps-scripted`]: `1.0.0`,
},
}, async ({path, run, source}) => {
const {stdout} = await run(`install`, `--inline-builds`);
expect(stdout).toContain(`no-deps-scripted@npm:1.0.0 must be built because it never has been before`);
expect(stdout).toContain(`STDOUT preinstall out`);
}),
);
test(
`it should skip build scripts when using --mode=skip-build`,
makeTemporaryEnv({
dependencies: {
[`no-deps-scripted`]: `1.0.0`,
},
}, async ({path, run, source}) => {
const {stdout} = await run(`install`, `--inline-builds`, `--mode=skip-build`);
expect(stdout).not.toContain(`no-deps-scripted@npm:1.0.0 must be built because it never has been before`);
expect(stdout).not.toContain(`STDOUT preinstall out`);
}),
);
test(
`it shouldn't impact how artifacts are generated when using --mode=skip-build`,
makeTemporaryEnv({
dependencies: {
[`no-deps-scripted`]: `1.0.0`,
},
}, async ({path, run, source}) => {
const pnpPath = ppath.join(path, Filename.pnpCjs);
await run(`install`);
const pnpFileWithBuilds = await xfs.readFilePromise(pnpPath);
await xfs.removePromise(pnpPath);
await run(`install`, `--mode=skip-build`);
const pnpFileWithoutBuilds = await xfs.readFilePromise(pnpPath);
expect(pnpFileWithBuilds).toEqual(pnpFileWithoutBuilds);
}),
);
tests.testIf(
() => process.platform !== `win32`,
`it should install from zips that are symlinks`,
makeTemporaryEnv({
dependencies: {
[`no-deps`]: `1.0.0`,
},
}, async ({path, run, source}) => {
await run(`install`);
const allFiles = await xfs.readdirPromise(ppath.join(path, `.yarn/cache`));
const zipFiles = allFiles.filter(file => file.endsWith(`.zip`));
await xfs.mkdirPromise(ppath.join(path, `store`));
for (const filename of zipFiles) {
const zipFile = ppath.join(path, `.yarn/cache`, filename);
const storePath = ppath.join(path, `store`, filename);
await xfs.movePromise(zipFile, storePath);
await xfs.symlinkPromise(storePath, zipFile);
}
await xfs.removePromise(ppath.join(path, Filename.pnpCjs));
await run(`install`, `--immutable`);
}),
);
test(
`it should refuse to create a lockfile when using --immutable`,
makeTemporaryEnv({
dependencies: {
[`no-deps`]: `1.0.0`,
},
}, async ({path, run, source}) => {
await expect(run(`install`, `--immutable`)).rejects.toThrow(/YN0028/);
}),
);
test(
`it should refuse to change the lockfile when using --immutable`,
makeTemporaryEnv({}, async ({path, run, source}) => {
await run(`install`);
await xfs.writeJsonPromise(ppath.join(path, `yarn.lock`), {
dependencies: {
[`no-deps`]: `1.0.0`,
},
});
await expect(run(`install`, `--immutable`)).rejects.toThrow(/YN0028/);
}),
);
test(
`it should update the lockfile when using --refresh-lockfile`,
makeTemporaryEnv({
dependencies: {
[`one-fixed-dep`]: `1.0.0`,
},
}, async ({path, run, source}) => {
await run(`install`);
// Sanity check
await expect(source(`require('one-fixed-dep')`)).resolves.toMatchObject({
name: `one-fixed-dep`,
version: `1.0.0`,
dependencies: {
[`no-deps`]: {
name: `no-deps`,
version: `1.0.0`,
},
},
});
const lockfilePath = ppath.join(path, Filename.lockfile);
const lockfileContent = await xfs.readFilePromise(lockfilePath, `utf8`);
const modifiedLockfile = lockfileContent.replace(/no-deps: "npm:1.0.0"/, `no-deps: "npm:2.0.0"`);
await xfs.writeFilePromise(lockfilePath, modifiedLockfile);
await run(`install`);
// Sanity check
await expect(source(`require('one-fixed-dep')`)).resolves.toMatchObject({
name: `one-fixed-dep`,
version: `1.0.0`,
dependencies: {
[`no-deps`]: {
name: `no-deps`,
version: `2.0.0`,
},
},
});
await run(`install`, `--refresh-lockfile`);
// Actual test
await expect(source(`require('one-fixed-dep')`)).resolves.toMatchObject({
name: `one-fixed-dep`,
version: `1.0.0`,
dependencies: {
[`no-deps`]: {
name: `no-deps`,
version: `1.0.0`,
},
},
});
}),
);
test(
`it should block invalid lockfiles when using --refresh-lockfile with --immutable`,
makeTemporaryEnv({
dependencies: {
[`one-fixed-dep`]: `1.0.0`,
},
}, async ({path, run, source}) => {
await run(`install`);
const lockfilePath = ppath.join(path, Filename.lockfile);
const lockfileContent = await xfs.readFilePromise(lockfilePath, `utf8`);
const modifiedLockfile = lockfileContent.replace(/no-deps: "npm:1.0.0"/, `no-deps: "npm:2.0.0"`);
await xfs.writeFilePromise(lockfilePath, modifiedLockfile);
await run(`install`);
await expect(run(`install`, `--immutable`, `--refresh-lockfile`)).rejects.toThrow(/YN0028/);
}),
);
test(
`it should enable --refresh-lockfile --immutable by default in public PR CIs`,
makeTemporaryEnv({
dependencies: {
[`one-fixed-dep`]: `1.0.0`,
},
}, async ({path, run, source}) => {
await run(`install`);
const lockfilePath = ppath.join(path, Filename.lockfile);
const lockfileContent = await xfs.readFilePromise(lockfilePath, `utf8`);
const modifiedLockfile = lockfileContent.replace(/no-deps: "npm:1.0.0"/, `no-deps: "npm:2.0.0"`);
await xfs.writeFilePromise(lockfilePath, modifiedLockfile);
const eventPath = ppath.join(path, `github-event-file.json`);
await xfs.writeJsonPromise(eventPath, {
repository: {
private: false,
},
});
await run(`install`);
await expect(run(`install`, {
env: {
GITHUB_ACTIONS: `true`,
GITHUB_EVENT_NAME: `pull_request`,
GITHUB_EVENT_PATH: npath.fromPortablePath(eventPath),
},
})).rejects.toThrow(/YN0028/);
}),
);
test(
`it should not enable --refresh-lockfile --immutable in private PR CIs`,
makeTemporaryEnv({
dependencies: {
[`one-fixed-dep`]: `1.0.0`,
},
}, async ({path, run, source}) => {
await run(`install`);
const lockfilePath = ppath.join(path, Filename.lockfile);
const lockfileContent = await xfs.readFilePromise(lockfilePath, `utf8`);
const modifiedLockfile = lockfileContent.replace(/no-deps: "npm:1.0.0"/, `no-deps: "npm:2.0.0"`);
await xfs.writeFilePromise(lockfilePath, modifiedLockfile);
const eventPath = ppath.join(path, `github-event-file.json`);
await xfs.writeJsonPromise(eventPath, {
repository: {
private: true,
},
});
await run(`install`);
await run(`install`, {
env: {
GITHUB_ACTIONS: `true`,
GITHUB_EVENT_NAME: `pull_request`,
GITHUB_EVENT_PATH: npath.fromPortablePath(eventPath),
},
});
}),
);
test(
`it should not enable --refresh-lockfile --immutable if the GH environment file is missing`,
makeTemporaryEnv({
dependencies: {
[`one-fixed-dep`]: `1.0.0`,
},
}, async ({path, run, source}) => {
await run(`install`);
const lockfilePath = ppath.join(path, Filename.lockfile);
const lockfileContent = await xfs.readFilePromise(lockfilePath, `utf8`);
const modifiedLockfile = lockfileContent.replace(/no-deps: "npm:1.0.0"/, `no-deps: "npm:2.0.0"`);
await xfs.writeFilePromise(lockfilePath, modifiedLockfile);
const eventPath = ppath.join(path, `github-event-file.json`);
await run(`install`);
await run(`install`, {
env: {
GITHUB_ACTIONS: `true`,
GITHUB_EVENT_NAME: `pull_request`,
GITHUB_EVENT_PATH: npath.fromPortablePath(eventPath),
},
});
}),
);
test(
`it should not enable --refresh-lockfile --immutable if the GH environment file is weird`,
makeTemporaryEnv({
dependencies: {
[`one-fixed-dep`]: `1.0.0`,
},
}, async ({path, run, source}) => {
await run(`install`);
const lockfilePath = ppath.join(path, Filename.lockfile);
const lockfileContent = await xfs.readFilePromise(lockfilePath, `utf8`);
const modifiedLockfile = lockfileContent.replace(/no-deps: "npm:1.0.0"/, `no-deps: "npm:2.0.0"`);
await xfs.writeFilePromise(lockfilePath, modifiedLockfile);
const eventPath = ppath.join(path, `github-event-file.json`);
await xfs.writeJsonPromise(eventPath, {
hello: `world`,
});
await run(`install`);
await run(`install`, {
env: {
GITHUB_ACTIONS: `true`,
GITHUB_EVENT_NAME: `pull_request`,
GITHUB_EVENT_PATH: npath.fromPortablePath(eventPath),
},
});
}),
);
test(
`it should accept to add files to the cache when using --immutable without --immutable-cache`,
makeTemporaryEnv({
dependencies: {
[`no-deps`]: `1.0.0`,
},
}, async ({path, run, source}) => {
await run(`install`);
await xfs.removePromise(ppath.join(path, `.yarn/cache`));
await run(`install`, `--immutable`);
}),
);
test(
`it should refuse to create a cache when using --immutable-cache`,
makeTemporaryEnv({
dependencies: {},
}, async ({path, run, source}) => {
await expect(run(`install`, `--immutable-cache`)).rejects.toThrowError(/Cache path does not exist/);
}),
);
test(
`it should refuse to add files to the cache when using --immutable-cache`,
makeTemporaryEnv({
dependencies: {
[`no-deps`]: `1.0.0`,
},
}, async ({path, run, source}) => {
// Ensure the cache directory exists
await xfs.mkdirPromise(ppath.join(path, `.yarn/cache`), {recursive: true});
await expect(run(`install`, `--immutable-cache`)).rejects.toThrow(/YN0056/);
}),
);
test(
`it should refuse to add files to the cache when using --immutable-cache, even when the lockfile is good`,
makeTemporaryEnv({
dependencies: {
[`no-deps`]: `1.0.0`,
},
}, async ({path, run, source}) => {
await run(`install`);
// Empty, rather than remove the cache
await xfs.removePromise(ppath.join(path, `.yarn/cache`));
await xfs.mkdirPromise(ppath.join(path, `.yarn/cache`), {recursive: true});
await expect(run(`install`, `--immutable-cache`)).rejects.toThrow(/YN0056/);
}),
);
test(
`it should refuse to remove files from the cache when using --immutable-cache`,
makeTemporaryEnv({
dependencies: {
[`no-deps`]: `1.0.0`,
},
}, async ({path, run, source}) => {
await run(`install`);
await xfs.writeJsonPromise(ppath.join(path, Filename.manifest), {
dependencies: {},
});
await expect(run(`install`, `--immutable-cache`)).rejects.toThrow(/YN0056/);
}),
);
test(
`it should validate the cache files against the remote source when using --check-cache`,
makeTemporaryEnv({
dependencies: {
[`no-deps`]: `1.0.0`,
},
}, async ({path, run, source}) => {
let archiveName1: Filename;
let archiveName2: Filename;
// First we need to detect the name that the true cache archive would have
{
await run(`install`);
const allFiles1 = await xfs.readdirPromise(ppath.join(path, `.yarn/cache`));
const zipFiles1 = allFiles1.filter(file => file.endsWith(`.zip`));
// Just a sanity check, since this test is quite complex
expect(zipFiles1).toHaveLength(1);
archiveName1 = zipFiles1[0];
}
await xfs.writeJsonPromise(ppath.join(path, Filename.manifest), {
dependencies: {
[`no-deps`]: `2.0.0`,
},
});
// Then we install the project with 2.0.0
{
await run(`install`);
const allFiles2 = await xfs.readdirPromise(ppath.join(path, `.yarn/cache`));
const zipFiles2 = allFiles2.filter(file => file.endsWith(`.zip`));
// Just a sanity check, since this test is quite complex
expect(zipFiles2).toHaveLength(1);
archiveName2 = zipFiles2[0];
}
// We need to replace the hash in the cache filename, otherwise the cache just won't find the archive
archiveName1 = archiveName1.replace(/[^-]+$/, archiveName2.match(/[^-]+$/)![0]) as Filename;
await xfs.writeJsonPromise(ppath.join(path, Filename.manifest), {
dependencies: {
[`no-deps`]: `1.0.0`,
},
});
// Then we disguise 2.0.0 as 1.0.0. The stored checksum will stay the same.
{
const lockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
// Moves from "2.0.0" to "1.0.0"
await xfs.writeFilePromise(ppath.join(path, Filename.lockfile), lockfile.replace(/2\.0\.0/g, `1.0.0`));
// Don't forget to rename the archive to match the name the real 1.0.0 would have
await xfs.movePromise(ppath.join(path, `.yarn/cache`, archiveName2), ppath.join(path, `.yarn/cache`, archiveName1));
}
// Just checking that the test is properly written: it should pass, because the lockfile checksum will match the tarballs
await run(`install`, `--immutable`, `--immutable-cache`);
// But now, --check-cache should redownload the packages and see that the checksums don't match
await expect(run(`install`, `--check-cache`)).rejects.toThrow(/YN0018/);
}),
);
test(
`reports warning if published binary field is a path but no package name is set`,
makeTemporaryEnv(
{
bin: `./bin/cli.js`,
},
async ({path, run, source}) => {
const {stdout} = await run(`install`);
expect(stdout).toContain(`root-workspace-0b6124: String bin field, but no attached package name`);
},
),
);
test(
`displays validation issues of nested workspaces`,
makeTemporaryEnv(
{
workspaces: [`packages`],
},
async ({path, run, source}) => {
await xfs.mkdirPromise(ppath.join(path, `packages`), {recursive: true});
await xfs.mkdirPromise(ppath.join(path, `packages/package-a`), {recursive: true});
await xfs.writeJsonPromise(ppath.join(path, `packages`, Filename.manifest), {
workspaces: [`package-a`],
});
await xfs.writeJsonPromise(ppath.join(path, `packages/package-a`, Filename.manifest), {
bin: `./bin/cli.js`,
});
await expect(run(`install`)).resolves.toMatchObject({
stdout: expect.stringContaining(`package-a-ddd35d: String bin field, but no attached package name`),
});
},
),
);
test(
`should not build virtual workspaces`,
makeTemporaryEnv(
{
workspaces: [`workspace`],
dependencies: {
foo: `workspace:*`,
'no-deps': `*`,
},
},
async ({path, run, source}) => {
await xfs.mkdirPromise(ppath.join(path, `workspace`));
await xfs.writeJsonPromise(ppath.join(path, `workspace`, Filename.manifest), {
name: `foo`,
scripts: {
postinstall: `echo "foo"`,
},
peerDependencies: {
'no-deps': `*`,
},
});
const {stdout} = await run(`install`);
expect(stdout).toContain(`foo@workspace:workspace must be built`);
expect(stdout).not.toMatch(/foo@virtual:.* must be built/);
},
),
);
test(
`should only print one error message for failed builds`,
makeTemporaryEnv(
{
scripts: {
postinstall: `exit 1`,
},
},
async ({path, run, source}) => {
let code;
let stdout;
try {
({code, stdout} = await run(`install`));
} catch (error) {
({code, stdout} = error);
}
expect(code).toEqual(1);
expect(stdout.match(/YN0009/g).length).toEqual(1);
},
),
);
test(
`should not continue running build scripts if one of them fails`,
makeTemporaryEnv(
{
scripts: {
preinstall: `exit 1`,
postinstall: `echo 'foo'`,
},
},
async ({path, run, source}) => {
await expect(run(`install`, `--inline-builds`)).rejects.toMatchObject({
code: 1,
stdout: expect.not.stringContaining(`foo`),
});
},
),
);
test(
`should not mark package as built if any of its scripts fails`,
makeTemporaryEnv(
{
scripts: {
preinstall: `echo 'foo'`,
postinstall: `exit 1`,
},
},
async ({path, run, source}) => {
await expect(run(`install`, `--inline-builds`)).rejects.toMatchObject({
code: 1,
stdout: expect.stringContaining(`foo`),
});
await expect(run(`install`, `--inline-builds`)).rejects.toMatchObject({
code: 1,
stdout: expect.stringContaining(`foo`),
});
},
),
);
test(
`should wait for direct dependencies to finish building`,
makeTemporaryMonorepoEnv(
{
workspaces: [`packages/*`],
},
{
'packages/foo': {
name: `foo`,
dependencies: {
bar: `workspace:*`,
},
scripts: {
postinstall: `node -e "require('bar')"`,
},
},
'packages/bar': {
name: `bar`,
scripts: {
postinstall: `sleep 5 && node -e "fs.writeFileSync('index.js', '')"`,
},
},
},
async ({path, run, source}) => {
await expect(run(`install`, `--inline-builds`)).resolves.toMatchObject({
code: 0,
});
},
),
);
test(
`should wait for indirect dependencies to finish building`,
makeTemporaryMonorepoEnv(
{
workspaces: [`packages/*`],
},
{
'packages/foo': {
name: `foo`,
dependencies: {
bar: `workspace:*`,
},
scripts: {
postinstall: `node -e "require('bar')"`,
},
},
'packages/bar': {
name: `bar`,
dependencies: {
baz: `workspace:*`,
},
},
'packages/baz': {
name: `baz`,
scripts: {
postinstall: `sleep 5 && node -e "fs.writeFileSync('index.js', '')"`,
},
},
},
async ({path, run, source}) => {
await xfs.writeFilePromise(ppath.join(path, `packages/bar/index.js`), `require('baz')`);
await expect(run(`install`, `--inline-builds`)).resolves.toMatchObject({
code: 0,
});
},
),
);
test(
`should wait for virtual workspace dependencies to finish building`,
makeTemporaryMonorepoEnv(
{
workspaces: [`packages/*`],
},
{
'packages/foo': {
name: `foo`,
dependencies: {
bar: `workspace:*`,
},
scripts: {
postinstall: `node -e "require('bar')"`,
},
},
'packages/bar': {
name: `bar`,
peerDependencies: {
'no-deps': `*`,
},
scripts: {
postinstall: `sleep 5 && node -e "fs.writeFileSync('index.js', '')"`,
},
},
},
async ({path, run, source}) => {
await expect(run(`install`, `--inline-builds`)).resolves.toMatchObject({
code: 0,
});
},
),
);
test(
`should support a self-referencing build dependency`,
makeTemporaryEnv(
{
name: `foo`,
dependencies: {
'no-deps': `1.0.0`,
},
scripts: {
postinstall: `echo foo`,
},
},
async ({path, run, source}) => {
await xfs.writeJsonPromise(ppath.join(path, Filename.rc), {
packageExtensions: {
'no-deps@*': {
dependencies: {
foo: `workspace:*`,
},
},
},
});
await expect(run(`install`, `--inline-builds`)).resolves.toMatchObject({
code: 0,
});
},
),
);
test(
`should support a self-referencing virtual workspace build dependency`,
makeTemporaryMonorepoEnv(
{
workspaces: [`packages/*`],
},
{
'packages/foo': {
name: `foo`,
peerDependencies: {
'no-deps': `1.0.0`,
},
dependencies: {
bar: `workspace:*`,
},
scripts: {
postinstall: `echo foo`,
},
},
'packages/bar': {
name: `bar`,
dependencies: {
foo: `workspace:*`,
},
},
},
async ({path, run, source}) => {
await expect(run(`install`, `--inline-builds`)).resolves.toMatchObject({
code: 0,
});
},
),
);
test(
`it should print a warning when using \`enableScripts: false\``,
makeTemporaryEnv({
dependencies: {
[`no-deps-scripted`]: `1.0.0`,
},
}, async ({path, run, source}) => {
await xfs.writeJsonPromise(ppath.join(path, Filename.rc), {
enableScripts: false,
});
const {stdout} = await run(`install`, `--inline-builds`);
expect(stdout).toMatch(/YN0004/g);
}),
);
test(
`it should print an info when \`dependenciesMeta[].built: false\`, even when using using \`enableScripts: false\``,
makeTemporaryEnv({
dependencies: {
[`no-deps-scripted`]: `1.0.0`,
},
dependenciesMeta: {
'no-deps-scripted': {
built: false,
},
},
}, async ({path, run, source}) => {
await xfs.writeJsonPromise(ppath.join(path, Filename.rc), {
enableScripts: false,
});
const {stdout} = await run(`install`, `--inline-builds`);
expect(stdout).toMatch(/YN0005/g);
expect(stdout).not.toMatch(/YN0004/g);
}),
);
test(
`it should throw a proper error if not find any locator`,
makeTemporaryEnv({}, async ({path, run, source}) => {
await xfs.mkdirPromise(ppath.join(path, `non-workspace`));
await xfs.writeJsonPromise(ppath.join(path, `non-workspace`, Filename.manifest), {
name: `non-workspace`,
});
await expect(run(`install`, {cwd: ppath.join(path, `non-workspace`)})).rejects.toMatchObject({
code: 1,
stdout: expect.stringMatching(/The nearest package directory \(.+\) doesn't seem to be part of the project declared in .+\./g),
});
}),
);
test(
`it should fetch only required packages when using \`--mode=update-lockfile\``,
makeTemporaryEnv({
dependencies: {
[`one-fixed-dep`]: `1.0.0`,
[`no-deps`]: `1.0.0`,
},
}, async ({path, run, source}) => {
await run(`install`);
await xfs.writeJsonPromise(ppath.join(path, Filename.manifest), {
dependencies: {
[`one-fixed-dep`]: `1.0.0`,
[`no-deps`]: `2.0.0`,
},
});
await xfs.removePromise(ppath.join(path, `.yarn/cache`));
await xfs.mkdirPromise(ppath.join(path, `.yarn/cache`), {recursive: true});
await expect(tests.startRegistryRecording(async () => {
await run(`install`, `--mode=update-lockfile`);
})).resolves.toEqual([{
type: `packageTarball`,
scope: undefined,
localName: `no-deps`,
version: `2.0.0`,
}]);
const cacheAfter = await xfs.readdirPromise(ppath.join(path, `.yarn/cache`));
expect(cacheAfter.find(entry => entry.includes(`one-fixed-dep-npm-1.0.0`))).toBeUndefined();
expect(cacheAfter.find(entry => entry.includes(`no-deps-npm-1.0.0`))).toBeUndefined();
expect(cacheAfter.find(entry => entry.includes(`no-deps-npm-2.0.0`))).toBeDefined();
}),
);
test(
`it should disable immutable installs when using \`--mode=update-lockfile\``,
makeTemporaryEnv({
dependencies: {
[`no-deps`]: `1.0.0`,
},
}, async ({path, run}) => {
await xfs.writeJsonPromise(ppath.join(path, Filename.rc), {
enableImmutableInstalls: true,
});
const {stdout} = await run(`install`, `--mode=update-lockfile`);
expect(stdout).not.toMatch(/YN0028/g);
}),
);
test(
`it should throw when \`--immutable\` or \`--immutable-cache\` is specified with \`--mode=update-lockfile\``,
makeTemporaryEnv({}, async ({path, run}) => {
await expect(run(`install`, `--mode=update-lockfile`, `--immutable`)).rejects.toMatchObject({
code: 1,
stdout: expect.stringMatching(/--immutable and --immutable-cache cannot be used with --mode=update-lockfile/g),
});
await expect(run(`install`, `--mode=update-lockfile`, `--immutable-cache`)).rejects.toMatchObject({
code: 1,
stdout: expect.stringMatching(/--immutable and --immutable-cache cannot be used with --mode=update-lockfile/g),
});
await expect(run(`install`, `--mode=update-lockfile`, `--immutable`, `--immutable-cache`)).rejects.toMatchObject({
code: 1,
stdout: expect.stringMatching(/--immutable and --immutable-cache cannot be used with --mode=update-lockfile/g),
});
}),
);
test(`it should exit with an error code after an unexpected empty event loop`,
makeTemporaryEnv({}, async ({path, run}) => {
await xfs.writeFilePromise(ppath.join(path, `plugin.cjs`), `
module.exports = {
name: 'test',
factory() {
return {
hooks: {
afterAllInstalled: () => new Promise(() => {}),
},
};
},
};
`);
await xfs.writeJsonPromise(ppath.join(path, Filename.rc), {
plugins: [`./plugin.cjs`],
});
await expect(run(`install`)).rejects.toMatchObject({
code: 42,
stdout: expect.stringContaining(`Yarn is terminating due to an unexpected empty event loop`),
});
}),
);
});
});