mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-10-27 11:18:14 +01:00 
			
		
		
		
	Remove semicolons from test
This commit is contained in:
		
							parent
							
								
									2e989fbe83
								
							
						
					
					
						commit
						c074c835d4
					
				| @ -1,262 +1,262 @@ | |||||||
| const chai = require('chai'); | const chai = require('chai') | ||||||
| const sinon = require('sinon'); | const sinon = require('sinon') | ||||||
| const fs = require('../../../server/libs/fsExtra'); | const fs = require('../../../server/libs/fsExtra') | ||||||
| const which = require('../../../server/libs/which'); | const which = require('../../../server/libs/which') | ||||||
| const path = require('path'); | const path = require('path') | ||||||
| const BinaryManager = require('../../../server/managers/BinaryManager'); | const BinaryManager = require('../../../server/managers/BinaryManager') | ||||||
| 
 | 
 | ||||||
| const expect = chai.expect; | const expect = chai.expect | ||||||
| 
 | 
 | ||||||
| describe('BinaryManager', () => { | describe('BinaryManager', () => { | ||||||
|   let binaryManager; |   let binaryManager | ||||||
| 
 | 
 | ||||||
|   describe('init', () => { |   describe('init', () => { | ||||||
|     let findStub; |     let findStub | ||||||
|     let installStub; |     let installStub | ||||||
|     let errorStub; |     let errorStub | ||||||
|     let exitStub; |     let exitStub | ||||||
| 
 | 
 | ||||||
|     beforeEach(() => { |     beforeEach(() => { | ||||||
|       binaryManager = new BinaryManager(); |       binaryManager = new BinaryManager() | ||||||
|       findStub = sinon.stub(binaryManager, 'findRequiredBinaries'); |       findStub = sinon.stub(binaryManager, 'findRequiredBinaries') | ||||||
|       installStub = sinon.stub(binaryManager, 'install'); |       installStub = sinon.stub(binaryManager, 'install') | ||||||
|       errorStub = sinon.stub(console, 'error'); |       errorStub = sinon.stub(console, 'error') | ||||||
|       exitStub = sinon.stub(process, 'exit'); |       exitStub = sinon.stub(process, 'exit') | ||||||
|     }); |     }) | ||||||
| 
 | 
 | ||||||
|     afterEach(() => { |     afterEach(() => { | ||||||
|       findStub.restore(); |       findStub.restore() | ||||||
|       installStub.restore(); |       installStub.restore() | ||||||
|       errorStub.restore(); |       errorStub.restore() | ||||||
|       exitStub.restore(); |       exitStub.restore() | ||||||
|     }); |     }) | ||||||
| 
 | 
 | ||||||
|     it('should not install binaries if they are already found', async () => { |     it('should not install binaries if they are already found', async () => { | ||||||
|       findStub.resolves([]); |       findStub.resolves([]) | ||||||
|        |        | ||||||
|       await binaryManager.init(); |       await binaryManager.init() | ||||||
| 
 | 
 | ||||||
|       expect(installStub.called).to.be.false; |       expect(installStub.called).to.be.false | ||||||
|       expect(findStub.calledOnce).to.be.true; |       expect(findStub.calledOnce).to.be.true | ||||||
|       expect(errorStub.called).to.be.false; |       expect(errorStub.called).to.be.false | ||||||
|       expect(exitStub.called).to.be.false; |       expect(exitStub.called).to.be.false | ||||||
|     }); |     }) | ||||||
| 
 | 
 | ||||||
|     it('should install missing binaries', async () => { |     it('should install missing binaries', async () => { | ||||||
|       const missingBinaries = ['ffmpeg', 'ffprobe']; |       const missingBinaries = ['ffmpeg', 'ffprobe'] | ||||||
|       const missingBinariesAfterInstall = []; |       const missingBinariesAfterInstall = [] | ||||||
|       findStub.onFirstCall().resolves(missingBinaries); |       findStub.onFirstCall().resolves(missingBinaries) | ||||||
|       findStub.onSecondCall().resolves(missingBinariesAfterInstall); |       findStub.onSecondCall().resolves(missingBinariesAfterInstall) | ||||||
| 
 | 
 | ||||||
|       await binaryManager.init(); |       await binaryManager.init() | ||||||
| 
 | 
 | ||||||
|       expect(findStub.calledTwice).to.be.true; |       expect(findStub.calledTwice).to.be.true | ||||||
|       expect(installStub.calledOnce).to.be.true; |       expect(installStub.calledOnce).to.be.true | ||||||
|       expect(errorStub.called).to.be.false; |       expect(errorStub.called).to.be.false | ||||||
|       expect(exitStub.called).to.be.false; |       expect(exitStub.called).to.be.false | ||||||
|     }); |     }) | ||||||
| 
 | 
 | ||||||
|     it('exit if binaries are not found after installation', async () => { |     it('exit if binaries are not found after installation', async () => { | ||||||
|       const missingBinaries = ['ffmpeg', 'ffprobe']; |       const missingBinaries = ['ffmpeg', 'ffprobe'] | ||||||
|       const missingBinariesAfterInstall = ['ffmpeg', 'ffprobe']; |       const missingBinariesAfterInstall = ['ffmpeg', 'ffprobe'] | ||||||
|       findStub.onFirstCall().resolves(missingBinaries); |       findStub.onFirstCall().resolves(missingBinaries) | ||||||
|       findStub.onSecondCall().resolves(missingBinariesAfterInstall); |       findStub.onSecondCall().resolves(missingBinariesAfterInstall) | ||||||
| 
 | 
 | ||||||
|       await binaryManager.init(); |       await binaryManager.init() | ||||||
| 
 | 
 | ||||||
|       expect(findStub.calledTwice).to.be.true; |       expect(findStub.calledTwice).to.be.true | ||||||
|       expect(installStub.calledOnce).to.be.true; |       expect(installStub.calledOnce).to.be.true | ||||||
|       expect(errorStub.calledOnce).to.be.true; |       expect(errorStub.calledOnce).to.be.true | ||||||
|       expect(exitStub.calledOnce).to.be.true; |       expect(exitStub.calledOnce).to.be.true | ||||||
|       expect(exitStub.calledWith(1)).to.be.true; |       expect(exitStub.calledWith(1)).to.be.true | ||||||
|     }); |     }) | ||||||
|   }); |   }) | ||||||
| 
 | 
 | ||||||
|    |    | ||||||
|   describe('findRequiredBinaries', () => { |   describe('findRequiredBinaries', () => { | ||||||
|     let findBinaryStub; |     let findBinaryStub | ||||||
| 
 | 
 | ||||||
|     beforeEach(() => { |     beforeEach(() => { | ||||||
|       const requiredBinaries = [{ name: 'ffmpeg', envVariable: 'FFMPEG_PATH' }]; |       const requiredBinaries = [{ name: 'ffmpeg', envVariable: 'FFMPEG_PATH' }] | ||||||
|       binaryManager = new BinaryManager(requiredBinaries); |       binaryManager = new BinaryManager(requiredBinaries) | ||||||
|       findBinaryStub = sinon.stub(binaryManager, 'findBinary'); |       findBinaryStub = sinon.stub(binaryManager, 'findBinary') | ||||||
|     }); |     }) | ||||||
| 
 | 
 | ||||||
|     afterEach(() => { |     afterEach(() => { | ||||||
|       findBinaryStub.restore(); |       findBinaryStub.restore() | ||||||
|     }); |     }) | ||||||
| 
 | 
 | ||||||
|     it('should put found paths in the correct environment variables', async () => { |     it('should put found paths in the correct environment variables', async () => { | ||||||
|       const pathToFFmpeg = '/path/to/ffmpeg'; |       const pathToFFmpeg = '/path/to/ffmpeg' | ||||||
|       const missingBinaries = []; |       const missingBinaries = [] | ||||||
|       delete process.env.FFMPEG_PATH; |       delete process.env.FFMPEG_PATH | ||||||
|       findBinaryStub.resolves(pathToFFmpeg); |       findBinaryStub.resolves(pathToFFmpeg) | ||||||
| 
 | 
 | ||||||
|       const result = await binaryManager.findRequiredBinaries(); |       const result = await binaryManager.findRequiredBinaries() | ||||||
| 
 | 
 | ||||||
|       expect(result).to.deep.equal(missingBinaries); |       expect(result).to.deep.equal(missingBinaries) | ||||||
|       expect(findBinaryStub.calledOnce).to.be.true; |       expect(findBinaryStub.calledOnce).to.be.true | ||||||
|       expect(process.env.FFMPEG_PATH).to.equal(pathToFFmpeg); |       expect(process.env.FFMPEG_PATH).to.equal(pathToFFmpeg) | ||||||
|     }); |     }) | ||||||
| 
 | 
 | ||||||
|     it('should add missing binaries to result', async () => { |     it('should add missing binaries to result', async () => { | ||||||
|       const missingBinaries = ['ffmpeg']; |       const missingBinaries = ['ffmpeg'] | ||||||
|       delete process.env.FFMPEG_PATH;     |       delete process.env.FFMPEG_PATH     | ||||||
|       findBinaryStub.resolves(null); |       findBinaryStub.resolves(null) | ||||||
| 
 | 
 | ||||||
|       const result = await binaryManager.findRequiredBinaries(); |       const result = await binaryManager.findRequiredBinaries() | ||||||
| 
 | 
 | ||||||
|       expect(result).to.deep.equal(missingBinaries); |       expect(result).to.deep.equal(missingBinaries) | ||||||
|       expect(findBinaryStub.calledOnce).to.be.true; |       expect(findBinaryStub.calledOnce).to.be.true | ||||||
|       expect(process.env.FFMPEG_PATH).to.be.undefined; |       expect(process.env.FFMPEG_PATH).to.be.undefined | ||||||
|     }); |     }) | ||||||
|   }); |   }) | ||||||
|    |    | ||||||
|   describe('install', () => { |   describe('install', () => { | ||||||
|     let accessStub; |     let accessStub | ||||||
|     let downloadBinariesStub; |     let downloadBinariesStub | ||||||
| 
 | 
 | ||||||
|     beforeEach(() => { |     beforeEach(() => { | ||||||
|       binaryManager = new BinaryManager(); |       binaryManager = new BinaryManager() | ||||||
|       accessStub = sinon.stub(fs, 'access'); |       accessStub = sinon.stub(fs, 'access') | ||||||
|       downloadBinariesStub = sinon.stub(binaryManager, 'downloadBinaries'); |       downloadBinariesStub = sinon.stub(binaryManager, 'downloadBinaries') | ||||||
|       binaryManager.mainInstallPath = '/path/to/main/install' |       binaryManager.mainInstallPath = '/path/to/main/install' | ||||||
|       binaryManager.altInstallPath = '/path/to/alt/install' |       binaryManager.altInstallPath = '/path/to/alt/install' | ||||||
|     }); |     }) | ||||||
| 
 | 
 | ||||||
|     afterEach(() => { |     afterEach(() => { | ||||||
|       accessStub.restore(); |       accessStub.restore() | ||||||
|       downloadBinariesStub.restore(); |       downloadBinariesStub.restore() | ||||||
|     }); |     }) | ||||||
| 
 | 
 | ||||||
|     it('should not install binaries if no binaries are passed', async () => { |     it('should not install binaries if no binaries are passed', async () => { | ||||||
|       const binaries = []; |       const binaries = [] | ||||||
| 
 | 
 | ||||||
|       await binaryManager.install(binaries); |       await binaryManager.install(binaries) | ||||||
| 
 | 
 | ||||||
|       expect(accessStub.called).to.be.false; |       expect(accessStub.called).to.be.false | ||||||
|       expect(downloadBinariesStub.called).to.be.false; |       expect(downloadBinariesStub.called).to.be.false | ||||||
|     }); |     }) | ||||||
| 
 | 
 | ||||||
|     it('should install binaries in main install path if has access', async () => { |     it('should install binaries in main install path if has access', async () => { | ||||||
|       const binaries = ['ffmpeg']; |       const binaries = ['ffmpeg'] | ||||||
|       const destination = binaryManager.mainInstallPath; |       const destination = binaryManager.mainInstallPath | ||||||
|       accessStub.withArgs(destination, fs.constants.W_OK).resolves(); |       accessStub.withArgs(destination, fs.constants.W_OK).resolves() | ||||||
|       downloadBinariesStub.resolves(); |       downloadBinariesStub.resolves() | ||||||
|        |        | ||||||
|       await binaryManager.install(binaries); |       await binaryManager.install(binaries) | ||||||
| 
 | 
 | ||||||
|       expect(accessStub.calledOnce).to.be.true; |       expect(accessStub.calledOnce).to.be.true | ||||||
|       expect(downloadBinariesStub.calledOnce).to.be.true; |       expect(downloadBinariesStub.calledOnce).to.be.true | ||||||
|       expect(downloadBinariesStub.calledWith(binaries, sinon.match({ destination: destination }))).to.be.true;   |       expect(downloadBinariesStub.calledWith(binaries, sinon.match({ destination: destination }))).to.be.true   | ||||||
|     }); |     }) | ||||||
| 
 | 
 | ||||||
|     it('should install binaries in alt install path if has no access to main', async () => { |     it('should install binaries in alt install path if has no access to main', async () => { | ||||||
|       const binaries = ['ffmpeg']; |       const binaries = ['ffmpeg'] | ||||||
|       const mainDestination = binaryManager.mainInstallPath; |       const mainDestination = binaryManager.mainInstallPath | ||||||
|       const destination = binaryManager.altInstallPath; |       const destination = binaryManager.altInstallPath | ||||||
|       accessStub.withArgs(mainDestination, fs.constants.W_OK).rejects(); |       accessStub.withArgs(mainDestination, fs.constants.W_OK).rejects() | ||||||
|       downloadBinariesStub.resolves(); |       downloadBinariesStub.resolves() | ||||||
|        |        | ||||||
|       await binaryManager.install(binaries); |       await binaryManager.install(binaries) | ||||||
| 
 | 
 | ||||||
|       expect(accessStub.calledOnce).to.be.true; |       expect(accessStub.calledOnce).to.be.true | ||||||
|       expect(downloadBinariesStub.calledOnce).to.be.true; |       expect(downloadBinariesStub.calledOnce).to.be.true | ||||||
|       expect(downloadBinariesStub.calledWith(binaries, sinon.match({ destination: destination }))).to.be.true;   |       expect(downloadBinariesStub.calledWith(binaries, sinon.match({ destination: destination }))).to.be.true   | ||||||
|     }); |     }) | ||||||
|   }); |   }) | ||||||
| }); | }) | ||||||
| 
 | 
 | ||||||
| describe('findBinary', () => { | describe('findBinary', () => { | ||||||
|   let binaryManager; |   let binaryManager | ||||||
|   let fsPathExistsStub; |   let fsPathExistsStub | ||||||
|   let whichSyncStub; |   let whichSyncStub | ||||||
|   let mainInstallPath; |   let mainInstallPath | ||||||
|   let altInstallPath; |   let altInstallPath | ||||||
| 
 | 
 | ||||||
|   const name = 'ffmpeg'; |   const name = 'ffmpeg' | ||||||
|   const envVariable = 'FFMPEG_PATH'; |   const envVariable = 'FFMPEG_PATH' | ||||||
|   const defaultPath = '/path/to/ffmpeg'; |   const defaultPath = '/path/to/ffmpeg' | ||||||
|   const executable = name + (process.platform == 'win32' ? '.exe' : ''); |   const executable = name + (process.platform == 'win32' ? '.exe' : '') | ||||||
|   const whichPath = '/usr/bin/ffmpeg'; |   const whichPath = '/usr/bin/ffmpeg' | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|   beforeEach(() => { |   beforeEach(() => { | ||||||
|     binaryManager = new BinaryManager(); |     binaryManager = new BinaryManager() | ||||||
|     fsPathExistsStub = sinon.stub(fs, 'pathExists'); |     fsPathExistsStub = sinon.stub(fs, 'pathExists') | ||||||
|     whichSyncStub = sinon.stub(which, 'sync'); |     whichSyncStub = sinon.stub(which, 'sync') | ||||||
|     binaryManager.mainInstallPath = '/path/to/main/install' |     binaryManager.mainInstallPath = '/path/to/main/install' | ||||||
|     mainInstallPath = path.join(binaryManager.mainInstallPath, executable); |     mainInstallPath = path.join(binaryManager.mainInstallPath, executable) | ||||||
|     binaryManager.altInstallPath = '/path/to/alt/install' |     binaryManager.altInstallPath = '/path/to/alt/install' | ||||||
|     altInstallPath = path.join(binaryManager.altInstallPath, executable); |     altInstallPath = path.join(binaryManager.altInstallPath, executable) | ||||||
|   }); |   }) | ||||||
| 
 | 
 | ||||||
|   afterEach(() => { |   afterEach(() => { | ||||||
|     fsPathExistsStub.restore(); |     fsPathExistsStub.restore() | ||||||
|     whichSyncStub.restore(); |     whichSyncStub.restore() | ||||||
|   }); |   }) | ||||||
| 
 | 
 | ||||||
|   it('should return defaultPath if it exists', async () => { |   it('should return defaultPath if it exists', async () => { | ||||||
|     process.env[envVariable] = defaultPath; |     process.env[envVariable] = defaultPath | ||||||
|     fsPathExistsStub.withArgs(defaultPath).resolves(true); |     fsPathExistsStub.withArgs(defaultPath).resolves(true) | ||||||
| 
 | 
 | ||||||
|     const result = await binaryManager.findBinary(name, envVariable); |     const result = await binaryManager.findBinary(name, envVariable) | ||||||
| 
 | 
 | ||||||
|     expect(result).to.equal(defaultPath); |     expect(result).to.equal(defaultPath) | ||||||
|     expect(fsPathExistsStub.calledOnceWith(defaultPath)).to.be.true; |     expect(fsPathExistsStub.calledOnceWith(defaultPath)).to.be.true | ||||||
|     expect(whichSyncStub.notCalled).to.be.true; |     expect(whichSyncStub.notCalled).to.be.true | ||||||
|   }); |   }) | ||||||
| 
 | 
 | ||||||
|   it('should return whichPath if it exists', async () => { |   it('should return whichPath if it exists', async () => { | ||||||
|     delete process.env[envVariable]; |     delete process.env[envVariable] | ||||||
|     whichSyncStub.returns(whichPath); |     whichSyncStub.returns(whichPath) | ||||||
| 
 | 
 | ||||||
|     const result = await binaryManager.findBinary(name, envVariable); |     const result = await binaryManager.findBinary(name, envVariable) | ||||||
| 
 | 
 | ||||||
|     expect(result).to.equal(whichPath); |     expect(result).to.equal(whichPath) | ||||||
|     expect(fsPathExistsStub.notCalled).to.be.true; |     expect(fsPathExistsStub.notCalled).to.be.true | ||||||
|     expect(whichSyncStub.calledOnce).to.be.true; |     expect(whichSyncStub.calledOnce).to.be.true | ||||||
|   }); |   }) | ||||||
| 
 | 
 | ||||||
|   it('should return mainInstallPath if it exists', async () => { |   it('should return mainInstallPath if it exists', async () => { | ||||||
|     delete process.env[envVariable]; |     delete process.env[envVariable] | ||||||
|     whichSyncStub.returns(null); |     whichSyncStub.returns(null) | ||||||
|     fsPathExistsStub.withArgs(mainInstallPath).resolves(true); |     fsPathExistsStub.withArgs(mainInstallPath).resolves(true) | ||||||
| 
 | 
 | ||||||
|     const result = await binaryManager.findBinary(name, envVariable); |     const result = await binaryManager.findBinary(name, envVariable) | ||||||
| 
 | 
 | ||||||
|     expect(result).to.equal(mainInstallPath); |     expect(result).to.equal(mainInstallPath) | ||||||
|     expect(whichSyncStub.calledOnce).to.be.true; |     expect(whichSyncStub.calledOnce).to.be.true | ||||||
|     expect(fsPathExistsStub.calledOnceWith(mainInstallPath)).to.be.true; |     expect(fsPathExistsStub.calledOnceWith(mainInstallPath)).to.be.true | ||||||
|   }); |   }) | ||||||
| 
 | 
 | ||||||
|   it('should return altInstallPath if it exists', async () => { |   it('should return altInstallPath if it exists', async () => { | ||||||
|     delete process.env[envVariable]; |     delete process.env[envVariable] | ||||||
|     whichSyncStub.returns(null); |     whichSyncStub.returns(null) | ||||||
|     fsPathExistsStub.withArgs(mainInstallPath).resolves(false); |     fsPathExistsStub.withArgs(mainInstallPath).resolves(false) | ||||||
|     fsPathExistsStub.withArgs(altInstallPath).resolves(true); |     fsPathExistsStub.withArgs(altInstallPath).resolves(true) | ||||||
| 
 | 
 | ||||||
|     const result = await binaryManager.findBinary(name, envVariable); |     const result = await binaryManager.findBinary(name, envVariable) | ||||||
| 
 | 
 | ||||||
|     expect(result).to.equal(altInstallPath); |     expect(result).to.equal(altInstallPath) | ||||||
|     expect(whichSyncStub.calledOnce).to.be.true; |     expect(whichSyncStub.calledOnce).to.be.true | ||||||
|     expect(fsPathExistsStub.calledTwice).to.be.true; |     expect(fsPathExistsStub.calledTwice).to.be.true | ||||||
|     expect(fsPathExistsStub.calledWith(mainInstallPath)).to.be.true; |     expect(fsPathExistsStub.calledWith(mainInstallPath)).to.be.true | ||||||
|     expect(fsPathExistsStub.calledWith(altInstallPath)).to.be.true; |     expect(fsPathExistsStub.calledWith(altInstallPath)).to.be.true | ||||||
|   }); |   }) | ||||||
| 
 | 
 | ||||||
|   it('should return null if binary is not found', async () => { |   it('should return null if binary is not found', async () => { | ||||||
|     delete process.env[envVariable]; |     delete process.env[envVariable] | ||||||
|     whichSyncStub.returns(null); |     whichSyncStub.returns(null) | ||||||
|     fsPathExistsStub.withArgs(mainInstallPath).resolves(false); |     fsPathExistsStub.withArgs(mainInstallPath).resolves(false) | ||||||
|     fsPathExistsStub.withArgs(altInstallPath).resolves(false); |     fsPathExistsStub.withArgs(altInstallPath).resolves(false) | ||||||
| 
 | 
 | ||||||
|     const result = await binaryManager.findBinary(name, envVariable); |     const result = await binaryManager.findBinary(name, envVariable) | ||||||
| 
 | 
 | ||||||
|     expect(result).to.be.null; |     expect(result).to.be.null | ||||||
|     expect(whichSyncStub.calledOnce).to.be.true; |     expect(whichSyncStub.calledOnce).to.be.true | ||||||
|     expect(fsPathExistsStub.calledTwice).to.be.true; |     expect(fsPathExistsStub.calledTwice).to.be.true | ||||||
|     expect(fsPathExistsStub.calledWith(mainInstallPath)).to.be.true; |     expect(fsPathExistsStub.calledWith(mainInstallPath)).to.be.true | ||||||
|     expect(fsPathExistsStub.calledWith(altInstallPath)).to.be.true; |     expect(fsPathExistsStub.calledWith(altInstallPath)).to.be.true | ||||||
|   }); |   }) | ||||||
| }); | }) | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user