-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathexec.test.js
More file actions
123 lines (108 loc) · 3.24 KB
/
exec.test.js
File metadata and controls
123 lines (108 loc) · 3.24 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
import { resolve } from "path";
import test from "ava";
import { stub } from "sinon";
import { WritableStreamBuffer } from "stream-buffers";
import exec from "../lib/exec.js";
test.beforeEach((t) => {
t.context.stdout = new WritableStreamBuffer();
t.context.stderr = new WritableStreamBuffer();
// Mock logger
t.context.log = stub();
t.context.error = stub();
t.context.logger = {
log: t.context.log,
error: t.context.error,
warn: t.context.warn,
};
});
test("Pipe script output to stdout and stderr", async (t) => {
const pluginConfig = {
publishCmd: '>&2 echo "write to stderr" && echo "write to stdout"',
};
const context = {
stdout: t.context.stdout,
stderr: t.context.stderr,
logger: t.context.logger,
options: {},
};
const result = await exec("publishCmd", pluginConfig, context);
t.is(result, "write to stdout");
t.is(t.context.stdout.getContentsAsString("utf8").trim(), "write to stdout");
t.is(t.context.stderr.getContentsAsString("utf8").trim(), "write to stderr");
});
test("Generate command with template", async (t) => {
const pluginConfig = {
publishCmd: `./test/fixtures/echo-args.sh \${config.conf} \${lastRelease.version}`,
conf: "confValue",
};
const context = {
stdout: t.context.stdout,
stderr: t.context.stderr,
lastRelease: { version: "1.0.0" },
logger: t.context.logger,
};
const result = await exec("publishCmd", pluginConfig, context);
t.is(result, "confValue 1.0.0");
});
test("Generate command with env variables", async (t) => {
const pluginConfig = {
publishCmd: {
cmd: `./test/fixtures/echo-args.sh \${config.conf} \${lastRelease.version}`,
env: {
NEXT_RELEASE_NOTES: "${nextRelease.notes}",
},
},
conf: "confValue",
};
const context = {
stdout: t.context.stdout,
stderr: t.context.stderr,
lastRelease: { version: "1.0.0" },
nextRelease: { notes: "notes &\"'" },
logger: t.context.logger,
};
const result = await exec("publishCmd", pluginConfig, context);
t.is(result, "confValue 1.0.0 notes &\"'");
});
test('Execute the script with the specified "shell"', async (t) => {
const context = {
stdout: t.context.stdout,
stderr: t.context.stderr,
logger: t.context.logger,
};
let result = await exec(
"publishCmd",
{ publishCmd: "echo $0", shell: "bash" },
context,
);
t.is(result, "bash");
result = await exec(
"publishCmd",
{ publishCmd: "echo $0", shell: "sh" },
context,
);
t.is(result, "sh");
});
test('Execute the script in "cmd" if no step specific command is passed', async (t) => {
const context = {
stdout: t.context.stdout,
stderr: t.context.stderr,
logger: t.context.logger,
};
const result = await exec("publishCmd", { cmd: "echo run cmd" }, context);
t.is(result, "run cmd");
});
test('Exececute the script in cmd from the relative in "execCwd"', async (t) => {
const pluginConfig = {
publishCmd: `./fixtures/echo-args.sh $PWD`,
execCwd: "test",
};
const context = {
stdout: t.context.stdout,
stderr: t.context.stderr,
logger: t.context.logger,
cwd: process.cwd(),
};
const result = await exec("publishCmd", pluginConfig, context);
t.is(result, resolve(process.cwd(), "test"));
});