From b57f41746b09a0dc2b98238faa5be9ff968fcd8b Mon Sep 17 00:00:00 2001 From: Zxilly Date: Sat, 17 Feb 2024 05:20:45 +0800 Subject: [PATCH] test: need new way to test `run` --- src/index.test.ts | 62 ----------------------------------------------- 1 file changed, 62 deletions(-) diff --git a/src/index.test.ts b/src/index.test.ts index fa7ea74..bff90c9 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -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((binWrapper), 'canExec').mockImplementationOnce(() => Promise.resolve(false)); - - await expect(binWrapper.run()).rejects.toThrowError(`The binary "${binWrapper.path()}" is not executable`); - expect(binWrapper.ensureExist).toHaveBeenCalled(); - expect((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((binWrapper), 'canExec').mockImplementationOnce(() => Promise.resolve(true)); - - await expect(binWrapper.run()).resolves.toBeUndefined(); - expect(binWrapper.ensureExist).toHaveBeenCalled(); - expect((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((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((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((binWrapper), 'canExec').mockImplementationOnce(() => Promise.resolve(true)); - - await expect(binWrapper.run(cmd)).resolves.toBeUndefined(); - expect(binWrapper.ensureExist).toHaveBeenCalled(); - expect((binWrapper).canExec).toHaveBeenCalled(); - }); - }); });