destroyEvent: sinon .stub() .withArgs('event-to-delete') .resolves(), },
describe('name setter', function () { it('sets name into cliConfig and saves it', function () { const config = createConfigStub(); config.set.withArgs('name', 'testing').returnsThis(); const testInstance = new Instance({}, {}, ''); testInstance._cliConfig = config; testInstance.name = 'testing'; expect(config.set.calledOnce).to.be.true; expect(config.save.calledOnce).to.be.true; }); });
it('fails when config.js present', function () { const existsStub = sinon.stub(fs, 'existsSync'); existsStub.withArgs(sinon.match(/config\.js/)).returns(true); const errorStub = sinon.stub(console, 'error'); expect(checkValidInstall('test')).to.equal(false); expect(existsStub.calledOnce).to.be.true; expect(errorStub.calledOnce).to.be.true; expect(existsStub.args[0][0]).to.match(/config\.js/); expect(errorStub.args[0][0]).to.match(/Ghost-CLI only works with Ghost versions >= 1\.0\.0/); });
it("Allows setting a custom validation rate", () => { const network = new Network({Module: fakeModule}) const stub = sinon.stub(fakeModule, "ccall").callsFake(() => 0) return network.train(testData, {validation: {interval: 2, data: testData}}).then(() => { expect(stub.withArgs("set_validationInterval")).to.be.calledWith("set_validationInterval", null, ["number", "number"], [0, 2]) stub.restore() }) })
function testConfigAccessors(instanceProp, configProp, defaultValue = null) { return () => { const config = createConfigStub(); config.get.withArgs(configProp, defaultValue).returns('1.0.0'); const instance = new Instance({}, {}, ''); instance._cliConfig = config; expect(instance[instanceProp]).to.equal('1.0.0'); expect(config.get.calledOnce).to.be.true; instance[instanceProp] = '2.0.0'; expect(config.set.calledOnce).to.be.true; expect(config.set.calledWithExactly(configProp, '2.0.0')).to.be.true; expect(config.save.calledOnce).to.be.true; }; }
it('passes in "valid" installation', function () { const existsStub = sinon.stub(fs, 'existsSync'); existsStub.withArgs(sinon.match(/config\.js/)).returns(false); existsStub.withArgs(sinon.match(/package\.json/)).returns(false); existsStub.withArgs(sinon.match(/\.ghost-cli/)).returns(true); const errorStub = sinon.stub(console, 'error'); expect(checkValidInstall('test')).to.equal(true); expect(existsStub.calledThrice).to.be.true; expect(errorStub.called).to.be.false; });
beforeEach(async function() { let reason = null; const mocks = { readFileSync: sinon.stub().withArgs('/minke/minke-restart-reason').callsFake(function(name) { return reason; }), writeFileSync: sinon.stub().withArgs('/minke/minke-restart-reason').callsFake(function(name, v) { reason = v; }) }; mock('fs', mocks); const MinkeSetup = mock.reRequire('../../MinkeSetup'); mock.stop('fs'); const app = new MinkeSetup(null, {}, {}); this.MinkeSetup = MinkeSetup; this.app = app; });
it('fails within a Ghost git clone', function () { const existsStub = sinon.stub(fs, 'existsSync'); const readJsonStub = sinon.stub(fs, 'readJsonSync'); existsStub.withArgs(sinon.match(/config\.js/)).returns(false); existsStub.withArgs(sinon.match(/package\.json/)).returns(true); existsStub.withArgs(sinon.match(/Gruntfile\.js/)).returns(true); readJsonStub.returns({name: 'ghost'}); const errorStub = sinon.stub(console, 'error'); expect(checkValidInstall('test')).to.equal(false); expect(existsStub.calledThrice).to.be.true; expect(errorStub.calledOnce).to.be.true; expect(existsStub.args[1][0]).to.match(/package\.json/); expect(errorStub.args[0][0]).to.match(/Ghost-CLI commands do not work inside of a git clone/); });
beforeEach(() => { sinon.stub(exec, 'exists').withArgs('findsecbugs').resolves(true) sinon.stub(exec, 'command').resolves({ stdout: '' }) })
it('skips if cert has not been generated using the old method', function () { const skip = sinon.stub(); const existsSync = sinon.stub(); existsSync.withArgs('/var/www/ghost/system/files/ghost.org-ssl.conf').returns(true); existsSync.withArgs('/home/ghost/.acme.sh/ghost.org').returns(false); const migrate = proxyquire(modulePath, { 'fs-extra': {existsSync: existsSync}, os: {homedir: () => '/home/ghost'} }); migrate.migrateSSL(context, {skip: skip}); expect(existsSync.calledTwice).to.be.true; expect(existsSync.calledWithExactly('/var/www/ghost/system/files/ghost.org-ssl.conf')).to.be.true; expect(existsSync.calledWithExactly('/home/ghost/.acme.sh/ghost.org')).to.be.true; expect(skip.calledOnce).to.be.true; });
it('setRunningMode', function () { const setStub = sinon.stub().withArgs('running', 'testing').returnsThis(); const saveStub = sinon.stub(); const testInstance = new Instance({}, {}, ''); testInstance._cliConfig = {set: setStub, save: saveStub}; testInstance.setRunningMode('testing'); expect(setStub.calledOnce).to.be.true; expect(saveStub.calledOnce).to.be.true; });
it('returns false if running property not set in config & neither config exists', async function () { const hasStub = sinon.stub().withArgs('running').returns(false); const setEnvironmentStub = sinon.stub(); const testInstance = new Instance({}, {development: true, setEnvironment: setEnvironmentStub}, ''); testInstance._cliConfig = {has: hasStub}; const existsStub = sinon.stub(Config, 'exists').returns(false); const running = await testInstance.isRunning(); expect(running).to.be.false; expect(hasStub.calledOnce).to.be.true; expect(existsStub.calledTwice).to.be.true; expect(setEnvironmentStub.calledOnce).to.be.true; expect(setEnvironmentStub.calledWithExactly(true)).to.be.true; });
it('neither passes nor fails when .ghost-cli file is missing', function () { const existsStub = sinon.stub(fs, 'existsSync'); existsStub.withArgs(sinon.match(/config\.js/)).returns(false); existsStub.withArgs(sinon.match(/package\.json/)).returns(false); existsStub.withArgs(sinon.match(/\.ghost-cli/)).returns(false); expect(checkValidInstall('test')).to.equal(null); expect(existsStub.calledThrice).to.be.true; expect(existsStub.args[2][0]).to.match(/\.ghost-cli/); });
it("CCalls the WASM Module's train function for every iteration when a callback is given", () => { const network = new Network({Module: fakeModule}) const stub = sinon.stub(fakeModule, "ccall").callsFake(() => 0) const cb = () => {} return network.train(testData, {callback: cb}).then(() => { expect(stub.withArgs("train").callCount).to.equal(4) stub.restore() }) })
it("Stops ccalling the train function when the stoppedEarly value is true", () => { const network = new Network({Module: fakeModule}) let counter = 0 const stub = sinon.stub(fakeModule, "ccall").callsFake(_ => { if (_=="get_stoppedEarly") { return ++counter>2 } return 0 }) return network.train(testData, {epochs: 5}).then(() => { expect(stub.withArgs("train").callCount).to.equal(3) stub.restore() }) })