expect(p.textContent).to.match(/^Clicked: 1 times/) })
describe('password.generate', () => { it('should contains only 20 numbers', () => { const password = generate(20, { number: true }); expect(password).to.match(/^\d{20}$/); }); expect(password).to.match(/^[a-z]{20}$/); }); expect(password).to.match(/^[A-Z]{20}$/); }); const password = generate(20, { symbol: true }); expect(password).to.be.lengthOf(20); expect(password).to.not.match(/[a-zA-Z0-9]/); }); expect(password).to.match(/^[a-zA-Z0-9]{20}$/); });
it('should display initial count', () => { const { p } = setup() expect(p.textContent).to.match(/^Clicked: 0 times/) }) const { buttons, p } = setup() TestUtils.Simulate.click(buttons[0]) expect(p.textContent).to.match(/^Clicked: 1 times/) }) const { buttons, p } = setup() TestUtils.Simulate.click(buttons[1]) expect(p.textContent).to.match(/^Clicked: -1 times/) }) const { buttons, p } = setup() TestUtils.Simulate.click(buttons[0]) expect(p.textContent).to.match(/^Clicked: 1 times/) TestUtils.Simulate.click(buttons[2]) expect(p.textContent).to.match(/^Clicked: 0 times/) }) const { buttons, p } = setup() TestUtils.Simulate.click(buttons[0]) expect(p.textContent).to.match(/^Clicked: 1 times/) TestUtils.Simulate.click(buttons[2]) expect(p.textContent).to.match(/^Clicked: 0 times/) TestUtils.Simulate.click(buttons[3]) expect(p.textContent).to.match(/^Clicked: 1 times/)
it('should handle mocha test', function (done) { exec('mocha ' + path.join(__dirname, '/src/mocha/test.js'), function (_, result) { expect(result.toString('utf8')).to.match(/1 passing/) done() }) })
it('mailservice', function () { expect(options.mailservice).to.exist; expect(options.mailservice.validate('Mailgun')).to.be.true; expect(options.mailservice.validate('CaspersFriendlyEmailService')).to.match(/Invalid mail service/); });
it('rejects if a CLI version is specified in package.json and is not compatible with the current CLI version', async function () { try { await versionFromZip(path.join(__dirname, '../../fixtures/ghost-invalid-cli.zip')); expect(false, 'error should have been thrown').to.be.true; } catch (error) { expect(error).to.be.an.instanceof(SystemError); expect(error.message).to.equal('Zip file contains a Ghost version incompatible with this version of the CLI.'); expect(error.options.help).to.match(/Required: v\^0\.0\.1, current: v/); expect(error.options.suggestion).to.equal('npm install -g ghost-cli@latest'); } });
it("can be called with an error and a message", () => { function warnWithStackTrace () { util.warn(new SyntaxError("Test Error"), "Testing 1, 2, 3"); } warnWithStackTrace(); sinon.assert.calledOnce(console.warn); expect(console.warn.firstCall.args[0]).to.match(/^Testing 1, 2, 3 \nSyntaxError\: Test Error/); expect(console.warn.firstCall.args[0]).to.contain("at warnWithStackTrace"); });
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; }); });
it("should output to a file (--outfile=<file>) as YAML", () => { let output = helper.run("bundle", "-t", "yaml", "--outfile=test/.tmp/bundled.yaml", "test/files/valid/multi-file/api.yaml"); expect(output.stderr).to.have.lengthOf(0); expect(output.status).to.equal(0); expect(output.stdout).to.be.match(/Created test[/\\].tmp[/\\]bundled.yaml from test[/\\]files[/\\]valid[/\\]multi-file[/\\]api.yaml\n/); let expectedOutput = readFile("test/files/valid/multi-file/api.bundled.yaml"); let actualOutput = readFile("test/.tmp/bundled.yaml"); expect(actualOutput).to.equal(expectedOutput); });
it('when account has no funds should fail', function (done) { validParams.secret = account3.password; validParams.secondSecret = account3.password; putSignature(validParams, function (err, res) { node.expect(res.body).to.have.property('success').to.be.not.ok; node.expect(res.body).to.have.property('error').to.match(/Account does not have enough ARK: [a-zA-Z0-9]+ balance: 0/); done(); }); });
it("should error if an invalid argument is used", () => { let cli = bump("--commit --help --fizzbuzz --quiet"); expect(cli).to.have.exitCode(9); expect(cli).to.have.stdout(""); expect(cli.stderr).to.match(/^Unknown option: --fizzbuzz\n\nUsage: bump \[release\] \[options\] \[files...\]\n/); });
it("should error if an invalid shorthand argument is used", () => { let cli = exec.cli("-dqzv"); expect(cli).to.have.exitCode(9); expect(cli).to.have.stdout(""); expect(cli.stderr).to.match(/^Unknown option: -z\n\nUsage: npm-publish \[options\] \[package_path\]\n/); });
it("can be called with just an error", () => { function warnWithStackTrace () { util.warn(new RangeError("Test Error")); } warnWithStackTrace(); sinon.assert.calledOnce(console.warn); expect(console.warn.firstCall.args[0]).to.match(/^RangeError\: Test Error/); expect(console.warn.firstCall.args[0]).to.contain("at warnWithStackTrace"); });
it("can be called with an error, a message, and params", () => { function warnWithStackTrace () { util.warn(new Error("Test Error"), "Testing %s, %d, %j", 1, 2, "3"); } warnWithStackTrace(); sinon.assert.calledOnce(console.warn); expect(console.warn.firstCall.args[0]).to.match(/^Testing 1, 2, "3" \nError\: Test Error/); expect(console.warn.firstCall.args[0]).to.contain("at warnWithStackTrace"); });
it("should error if an argument is missing its value", () => { let cli = bump("--commit --help --preid --quiet"); expect(cli).to.have.exitCode(9); expect(cli).to.have.stdout(""); expect(cli.stderr).to.match( /^The --preid option requires a value, such as "alpha", "beta", etc\.\n\nUsage: bump \[release\] \[options\] \[files...\]\n/ ); });