Skip to content

Commit 5fa61d8

Browse files
authored
Simplify tests (#552)
1 parent 950d1e6 commit 5fa61d8

File tree

6 files changed

+48
-48
lines changed

6 files changed

+48
-48
lines changed

test/command.js

+38-38
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ test('allow commands with spaces and array arguments', async t => {
5353
});
5454

5555
test('execaCommand()', async t => {
56-
const {stdout} = await execaCommand('node test/fixtures/echo.js foo bar');
56+
const {stdout} = await execaCommand('echo.js foo bar');
5757
t.is(stdout, 'foo\nbar');
5858
});
5959

6060
test('execaCommand() ignores consecutive spaces', async t => {
61-
const {stdout} = await execaCommand('node test/fixtures/echo.js foo bar');
61+
const {stdout} = await execaCommand('echo.js foo bar');
6262
t.is(stdout, 'foo\nbar');
6363
});
6464

@@ -68,27 +68,27 @@ test('execaCommand() allows escaping spaces in commands', async t => {
6868
});
6969

7070
test('execaCommand() allows escaping spaces in arguments', async t => {
71-
const {stdout} = await execaCommand('node test/fixtures/echo.js foo\\ bar');
71+
const {stdout} = await execaCommand('echo.js foo\\ bar');
7272
t.is(stdout, 'foo bar');
7373
});
7474

7575
test('execaCommand() escapes other whitespaces', async t => {
76-
const {stdout} = await execaCommand('node test/fixtures/echo.js foo\tbar');
76+
const {stdout} = await execaCommand('echo.js foo\tbar');
7777
t.is(stdout, 'foo\tbar');
7878
});
7979

8080
test('execaCommand() trims', async t => {
81-
const {stdout} = await execaCommand(' node test/fixtures/echo.js foo bar ');
81+
const {stdout} = await execaCommand(' echo.js foo bar ');
8282
t.is(stdout, 'foo\nbar');
8383
});
8484

8585
test('execaCommandSync()', t => {
86-
const {stdout} = execaCommandSync('node test/fixtures/echo.js foo bar');
86+
const {stdout} = execaCommandSync('echo.js foo bar');
8787
t.is(stdout, 'foo\nbar');
8888
});
8989

9090
test('$', async t => {
91-
const {stdout} = await $`node test/fixtures/echo.js foo bar`;
91+
const {stdout} = await $`echo.js foo bar`;
9292
t.is(stdout, 'foo\nbar');
9393
});
9494

@@ -98,76 +98,76 @@ test('$ accepts options', async t => {
9898
});
9999

100100
test('$ allows string interpolation', async t => {
101-
const {stdout} = await $`node test/fixtures/echo.js foo ${'bar'}`;
101+
const {stdout} = await $`echo.js foo ${'bar'}`;
102102
t.is(stdout, 'foo\nbar');
103103
});
104104

105105
test('$ allows number interpolation', async t => {
106-
const {stdout} = await $`node test/fixtures/echo.js 1 ${2}`;
106+
const {stdout} = await $`echo.js 1 ${2}`;
107107
t.is(stdout, '1\n2');
108108
});
109109

110110
test('$ allows array interpolation', async t => {
111-
const {stdout} = await $`node test/fixtures/echo.js ${['foo', 'bar']}`;
111+
const {stdout} = await $`echo.js ${['foo', 'bar']}`;
112112
t.is(stdout, 'foo\nbar');
113113
});
114114

115115
test('$ allows execa return value interpolation', async t => {
116-
const foo = await $`node test/fixtures/echo.js foo`;
117-
const {stdout} = await $`node test/fixtures/echo.js ${foo} bar`;
116+
const foo = await $`echo.js foo`;
117+
const {stdout} = await $`echo.js ${foo} bar`;
118118
t.is(stdout, 'foo\nbar');
119119
});
120120

121121
test('$ allows execa return value array interpolation', async t => {
122-
const foo = await $`node test/fixtures/echo.js foo`;
123-
const {stdout} = await $`node test/fixtures/echo.js ${[foo, 'bar']}`;
122+
const foo = await $`echo.js foo`;
123+
const {stdout} = await $`echo.js ${[foo, 'bar']}`;
124124
t.is(stdout, 'foo\nbar');
125125
});
126126

127127
test('$ allows execa return value buffer interpolation', async t => {
128-
const foo = await $({encoding: null})`node test/fixtures/echo.js foo`;
129-
const {stdout} = await $`node test/fixtures/echo.js ${foo} bar`;
128+
const foo = await $({encoding: null})`echo.js foo`;
129+
const {stdout} = await $`echo.js ${foo} bar`;
130130
t.is(stdout, 'foo\nbar');
131131
});
132132

133133
test('$ allows execa return value buffer array interpolation', async t => {
134-
const foo = await $({encoding: null})`node test/fixtures/echo.js foo`;
135-
const {stdout} = await $`node test/fixtures/echo.js ${[foo, 'bar']}`;
134+
const foo = await $({encoding: null})`echo.js foo`;
135+
const {stdout} = await $`echo.js ${[foo, 'bar']}`;
136136
t.is(stdout, 'foo\nbar');
137137
});
138138

139139
test('$ ignores consecutive spaces', async t => {
140-
const {stdout} = await $`node test/fixtures/echo.js foo bar`;
140+
const {stdout} = await $`echo.js foo bar`;
141141
t.is(stdout, 'foo\nbar');
142142
});
143143

144144
test('$ allows escaping spaces with interpolation', async t => {
145-
const {stdout} = await $`node test/fixtures/echo.js ${'foo bar'}`;
145+
const {stdout} = await $`echo.js ${'foo bar'}`;
146146
t.is(stdout, 'foo bar');
147147
});
148148

149149
test('$ disallows escaping spaces with backslashes', async t => {
150-
const {stdout} = await $`node test/fixtures/echo.js foo\\ bar`;
150+
const {stdout} = await $`echo.js foo\\ bar`;
151151
t.is(stdout, 'foo\\\nbar');
152152
});
153153

154154
test('$ allows space escaped values in array interpolation', async t => {
155-
const {stdout} = await $`node test/fixtures/echo.js ${['foo', 'bar baz']}`;
155+
const {stdout} = await $`echo.js ${['foo', 'bar baz']}`;
156156
t.is(stdout, 'foo\nbar baz');
157157
});
158158

159159
test('$ passes newline escape sequence as one argument', async t => {
160-
const {stdout} = await $`node test/fixtures/echo.js \n`;
160+
const {stdout} = await $`echo.js \n`;
161161
t.is(stdout, '\n');
162162
});
163163

164164
test('$ passes newline escape sequence in interpolation as one argument', async t => {
165-
const {stdout} = await $`node test/fixtures/echo.js ${'\n'}`;
165+
const {stdout} = await $`echo.js ${'\n'}`;
166166
t.is(stdout, '\n');
167167
});
168168

169169
test('$ handles invalid escape sequence', async t => {
170-
const {stdout} = await $`node test/fixtures/echo.js \u`;
170+
const {stdout} = await $`echo.js \u`;
171171
t.is(stdout, '\\u');
172172
});
173173

@@ -177,17 +177,17 @@ test('$ allows escaping spaces in commands with interpolation', async t => {
177177
});
178178

179179
test('$ escapes other whitespaces', async t => {
180-
const {stdout} = await $`node test/fixtures/echo.js foo\tbar`;
180+
const {stdout} = await $`echo.js foo\tbar`;
181181
t.is(stdout, 'foo\tbar');
182182
});
183183

184184
test('$ trims', async t => {
185-
const {stdout} = await $` node test/fixtures/echo.js foo bar `;
185+
const {stdout} = await $` echo.js foo bar `;
186186
t.is(stdout, 'foo\nbar');
187187
});
188188

189189
test('$.sync', t => {
190-
const {stdout} = $.sync`node test/fixtures/echo.js foo bar`;
190+
const {stdout} = $.sync`echo.js foo bar`;
191191
t.is(stdout, 'foo\nbar');
192192
});
193193

@@ -197,38 +197,38 @@ test('$.sync accepts options', t => {
197197
});
198198

199199
test('$.sync allows execa return value interpolation', t => {
200-
const foo = $.sync`node test/fixtures/echo.js foo`;
201-
const {stdout} = $.sync`node test/fixtures/echo.js ${foo} bar`;
200+
const foo = $.sync`echo.js foo`;
201+
const {stdout} = $.sync`echo.js ${foo} bar`;
202202
t.is(stdout, 'foo\nbar');
203203
});
204204

205205
test('$.sync allows execa return value array interpolation', t => {
206-
const foo = $.sync`node test/fixtures/echo.js foo`;
207-
const {stdout} = $.sync`node test/fixtures/echo.js ${[foo, 'bar']}`;
206+
const foo = $.sync`echo.js foo`;
207+
const {stdout} = $.sync`echo.js ${[foo, 'bar']}`;
208208
t.is(stdout, 'foo\nbar');
209209
});
210210

211211
test('$.sync allows execa return value buffer interpolation', t => {
212-
const foo = $({encoding: null}).sync`node test/fixtures/echo.js foo`;
213-
const {stdout} = $.sync`node test/fixtures/echo.js ${foo} bar`;
212+
const foo = $({encoding: null}).sync`echo.js foo`;
213+
const {stdout} = $.sync`echo.js ${foo} bar`;
214214
t.is(stdout, 'foo\nbar');
215215
});
216216

217217
test('$.sync allows execa return value buffer array interpolation', t => {
218-
const foo = $({encoding: null}).sync`node test/fixtures/echo.js foo`;
219-
const {stdout} = $.sync`node test/fixtures/echo.js ${[foo, 'bar']}`;
218+
const foo = $({encoding: null}).sync`echo.js foo`;
219+
const {stdout} = $.sync`echo.js ${[foo, 'bar']}`;
220220
t.is(stdout, 'foo\nbar');
221221
});
222222

223223
const invalidExpression = test.macro({
224224
async exec(t, input, expected) {
225225
await t.throwsAsync(
226-
async () => $`node test/fixtures/echo.js ${input}`,
226+
async () => $`echo.js ${input}`,
227227
{instanceOf: TypeError, message: expected},
228228
);
229229

230230
t.throws(
231-
() => $.sync`node test/fixtures/echo.js ${input}`,
231+
() => $.sync`echo.js ${input}`,
232232
{instanceOf: TypeError, message: expected},
233233
);
234234
},

test/fixtures/detach.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
import process from 'node:process';
33
import {execa} from '../../index.js';
44

5-
const subprocess = execa('node', ['./test/fixtures/forever.js'], {detached: true});
5+
const subprocess = execa('forever.js', {detached: true});
66
console.log(subprocess.pid);
77
process.exit(0);

test/fixtures/sub-process-exit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const cleanup = process.argv[2] === 'true';
66
const detached = process.argv[3] === 'true';
77

88
try {
9-
await execa('node', ['./test/fixtures/noop.js'], {cleanup, detached});
9+
await execa('noop.js', {cleanup, detached});
1010
} catch (error) {
1111
console.error(error);
1212
process.exit(1);

test/fixtures/sub-process.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import {execa} from '../../index.js';
44

55
const cleanup = process.argv[2] === 'true';
66
const detached = process.argv[3] === 'true';
7-
const subprocess = execa('node', ['./test/fixtures/forever.js'], {cleanup, detached});
7+
const subprocess = execa('forever.js', {cleanup, detached});
88
process.send(subprocess.pid);

test/kill.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ setFixtureDir();
1010
const TIMEOUT_REGEXP = /timed out after/;
1111

1212
test('kill("SIGKILL") should terminate cleanly', async t => {
13-
const subprocess = execa('node', ['./test/fixtures/no-killable.js'], {stdio: ['ipc']});
13+
const subprocess = execa('no-killable.js', {stdio: ['ipc']});
1414
await pEvent(subprocess, 'message');
1515

1616
subprocess.kill('SIGKILL');
@@ -23,7 +23,7 @@ test('kill("SIGKILL") should terminate cleanly', async t => {
2323
// Therefore, this feature and those tests do not make sense on Windows.
2424
if (process.platform !== 'win32') {
2525
test('`forceKillAfterTimeout: false` should not kill after a timeout', async t => {
26-
const subprocess = execa('node', ['./test/fixtures/no-killable.js'], {stdio: ['ipc']});
26+
const subprocess = execa('no-killable.js', {stdio: ['ipc']});
2727
await pEvent(subprocess, 'message');
2828

2929
subprocess.kill('SIGTERM', {forceKillAfterTimeout: false});
@@ -33,7 +33,7 @@ if (process.platform !== 'win32') {
3333
});
3434

3535
test('`forceKillAfterTimeout: number` should kill after a timeout', async t => {
36-
const subprocess = execa('node', ['./test/fixtures/no-killable.js'], {stdio: ['ipc']});
36+
const subprocess = execa('no-killable.js', {stdio: ['ipc']});
3737
await pEvent(subprocess, 'message');
3838

3939
subprocess.kill('SIGTERM', {forceKillAfterTimeout: 50});
@@ -43,7 +43,7 @@ if (process.platform !== 'win32') {
4343
});
4444

4545
test('`forceKillAfterTimeout: true` should kill after a timeout', async t => {
46-
const subprocess = execa('node', ['./test/fixtures/no-killable.js'], {stdio: ['ipc']});
46+
const subprocess = execa('no-killable.js', {stdio: ['ipc']});
4747
await pEvent(subprocess, 'message');
4848

4949
subprocess.kill('SIGTERM', {forceKillAfterTimeout: true});
@@ -53,7 +53,7 @@ if (process.platform !== 'win32') {
5353
});
5454

5555
test('kill() with no arguments should kill after a timeout', async t => {
56-
const subprocess = execa('node', ['./test/fixtures/no-killable.js'], {stdio: ['ipc']});
56+
const subprocess = execa('no-killable.js', {stdio: ['ipc']});
5757
await pEvent(subprocess, 'message');
5858

5959
subprocess.kill();

test/stream.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ test('buffer', async t => {
1919

2020
test('pass `stdout` to a file descriptor', async t => {
2121
const file = tempfile('.txt');
22-
await execa('test/fixtures/noop.js', ['foo bar'], {stdout: fs.openSync(file, 'w')});
22+
await execa('noop.js', ['foo bar'], {stdout: fs.openSync(file, 'w')});
2323
t.is(fs.readFileSync(file, 'utf8'), 'foo bar\n');
2424
});
2525

2626
test('pass `stderr` to a file descriptor', async t => {
2727
const file = tempfile('.txt');
28-
await execa('test/fixtures/noop-err.js', ['foo bar'], {stderr: fs.openSync(file, 'w')});
28+
await execa('noop-err.js', ['foo bar'], {stderr: fs.openSync(file, 'w')});
2929
t.is(fs.readFileSync(file, 'utf8'), 'foo bar\n');
3030
});
3131

0 commit comments

Comments
 (0)