results.push(result[0]); seed2 = result[0]; assert.ok(stub.called); stub.restore(); stub.callsFake((kernel) => {
it('Leaves nginx alone when no config file exists', function () { const {exists, inst, restartNginx} = stub(); exists.returns(false); return inst.uninstall(instance).then(() => { expect(exists.calledTwice).to.be.true; expect(restartNginx.called).to.be.false; }); });
it('rejects with error if execa command fails', function () { const execaStub = sinon.stub(execa, 'shell').rejects(new Error('oops, cmd could not be executed')); return filePermissions.task({}).then(() => { expect(false, 'error should have been thrown').to.be.true; }).catch((error) => { expect(error).to.be.an.instanceof(errors.ProcessError); expect(error.message).to.match(/oops, cmd could not be executed/); expect(execaStub.called).to.be.true; }); });
it('returns if pidfile not found', function () { const readFileStub = sinon.stub(fs, 'readFileSync').throws({code: 'ENOENT'}); const fkillStub = sinon.stub(); const LocalProcess = proxyquire(modulePath, { fkill: fkillStub }); const instance = new LocalProcess({}, {}, {}); return instance.stop('/var/www/ghost').then(() => { expect(readFileStub.calledWithExactly('/var/www/ghost/.ghostpid')).to.be.true; expect(fkillStub.called).to.be.false; }); });
it('skips when content when ghost is locally installed', function () { const execaStub = sinon.stub(execa, 'shell').resolves(); expect(filePermissions).to.exist; expect(filePermissions.enabled({instance: {process: {name: 'local'}}}), 'skips if no Ghost user should be used').to.be.false; expect(execaStub.called).to.be.false; });
it('with quiet enabled, resolves a static value', function () { const ui = new UI(); return ui.run('foo', null, {quiet: true}).then((result) => { expect(result).to.equal('foo'); expect(oraStub.called).to.be.false; }); });
it('skips checking parent folder permissions if --no-setup-linux-user is passed', function () { const accessStub = sinon.stub(fs, 'access').resolves(); const checkDirectoryStub = sinon.stub().resolves(); const installFolderPermissions = proxyquire(modulePath, { './check-directory': checkDirectoryStub }).task; const ctx = {argv: {'setup-linux-user': false}, system: {platform: {linux: false}}}; return installFolderPermissions(ctx).then(() => { expect(accessStub.calledOnce).to.be.true; expect(checkDirectoryStub.called).to.be.false; }); });
// @todo: Add more tests if necessary it('configureOptions loops over extensions', function () { const extensions = [{ config: {options: {setup: {test: true}}} }, {}]; const yargs = {option: sinon.stub(), epilogue: () => true}; yargs.option.returns(yargs); SetupCommand.configureOptions.call({options: {}}, 'Test', yargs, extensions, true); expect(yargs.option.called).to.be.true; expect(yargs.option.args[0][0]).to.equal('test'); });
it('doesn\'t run if the user backs out', async function () { const argv = {force: true}; const {command, ui} = createInstance(); ui.confirm.resolves(false); ui.listr.resolves(); await command.run(argv); expect(ui.confirm.calledOnce).to.be.true; expect(ui.log.called).to.be.false; expect(ui.listr.called).to.be.false; });
it('returns if directory is root', function () { const lstatStub = sinon.stub(fs, 'lstat').resolves(); const isRootStub = sinon.stub().returns(true); const checkDirectoryAndAbove = proxyquire(modulePath, { 'path-is-root': isRootStub }); return checkDirectoryAndAbove('/some/dir').then(() => { expect(lstatStub.called).to.be.false; expect(isRootStub.calledOnce).to.be.true; expect(isRootStub.calledWithExactly('/some/dir')).to.be.true; }); });
it('works with false', function () { const ui = new UI(); const log = sinon.stub(ui, 'log'); const formatDebug = sinon.stub(ui, '_formatDebug'); ui.error(false); expect(log.called).to.be.false; expect(formatDebug.calledOnce).to.be.true; });
it('skips if windows', function () { const statStub = sinon.stub(fs, 'lstatSync'); const instance = new LocalProcess({}, { platform: {windows: true} }, {}); modeStub.returns({others: {write: false, read: false}}); const result = instance._checkContentFolder('/var/www/ghost'); expect(result).to.be.true; expect(statStub.called).to.be.false; expect(modeStub.called).to.be.false; });
it('spinner does nothing with no tasks', function () { const renderer = new Renderer({}, []); const start = sinon.stub(); const buildText = sinon.stub(renderer, 'buildText').callsFake(({name}) => name); renderer.spinner = {start, paused: false}; renderer.frame(); expect(start.called).to.be.false; expect(buildText.called).to.be.false; });
it('passes if all folders have the correct permissions', function () { const execaStub = sinon.stub(execa, 'shell').resolves({stdout: ''}); return folderPermissions.task({}).then(() => { expect(execaStub.called).to.be.true; }); });
it('rejects with error if execa command fails', function () { const execaStub = sinon.stub(execa, 'shell').rejects(new Error('oops, cmd could not be executed')); return folderPermissions.task({}).then(() => { expect(false, 'error should have been thrown').to.be.true; }).catch((error) => { expect(error).to.be.an.instanceof(errors.ProcessError); expect(error.message).to.match(/oops, cmd could not be executed/); expect(execaStub.called).to.be.true; }); });