Skip to content

Commit 9f8c550

Browse files
authored
portability, add vitest config (#92)
tried running this on my nixos machine but echo is not in /bin/ on nixos :( also added some excludes to vitest.config.ts as it was running some tests in `.direnv` for some reason
1 parent f243789 commit 9f8c550

2 files changed

Lines changed: 28 additions & 25 deletions

File tree

tests/index.test.ts

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
test,
1010
expect,
1111
beforeEach,
12-
afterEach,
1312
vi,
1413
type Mock,
1514
assert,
@@ -65,7 +64,7 @@ describe('PTY', { repeats: 500 }, () => {
6564

6665
const onExit = vi.fn();
6766
const pty = new Pty({
68-
command: '/bin/echo',
67+
command: 'echo',
6968
args: [message],
7069
onExit,
7170
});
@@ -87,7 +86,7 @@ describe('PTY', { repeats: 500 }, () => {
8786
const oldFds = getOpenFds();
8887
const onExit = vi.fn();
8988
const pty = new Pty({
90-
command: '/bin/sh',
89+
command: 'sh',
9190
args: ['-c', 'exit 17'],
9291
onExit,
9392
});
@@ -107,7 +106,7 @@ describe('PTY', { repeats: 500 }, () => {
107106
const onExit = vi.fn();
108107

109108
const pty = new Pty({
110-
command: '/bin/cat',
109+
command: 'cat',
111110
onExit,
112111
});
113112

@@ -142,7 +141,7 @@ describe('PTY', { repeats: 500 }, () => {
142141
const onExit = vi.fn();
143142

144143
const pty = new Pty({
145-
command: '/bin/cat',
144+
command: 'cat',
146145
interactive: false,
147146
onExit,
148147
});
@@ -169,7 +168,7 @@ describe('PTY', { repeats: 500 }, () => {
169168
const onExit = vi.fn();
170169

171170
const pty = new Pty({
172-
command: '/bin/sh',
171+
command: 'sh',
173172
size: { rows: 24, cols: 80 },
174173
onExit,
175174
});
@@ -222,7 +221,7 @@ describe('PTY', { repeats: 500 }, () => {
222221
const onExit = vi.fn();
223222

224223
const pty = new Pty({
225-
command: '/bin/pwd',
224+
command: 'pwd',
226225
dir: cwd,
227226
onExit,
228227
});
@@ -245,7 +244,7 @@ describe('PTY', { repeats: 500 }, () => {
245244
const onExit = vi.fn();
246245

247246
const pty = new Pty({
248-
command: '/bin/sh',
247+
command: 'sh',
249248
args: ['-c', 'echo $ENV_VARIABLE && exit'],
250249
envs: {
251250
ENV_VARIABLE: message,
@@ -267,7 +266,7 @@ describe('PTY', { repeats: 500 }, () => {
267266
test("resize after exit shouldn't throw", async () => {
268267
const onExit = vi.fn();
269268
const pty = new Pty({
270-
command: '/bin/echo',
269+
command: 'echo',
271270
args: ['hello'],
272271
onExit,
273272
});
@@ -284,7 +283,7 @@ describe('PTY', { repeats: 500 }, () => {
284283
test("resize after close shouldn't throw", async () => {
285284
const onExit = vi.fn();
286285
const pty = new Pty({
287-
command: '/bin/sh',
286+
command: 'sh',
288287
onExit,
289288
});
290289

@@ -309,7 +308,7 @@ describe('PTY', { repeats: 500 }, () => {
309308
const onExit = vi.fn();
310309

311310
const pty = new Pty({
312-
command: '/bin/sh',
311+
command: 'sh',
313312
args: ['-c', `seq 0 ${n}`],
314313
onExit,
315314
});
@@ -340,7 +339,7 @@ describe('PTY', { repeats: 500 }, () => {
340339
const onExit = vi.fn();
341340

342341
const pty = new Pty({
343-
command: '/bin/echo',
342+
command: 'echo',
344343
args: ['-n', payload],
345344
onExit,
346345
});
@@ -364,7 +363,7 @@ describe('PTY', { repeats: 500 }, () => {
364363
let buffer = Buffer.from('');
365364

366365
const pty = new Pty({
367-
command: '/bin/sh',
366+
command: 'sh',
368367
args: ['-c', 'sleep 0.1 ; ls /proc/$$/fd'],
369368
onExit,
370369
});
@@ -412,7 +411,7 @@ describe('PTY', { repeats: 500 }, () => {
412411
buffers[i] = Buffer.from('');
413412

414413
const pty = new Pty({
415-
command: '/bin/cat',
414+
command: 'cat',
416415
onExit,
417416
});
418417

@@ -460,7 +459,7 @@ describe('PTY', { repeats: 500 }, () => {
460459

461460
await expect(async () => {
462461
new Pty({
463-
command: '/bin/this-does-not-exist',
462+
command: 'this-does-not-exist',
464463
onExit: () => {},
465464
});
466465
}).rejects.toThrow('No such file or directory');
@@ -472,7 +471,7 @@ describe('PTY', { repeats: 500 }, () => {
472471
const oldFds = getOpenFds();
473472
const onExit = vi.fn();
474473
const pty = new Pty({
475-
command: '/bin/echo',
474+
command: 'echo',
476475
args: ['hello'],
477476
onExit,
478477
});
@@ -498,11 +497,10 @@ describe('PTY', { repeats: 500 }, () => {
498497

499498
test('cannot resize when out of range', async () => {
500499
const oldFds = getOpenFds();
501-
let buffer = '';
502500

503501
const onExit = vi.fn();
504502
const pty = new Pty({
505-
command: '/bin/sh',
503+
command: 'sh',
506504
size: { rows: 24, cols: 80 },
507505
onExit,
508506
});
@@ -708,7 +706,7 @@ describe('cgroup opts', async () => {
708706
const onExit = vi.fn();
709707

710708
const pty = new Pty({
711-
command: '/bin/cat',
709+
command: 'cat',
712710
args: ['/proc/self/cgroup'],
713711
cgroupPath: cgroupState.sliceDir,
714712
onExit,
@@ -730,7 +728,7 @@ describe('cgroup opts', async () => {
730728
testOnlyOnDarwin('cgroup is not supported on darwin', async () => {
731729
expect(() => {
732730
new Pty({
733-
command: '/bin/cat',
731+
command: 'cat',
734732
args: ['/proc/self/cgroup'],
735733
cgroupPath: '/sys/fs/cgroup/test.slice',
736734
onExit: vi.fn(),
@@ -773,7 +771,7 @@ describe('sandbox opts', { repeats: 10 }, async () => {
773771
const onExit = vi.fn();
774772

775773
const pty = new Pty({
776-
command: '/bin/sh',
774+
command: 'sh',
777775
args: ['-c', 'echo hello'],
778776
cgroupPath: cgroupState.sliceDir,
779777
sandbox: {
@@ -816,8 +814,8 @@ describe('sandbox opts', { repeats: 10 }, async () => {
816814
const gitPath = `${tempDirPath}/.git`;
817815
await mkdir(gitPath);
818816
const pty = new Pty({
819-
command: '/bin/sh',
820-
args: ['-c', `/bin/sh -c "rm -rf ${gitPath}"`],
817+
command: 'sh',
818+
args: ['-c', `sh -c "rm -rf ${gitPath}"`],
821819
cgroupPath: cgroupState.sliceDir,
822820
sandbox: {
823821
rules: [
@@ -863,8 +861,8 @@ describe('sandbox opts', { repeats: 10 }, async () => {
863861
const indexLockPath = `${gitPath}/index.lock`;
864862
await writeFile(indexLockPath, 'locked');
865863
const pty = new Pty({
866-
command: '/bin/sh',
867-
args: ['-c', `/bin/sh -c "rm -f ${indexLockPath}"`],
864+
command: 'sh',
865+
args: ['-c', `sh -c "rm -f ${indexLockPath}"`],
868866
cgroupPath: cgroupState.sliceDir,
869867
sandbox: {
870868
rules: [

vitest.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
test: {
3+
exclude: ['node_modules', 'dist', '.direnv'],
4+
},
5+
};

0 commit comments

Comments
 (0)