-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathintegration.js
More file actions
728 lines (601 loc) · 25.5 KB
/
integration.js
File metadata and controls
728 lines (601 loc) · 25.5 KB
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
import fs from "fs-promise";
import co from "co";
import path from "path";
import run from "./sh";
import semver from "semver";
import touch from "touch";
import which from "which";
import CP from "child_process";
const hello = "Hello sailor!";
const test = "You should add some tests.";
const bowerMissing = "* ERROR: No bower.json or psc-package.json found in current or parent directories. Are you in a PureScript project?";
const initWithoutForce = f => new RegExp('\\* ERROR: Found .*'+f+': There\'s already a project here. Run `pulp init --force` if you\'re sure you want to overwrite it.');
const filesToOverwrite = ['./bower.json', './.gitignore', 'src/Main.purs', 'test/Main.purs'];
const buildHelp = ["Command: build", "Build the project."];
const docsHelp = ["Command: docs", "Generate project documentation."];
const skipped = "* Project unchanged; skipping build step.";
const newlines = /\r?\n/g;
const testBowerJson = {
"name": "test-package-for-pulp-tests",
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"output"
],
"repository": {
"type": "git",
"url": "git://github.com/not-real/not-real.git"
},
"dependencies": {
"purescript-console": "^0.1.0"
}
};
const testBowerJsonV0_15_0 = Object.assign({}, testBowerJson, {
"dependencies": {
"purescript-prelude": "^5.0.1",
"purescript-console": "^5.0.0",
"purescript-effect": "^3.0.0"
}
});
function resolvePath(cmd) {
return new Promise((resolve, reject) => {
which(cmd, (err, res) => err ? reject(err) : resolve(res));
});
}
function sleep(ms) {
return new Promise((resolve, reject) => {
setTimeout(resolve, ms);
});
}
function windowsify(script) {
return process.platform === "win32" ? `${script}.cmd` : script;
}
function assertThrows(promise) {
return promise.then(
() => { throw new Error("Expected the promise to throw") },
() => {}
);
}
function notWindowsIt(name, fn) {
if (process.platform === "win32") {
it("Skipping: " + name + " (since we are on windows)",
function() { return true; });
} else {
it(name, fn);
}
}
const psaHelper = co.wrap(function*(temp) {
const node = yield resolvePath("node");
const prog = (name, version) => `
if (process.argv[2] === "--version") {
process.stdout.write("${version}\\n");
} else {
process.stderr.write("assert ${name}\\n");
process.stderr.write(process.argv.join(" ") + "\\n");
}
`;
const p = path.resolve(temp, "bin");
yield fs.mkdir(p);
const writeProg = co.wrap(function* (name, version) {
const fullProgPath = path.resolve(p, windowsify(name));
const progJs = path.resolve(p, name + ".js");
const echoOff = process.platform === "win32" ? "@echo off\r\n" : "";
const args = process.platform === "win32" ? "%*" : "$@";
yield fs.writeFile(fullProgPath,
`${echoOff}"${node}" "${progJs}" ${args}`, "utf-8");
yield fs.chmod(fullProgPath, 0o755);
yield fs.writeFile(progJs, prog(name, version), "utf-8");
});
return {
binPath: p,
writeProg
};
});
function setupPackage(cwd, sh) {
return sh("git init")
.then(() => fs.writeFile(path.join(cwd, "LICENSE"),
"do whatever u want lol",
{encoding: 'utf8'}))
.then(() => sh("git add ."))
.then(() => sh("git config user.name \"Test User\""))
.then(() => sh("git config user.email test@test.com"))
.then(() => sh("git commit -m \"initial commit\""))
.then(() => sh("git tag v1.0.0"));
}
function* createModule(sh, temp, name) {
yield sh("mkdir " + name);
yield fs.writeFile(path.join(temp, name, name + ".purs"),
"module " + name + " where\n\nfoo = 1");
return path.join("output", name, "index.js");
}
const getPursVersion = co.wrap(function*(sh, assert) {
const [out] = yield sh("purs --version");
// Drops pre-release identifiers
// 0.15.0-alpha-01 --> 0.15.0
const pursVerWithExtras = semver.coerce(out.split(/\s/)[0]);
const pursVer = pursVerWithExtras === null ? pursVerWithExtras : semver.parse(pursVerWithExtras);
if (pursVer == null) {
assert.fail("Unable to parse output of purs --version");
}
return pursVer;
});
const psVersionUsed = CP.execSync("purs --version").toString("utf-8");
const notEsModulesPsVersionIt = function(testName, cb) {
const pursVerWithExtras = semver.coerce(psVersionUsed.split(/\s/)[0]);
const pursVer = semver.parse(pursVerWithExtras);
if (semver.lt(pursVer, semver.parse('0.15.0'))) {
it(testName, cb);
} else {
it.skip(testName, cb);
}
}
describe("integration tests", function() {
// This is, unfortunately, required, as CI is horrendously slow.
this.timeout(90000);
it("pulp --version", run(function*(sh, pulp, assert) {
const [out] = yield pulp("--version");
assert.ok(semver.valid(out.split(/\s/)[2]), out + " is not a valid version.");
}));
it("pulp -v", run(function*(sh, pulp, assert) {
const [out] = yield pulp("-v");
assert.ok(semver.valid(out.split(/\s/)[2]), out + " is not a valid version.");
}));
it("errors when bower.json is missing", run(function*(sh, pulp, assert) {
const [_, err] = yield pulp("build", null, { expectedExitCode: 1 });
assert.equal(err.trim(), bowerMissing);
}));
notEsModulesPsVersionIt("Bower has precedence over psc-package", run(function*(sh, pulp, assert) {
yield pulp("init");
// Create psc-package.json without installing any dependencies
yield sh("psc-package init");
// In the presence of both bower.json and psc-package.json, pulp should default to Bower
yield pulp("build");
assert.exists(path.join("output", "Main", "index.js"));
// The --psc-package flag can override that, in this case the build should fail because
// we haven't installed any dependencies with psc-package
assertThrows(pulp("--psc-package build"));
}));
["build --help", "build -h"].forEach((cmdline) => {
it("pulp " + cmdline, run(function*(sh, pulp, assert) {
const [_, err] = yield pulp(cmdline);
buildHelp.forEach(function(h) {
assert.ok(err.indexOf(h) > -1,
"output did not contain '" + h + "'\noutput was:\n" + err)
});
}));
});
it("pulp docs --help", run(function*(sh, pulp, assert) {
const [_, err] = yield pulp("docs --help");
docsHelp.forEach(function(h) {
assert.ok(err.indexOf(h) > -1,
"output did not contain '" + h + "'\noutput was:\n" + err)
});
}));
it("refuses to init without --force", run(function*(sh, pulp, assert, temp) {
for (var idx in filesToOverwrite) {
let file = path.join(temp, filesToOverwrite[idx])
, dir = path.dirname(file);
if (!(yield fs.exists(dir))) {
yield fs.mkdir(dir);
}
touch.sync(file);
const [_, err] = yield pulp("init", null, { expectedExitCode: 1 });
assert.match(err.trim(), initWithoutForce(path.basename(file)));
const rm = process.platform === "win32" ? "del" : "rm"
yield fs.unlink(file);
}
}));
it("init overwrites existing files with --force", run(function*(sh, pulp, assert, temp) {
for (var idx in filesToOverwrite) {
let file = path.join(temp, filesToOverwrite[idx]);
yield fs.writeFile(file, "hello");
yield pulp("init --force");
const out = yield fs.readFile(file);
assert.notEqual(out, "hello");
}
}));
it("pulp build", run(function*(sh, pulp, assert, temp) {
yield pulp("init");
yield pulp("build");
assert.exists(path.join("output", "Main", "index.js"));
}));
notEsModulesPsVersionIt("pulp build with psc-package", run(function*(sh, pulp, assert, temp) {
yield pulp("--psc-package init");
yield pulp("build");
assert.exists(path.join("output", "Main", "index.js"));
}));
it("finds bower.json in parent directories", run(function*(sh, pulp, assert, temp) {
yield pulp("init");
yield pulp("build", null, { cwd: path.join(temp, "src") });
assert.exists(path.join("output", "Main", "index.js"));
}));
it("handles .pulp-cache already existing", run(function*(sh, pulp, assert) {
yield pulp("init");
yield sh("mkdir .pulp-cache");
yield pulp("build");
}));
it("pulp build --include", run(function*(sh, pulp, assert, temp) {
yield pulp("init");
var extras = yield createModule(sh, temp, "Extras");
yield pulp("build --include Extras");
assert.exists(extras);
}));
notWindowsIt("handles empty string after --include", run(function*(sh, pulp, assert, temp) {
yield pulp("init");
yield pulp("build --include ''");
}));
it("handles consecutive delimiters for --include", run(function*(sh, pulp, assert, temp) {
yield pulp("init");
var extras = yield createModule(sh, temp, "Extras");
var extras2 = yield createModule(sh, temp, "Extras2");
var includeArg = ["Extras", "", "Extras2"].join(path.delimiter);
yield pulp("build --include " + includeArg);
assert.exists(extras);
assert.exists(extras2);
}));
it("handles delimiter as last character for --include", run(function*(sh, pulp, assert, temp) {
yield pulp("init");
var extras = yield createModule(sh, temp, "Extras");
yield pulp("build --include Extras" + path.delimiter);
assert.exists(extras);
}));
it("pulp run", run(function*(sh, pulp, assert) {
yield pulp("init");
const [out] = yield pulp("run");
assert.equal(out.trim(), hello);
}));
it("pulp --bower-file FILE run", run(function*(sh, pulp, assert, temp) {
yield pulp("init");
yield fs.rename(path.join(temp, "bower.json"), path.join(temp, "lol.json"));
const [out] = yield pulp("--bower-file lol.json run");
assert.equal(out.trim(), hello);
}));
it("pulp run -- program args", run(function*(sh, pulp, assert, temp) {
yield pulp("init");
const srcDir = path.join(temp, "run_with_args");
yield fs.mkdir(srcDir);
const pursVer = yield getPursVersion(sh, assert);
const resourceDir = semver.gte(pursVer, semver.parse('0.15.0')) ? "es": "cjs";
yield fs.copy(path.resolve(__dirname, `${resourceDir}/Main.purs`), path.join(srcDir, "Main.purs"));
yield fs.copy(path.resolve(__dirname, `${resourceDir}/Main.js`), path.join(srcDir, "Main.js"));
const [out] = yield pulp("run --src-path run_with_args -m Test.Main -- program args");
assert.equal(out.trim(), "program\nargs");
}));
notEsModulesPsVersionIt("pulp build --to", run(function*(sh, pulp, assert) {
yield pulp("init");
yield pulp("build --to out.js");
const [out] = yield sh("node out.js");
assert.equal(out.trim(), hello);
}));
notEsModulesPsVersionIt("pulp build --to creates parent directories", run(function*(sh, pulp, assert) {
yield pulp("init");
yield pulp("build --to nonexistent/out.js");
const [out] = yield sh("node nonexistent/out.js");
assert.equal(out.trim(), hello);
}));
notEsModulesPsVersionIt("pulp build --skip-entry-point --to", run(function*(sh, pulp, assert, temp) {
yield pulp("init");
yield pulp(`--then "echo module.exports = PS >> out.js" build --skip-entry-point --to out.js`);
const [out] = yield sh(`node -e "var o = require('./out'); o.Main.main();"`);
assert.equal(out.trim(), hello);
}));
notEsModulesPsVersionIt("pulp build -O", run(function*(sh, pulp, assert) {
yield pulp("init");
const [src] = yield pulp("build -O");
const [out] = yield sh("node", src);
assert.equal(out.trim(), hello);
}));
notEsModulesPsVersionIt("pulp build -O --to", run(function*(sh, pulp, assert) {
// Should be identical to `pulp build --to`.
yield pulp("init");
yield pulp("build -O --to out.js");
const [out] = yield sh("node out.js");
assert.equal(out.trim(), hello);
}));
notEsModulesPsVersionIt("pulp build --source-maps -O --to", run(function*(sh, pulp, assert) {
yield pulp("init");
yield pulp("build --source-maps -O --to out.js");
const [out] = yield sh("node out.js");
assert.equal(out.trim(), hello);
assert.exists("out.js.map");
}));
notEsModulesPsVersionIt("pulp build -O --src-path alt", run(function*(sh, pulp, assert, temp) {
yield pulp("init");
yield fs.rename(path.join(temp, "src"), path.join(temp, "alt"));
const [src] = yield pulp("build -O --src-path alt");
const [out] = yield sh("node", src);
assert.equal(out.trim(), hello);
}));
it("pulp test", run(function*(sh, pulp, assert) {
yield pulp("init");
const [out] = yield pulp("test");
assert.equal(out.trim(), test);
}));
it("pulp test --test-path alt", run(function*(sh, pulp, assert, temp) {
yield pulp("init");
yield fs.rename(path.join(temp, "test"), path.join(temp, "alt"));
const [out] = yield pulp("test --src-path alt");
assert.equal(out.trim(), test);
}));
it("pulp test --test-path test2 -- --something-node-wouldnt-like", run(function*(sh, pulp, assert, temp) {
yield pulp("init");
const newTest = path.join(temp, "test2");
yield fs.mkdir(newTest);
const pursVer = yield getPursVersion(sh, assert);
const resourceDir = semver.gte(pursVer, semver.parse('0.15.0')) ? "es": "cjs";
yield fs.copy(path.resolve(__dirname, `${resourceDir}/Main.purs`), path.join(newTest, "Main.purs"));
yield fs.copy(path.resolve(__dirname, `${resourceDir}/Main.js`), path.join(newTest, "Main.js"));
const [out] = yield pulp("test --test-path test2 -- --something-node-wouldnt-like");
assert.equal(out.trim(), "--something-node-wouldnt-like");
}));
notEsModulesPsVersionIt("pulp browserify", run(function*(sh, pulp, assert) {
yield pulp("init");
const [src] = yield pulp("browserify");
const [out] = yield sh("node", src);
assert.equal(out.trim(), hello);
}));
notEsModulesPsVersionIt("pulp browserify --to", run(function*(sh, pulp, assert) {
yield pulp("init");
yield pulp("browserify --to out.js");
const [out] = yield sh("node out.js");
assert.equal(out.trim(), hello);
}));
notEsModulesPsVersionIt("pulp browserify --source-maps --to", run(function*(sh, pulp, assert) {
yield pulp("init");
yield pulp("browserify --source-maps --to out.js");
const [out] = yield sh("node out.js");
assert.equal(out.trim(), hello);
assert.exists("out.js.map");
}));
notEsModulesPsVersionIt("pulp browserify --source-maps --to subdir", run(function*(sh, pulp, assert, temp) {
yield pulp("init");
yield fs.mkdir(path.join(temp, "subdir"));
yield pulp("browserify --source-maps --to subdir/out.js");
assert.exists("subdir/out.js.map");
}));
notEsModulesPsVersionIt("pulp browserify -O", run(function*(sh, pulp, assert) {
yield pulp("init");
const [src] = yield pulp("browserify -O");
const [out] = yield sh("node", src);
assert.equal(out.trim(), hello);
}));
notEsModulesPsVersionIt("pulp browserify -O --to", run(function*(sh, pulp, assert) {
yield pulp("init");
yield pulp("browserify -O --to out.js");
const [out] = yield sh("node out.js");
assert.equal(out.trim(), hello);
}));
notEsModulesPsVersionIt("output of pulp browserify --standalone may be `require()`d", run(function*(sh, pulp, assert, temp) {
yield pulp("init");
yield pulp("browserify --main Data.Function --standalone data-function --to data-function.js");
const dataFunction = require(path.join(temp, "data-function.js"));
const sub = (x) => (y) => x - y;
assert.equal(dataFunction.flip(sub)(1)(5), 4);
}));
// See https://github.com/purescript-contrib/pulp/pull/362
it.skip("pulp browserify --source-maps -O --to", run(function*(sh, pulp, assert) {
yield pulp("init");
yield pulp("browserify --source-maps -O --to out.js");
const [out] = yield sh("node out.js");
assert.equal(out.trim(), hello);
assert.exists("out.js.map");
}));
// See https://github.com/purescript-contrib/pulp/pull/362
it.skip("pulp browserify --source-maps -O --to subdir", run(function*(sh, pulp, assert, temp) {
yield pulp("init");
yield fs.mkdir(path.join(temp, "subdir"));
yield pulp("browserify --source-maps -O --to subdir/out.js");
assert.exists("subdir/out.js.map");
}));
notEsModulesPsVersionIt("pulp browserify --skip-compile", run(function*(sh, pulp, assert, temp) {
yield pulp("init");
yield fs.rename(path.join(temp, "src"), path.join(temp, "alt"));
yield pulp("build --src-path alt");
yield pulp("browserify --to out.js --skip-compile");
const [out] = yield sh("node out.js");
assert.equal(out.trim(), hello);
}));
it("pulp docs", run(function*(sh, pulp, assert) {
const pursVer = yield getPursVersion(sh, assert);
if (semver.gte(pursVer, semver.parse('0.13.0'))) {
yield pulp("init");
yield pulp("docs");
assert.file("generated-docs/html/Main.html");
}
}));
it("pulp docs --with-tests", run(function*(sh, pulp, assert) {
const pursVer = yield getPursVersion(sh, assert);
if (semver.gte(pursVer, semver.parse('0.13.0'))) {
yield pulp("init");
yield pulp("docs --with-tests");
assert.file("generated-docs/html/Test.Main.html");
}
}));
it("pulp psci includes dependencies", run(function*(sh, pulp, assert) {
yield pulp("init");
yield pulp("psci");
const [out] = yield pulp("psci", "import Prelude\n\"hello, \" <> \"world\"");
assert.match(out, /hello, world/);
}));
notEsModulesPsVersionIt("pulp psci includes dependencies with psc-package", run(function*(sh, pulp, assert) {
yield pulp("--psc-package init");
yield pulp("psci");
const [out] = yield pulp("psci", "import Prelude\n\"hello, \" <> \"world\"");
assert.match(out, /hello, world/);
}));
it("pulp psci includes local files", run(function*(sh, pulp, assert) {
yield pulp("init");
yield pulp("psci");
const [out] = yield pulp("psci", "import Main as Main\nMain.main");
assert.match(out, new RegExp(hello));
}));
notEsModulesPsVersionIt("pulp --before something build", run(function*(sh, pulp, assert, temp) {
yield pulp("init");
// In reality, this is likely to be a "--before clear" or something, but
// that's nightmarish to actually test.
touch.sync(path.join(temp, "before.txt"));
const mv = process.platform === "win32" ? "rename" : "mv";
yield pulp(`--before "${mv} before.txt after.txt" build --to out.js`);
const [out] = yield sh("node out.js");
assert.equal(out.trim(), hello);
assert.ok(yield fs.exists(path.join(temp, "after.txt")),
"test file before.txt was not found as after.txt");
}));
notEsModulesPsVersionIt("pulp --then something build", run(function*(sh, pulp, assert) {
yield pulp("init");
const mv = process.platform === "win32" ? "rename" : "mv";
yield pulp(`--then "${mv} out.js out2.js" build --to out.js`);
const [out] = yield sh("node out2.js");
assert.equal(out.trim(), hello);
}));
it("pulp --else something build", run(function*(sh, pulp, assert, temp) {
yield pulp("init");
// Deliberately cause a build failure.
const mainPath = path.join(temp, 'src', 'Main.purs');
yield fs.writeFile(
mainPath,
(yield fs.readFile(mainPath)).toString().concat("\ninvalidThing")
);
touch.sync(path.join(temp, "before.txt"));
const mv = process.platform === "win32" ? "rename" : "mv";
const [_, err] = yield pulp(
`--else "${mv} before.txt afterFailed.txt" build --to out.js`,
null, { expectedExitCode: 1 }
);
assert.match(err.trim(), /Unable to parse/); // Expected error
assert.exists(path.join(temp, "afterFailed.txt")); // --else has run
}));
notEsModulesPsVersionIt("pulp --then something browserify", run(function*(sh, pulp, assert, temp) {
yield pulp("init");
const mv = process.platform === "win32" ? "rename" : "mv";
yield pulp(`--then "echo lol > out.txt" browserify`);
assert.equal((yield fs.readFile(path.join(temp, "out.txt"), "utf-8")).trim(), "lol");
}));
notEsModulesPsVersionIt("pulp --then something browserify --to", run(function*(sh, pulp, assert) {
yield pulp("init");
const mv = process.platform === "win32" ? "rename" : "mv";
yield pulp(`--then "${mv} out.js out2.js" browserify --to out.js`);
const [out] = yield sh("node out2.js");
assert.equal(out.trim(), hello);
}));
notEsModulesPsVersionIt("pulp test --runtime", run(function*(sh, pulp, assert) {
yield pulp("init");
const [out] = yield pulp("test --runtime cat");
const [out2] = yield sh("node", out);
assert.equal(out2.trim(), test);
}));
it("pulp uses purs when psa is not available", run(function*(sh, pulp, assert, temp) {
const h = yield psaHelper(temp);
yield h.writeProg("purs", "0.12.0");
yield pulp("init");
const [out, err] = yield pulp("build", undefined, {path: h.binPath});
assert.match(err, /assert purs/);
}));
it("pulp ignores psa when it is too old", run(function*(sh, pulp, assert, temp) {
const h = yield psaHelper(temp);
yield h.writeProg("purs", "0.12.0");
yield h.writeProg("psa", "0.4.0");
yield pulp("init");
const [out, err] = yield pulp("build", undefined, {path: h.binPath});
assert.match(err, /assert purs/);
}));
it("pulp uses psa when it is available", run(function*(sh, pulp, assert, temp) {
const h = yield psaHelper(temp);
yield h.writeProg("purs", "0.12.0");
yield h.writeProg("psa", "0.7.0");
yield pulp("init");
const [out, err] = yield pulp("build", undefined, {path: h.binPath});
assert.match(err, /assert psa/);
}));
it("pulp ignores psa when --no-psa is passed", run(function*(sh, pulp, assert, temp) {
const h = yield psaHelper(temp);
yield h.writeProg("purs", "0.12.0");
yield h.writeProg("psa", "0.7.0");
yield pulp("init");
const [out, err] = yield pulp("build --no-psa", undefined, {path: h.binPath});
assert.match(err, /assert purs/);
}));
it("pulp passes arguments through to psa", run(function*(sh, pulp, assert, temp) {
const h = yield psaHelper(temp);
yield h.writeProg("purs", "0.12.0");
yield h.writeProg("psa", "0.7.0");
yield pulp("init");
const [out, err] = yield pulp("build -- --monochrome", undefined, {path: h.binPath});
assert.match(err, /--monochrome/);
assert.match(err, /--is-lib=bower_components/);
}));
it("pulp version requires a clean working tree", run(function*(sh, pulp, assert, temp) {
yield pulp("init");
yield setupPackage(temp, sh);
yield fs.writeFile(path.join(temp, "hello.txt"), "hello");
// TODO: check the output.
yield assertThrows(pulp("version"));
}));
it("pulp version checks using purs publish", run(function*(sh, pulp, assert, temp) {
yield pulp("init");
yield setupPackage(temp, sh);
// The bower.json file should be invalid because the repository key is
// missing. TODO: Check that we actually get this error.
yield assertThrows(pulp("version minor"));
}));
[["major", /v3.0.0/], ["minor", /v2.1.0/], ["patch", /v2.0.1/]].forEach((params) => {
const [ bumpType, pattern ] = params;
it("pulp version applies the specified bump: " + bumpType,
run(function*(sh, pulp, assert, temp) {
yield pulp("init");
yield setupPackage(temp, sh);
yield fs.writeFile(path.join(temp, "bower.json"), JSON.stringify(testBowerJson));
const psVer = yield getPursVersion(sh, assert);
if (semver.gte(psVer, semver.parse('0.15.0'))) {
// For tests to pass on the `v0.15.0-alpha-01` purs version,
// we need to use a custom fork of a non-core repo
// (i.e. working-group-purescript-es/purescript-prelude#es-modules-libraries).
// Since those repos' `bower.json` files point to dependencies
// whose "versions" are branch names as well, the `bower.json` JSON parsing fails.
// So, we need to remove the `bower_components` folder that gets set up
// when `pulp init` is called, and re-install the bower deps
// using the `bower.json` file.
//
// Furthermore, we have to install all 3 deps used in a typical `pulp init`
// setup. Otherwise, `pulp version` fails due to other dependency-related reasons.
yield fs.writeFile(path.join(temp, "bower.json"), JSON.stringify(testBowerJsonV0_15_0));
yield sh("rm -rf bower_components");
yield sh("bower install");
}
yield sh("git commit -am \"updating bower.json\"");
yield sh("git tag v2.0.0");
yield sh("git commit --allow-empty -m \"an empty commit for the new tag\"");
const [out, err] = yield pulp("version " + bumpType);
assert.match(err, pattern);
}));
});
it("pulp version for packages with no dependencies", run(function*(sh, pulp, assert, temp) {
yield setupPackage(temp, sh);
var bowerJson = Object.assign({}, testBowerJson, {"dependencies":{}});
yield fs.writeFile(path.join(temp, "bower.json"), JSON.stringify(bowerJson));
yield fs.mkdir(path.join(temp, "src"));
yield fs.writeFile(path.join(temp, "src", "Example.purs"), "module Example where\nexample = 1");
yield sh("git add .");
yield sh("git commit -m \"update bower.json and src/Example.purs\"");
yield sh("git tag v2.0.0");
yield sh("git commit --allow-empty -m \"an empty commit for the new tag\"");
const [out, err] = yield pulp("version minor");
assert.match(err, /v2.1.0/);
}));
it("pulp build -j 4", run(function*(sh, pulp, assert, temp) {
yield pulp("init");
yield pulp("build -j 4");
assert.exists(path.join("output", "Main", "index.js"));
}));
it("exits 1 on invalid commands", run(function*(sh, pulp) {
yield pulp("blah", null, { expectedExitCode: 1 });
}));
it("exits 1 on invalid options", run(function*(sh, pulp) {
yield pulp("build --blah", null, { expectedExitCode: 1 });
}));
it("exits 1 on --with-eff and --with-effect", run(function*(sh, pulp, assert) {
yield pulp("init --with-eff --with-effect", null, { expectedExitCode: 1 });
}));
});