Skip to content

Commit

Permalink
test: need new way to test run
Browse files Browse the repository at this point in the history
  • Loading branch information
Zxilly committed Feb 16, 2024
1 parent c05e13d commit b57f417
Showing 1 changed file with 0 additions and 62 deletions.
62 changes: 0 additions & 62 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,66 +84,4 @@ describe('BinWrapper', () => {
expect(pat).toBe(path.join(dest, bin));
});
});

describe('run', () => {
it('should ensure the binary exists and throw an error if it is not executable', async () => {
const dest = '/path/to/destination';
const bin = 'binary';
binWrapper.dest(dest);
binWrapper.use(bin);

jest.spyOn(binWrapper, 'ensureExist').mockImplementationOnce(() => Promise.resolve());
jest.spyOn((<any>binWrapper), 'canExec').mockImplementationOnce(() => Promise.resolve(false));

await expect(binWrapper.run()).rejects.toThrowError(`The binary "${binWrapper.path()}" is not executable`);
expect(binWrapper.ensureExist).toHaveBeenCalled();
expect((<any>binWrapper).canExec).toHaveBeenCalled();
});

it('should ensure the binary exists and not throw an error if it is executable', async () => {
const dest = '/path/to/destination';
const bin = 'binary';
binWrapper.dest(dest);
binWrapper.use(bin);

jest.spyOn(binWrapper, 'ensureExist').mockImplementationOnce(() => Promise.resolve());
jest.spyOn((<any>binWrapper), 'canExec').mockImplementationOnce(() => Promise.resolve(true));

await expect(binWrapper.run()).resolves.toBeUndefined();
expect(binWrapper.ensureExist).toHaveBeenCalled();
expect((<any>binWrapper).canExec).toHaveBeenCalled();
});

it('should ensure the binary exists with custom command and throw an error if it is not executable', async () => {
const dest = '/path/to/destination';
const bin = 'binary';
binWrapper.dest(dest);
binWrapper.use(bin);

const cmd = ['custom', 'command'];

jest.spyOn(binWrapper, 'ensureExist').mockImplementationOnce(() => Promise.resolve());
jest.spyOn((<any>binWrapper), 'canExec').mockImplementationOnce(() => Promise.resolve(false));

await expect(binWrapper.run(cmd)).rejects.toThrowError(`The binary "${binWrapper.path()}" is not executable`);
expect(binWrapper.ensureExist).toHaveBeenCalled();
expect((<any>binWrapper).canExec).toHaveBeenCalled();
});

it('should ensure the binary exists with custom command and not throw an error if it is executable', async () => {
const dest = '/path/to/destination';
const bin = 'binary';
binWrapper.dest(dest);
binWrapper.use(bin);

const cmd = ['custom', 'command'];

jest.spyOn(binWrapper, 'ensureExist').mockImplementationOnce(() => Promise.resolve());
jest.spyOn((<any>binWrapper), 'canExec').mockImplementationOnce(() => Promise.resolve(true));

await expect(binWrapper.run(cmd)).resolves.toBeUndefined();
expect(binWrapper.ensureExist).toHaveBeenCalled();
expect((<any>binWrapper).canExec).toHaveBeenCalled();
});
});
});

0 comments on commit b57f417

Please sign in to comment.