Example #1
0
  'reads and returns html in a json object': function () {
    fs.exists.withArgs('some/test.html').yields(true);
    fs.readFile.withArgs('some/test.html').yields(null,
        new Buffer('<b>html</b>'));
    var spy = sinon.spy();

    fileReader.read('some/test', {}, spy);

    sinon.assert.calledOnce(spy);
    sinon.assert.calledWithMatch(spy, null, { html : '<b>html</b>' });
  },
Example #2
0
 }).then(() => {
   sinon.assert.calledWithMatch(createLinter, {
     config: {
       pretty: true,
       metadata: true,
       output: 'json',
       boring: true,
       selfHosted: true,
     },
   });
 });
Example #3
0
 it('extends content of existing JSON file', () => {
   const filepath = path.join(__dirname, 'fixtures/does-not-exist.txt');
   const contents = {b: 2};
   const write = sinon.spy(fs, 'write');
   const read = sinon.stub(fs, 'readJSON').returns({a: 'a', b: 'b'});
   fs.extendJSON(filepath, contents);
   sinon.assert.calledOnce(write);
   sinon.assert.calledWithMatch(write, filepath, JSON.stringify({a: 'a', b: 2}, null, 2) + '\n');
   write.restore();
   read.restore();
 });
Example #4
0
 it("emptys the file state except for parentFolderId", () => {
   const folderId = 123;
   const form = new UploadForm({
     upload: { folders: { folder: { id: folderId } } }
   });
   const ev = { target: {} };
   sinon.stub(form, "setState");
   form.handleFileClick(ev);
   sinon.assert.calledWithMatch(form.setState, {
     file: sinon.match({ parentFolderId: folderId })
   });
 });
Example #5
0
 it('returns the ContentLength', async function() {
   s3Stub.headObject = sinon
     .stub()
     .returns(resolvedPromise({ ContentLength: 123 }));
   const s = new S3Storage({ s3_bucket: 'foo' });
   const len = await s.length('x');
   assert.equal(len, 123);
   sinon.assert.calledWithMatch(s3Stub.headObject, {
     Bucket: 'foo',
     Key: 'x'
   });
 });
Example #6
0
    it("should dispatch an error on bad kinto configuration", () => {
      const collections = collectionsReducer(defaultCollections, {type: null});
      const settings = {server: "http://bad.server/v999"};
      const dispatch = sandbox.spy();
      const getState = () => ({collections, settings});

      actions.select("tasks")(dispatch, getState);

      sinon.assert.calledWithMatch(notifyError,
        {message: "Cannot configure Kinto: Unsupported protocol version: v999" +
                  "; please check your settings."});
    });
Example #7
0
    it("should redirect to home if collection is not configured", () => {
      sandbox.stub(ReduxRouter, "updatePath");
      const collections = collectionsReducer(defaultCollections, {type: null});
      const dispatch = sandbox.spy();
      const getState = () => ({collections, settings});

      actions.select("blah")(dispatch, getState);

      sinon.assert.calledWithMatch(dispatch, {
        type: ReduxRouter.UPDATE_PATH,
        path: ""
      });
    });
Example #8
0
    it('Registers an AdSlot', () => {
      const compProps = {
        dfpNetworkId: '1000',
        adUnit: 'foo/bar/baz',
        slotId: 'testElement1',
        sizes: [[728, 90]],
      };

      ReactTestUtils.renderIntoDocument(<AdSlot {...compProps} />);

      sinon.assert.calledOnce(DFPManager.registerSlot);
      sinon.assert.calledWithMatch(DFPManager.registerSlot, compProps);
    });
Example #9
0
    function () {
      this.stub(mustache, 'render');
      renderer.render([{ file : testFile, html : '<html/>' }], {
        foo : [{ a : 1 }],
        bar : [{ b : 2 }]
      });

      sinon.assert.calledOnce(mustache.render);
      sinon.assert.calledWithMatch(mustache.render, '', {
        foo : [{ a : 1 }],
        bar : [{ b : 2 }]
      });
    }
Example #10
0
 it('returns a Stream object', function() {
   const stream = {};
   s3Stub.getObject = sinon
     .stub()
     .returns({ createReadStream: () => stream });
   const s = new S3Storage({ s3_bucket: 'foo' });
   const result = s.getStream('x');
   assert.equal(result, stream);
   sinon.assert.calledWithMatch(s3Stub.getObject, {
     Bucket: 'foo',
     Key: 'x'
   });
 });
Example #11
0
  it('sets all lists on each item before passing to mustache', function () {
    sandbox.stub(mustache, 'render');
    renderer.render([{ file : testFile, html : '<html/>' }], {
      foo : [{ a : 1 }],
      bar : [{ b : 2 }]
    });

    sinon.assert.calledOnce(mustache.render);
    sinon.assert.calledWithMatch(mustache.render, '', {
      foo : [{ a : 1 }],
      bar : [{ b : 2 }]
    });
  });
Example #12
0
    function () {
      fs.exists.withArgs('some/test.json').yields(true);
      fs.readFile.withArgs('some/test.json').yields(null,
        new Buffer('{"some":"long, wrapped\n    and indented json"}'));
      var spy = sinon.spy();

      fileReader.read('some/test', {}, spy);

      sinon.assert.calledOnce(spy);
      sinon.assert.calledWithMatch(spy, null, {
        some : 'long, wrapped and indented json'
      });
    },
Example #13
0
  'reads and returns parsed markdown in a json object': function () {
    fs.exists.withArgs('some/test.md').yields(true);
    fs.readFile.withArgs('some/test.md').yields(null,
        new Buffer('_markdown_'));
    var spy = sinon.spy();

    fileReader.read('some/test', {}, spy);

    sinon.assert.calledOnce(spy);
    sinon.assert.calledWithMatch(spy, null, {
      md : '<p><em>markdown</em></p>'
    });
  },
Example #14
0
  'igores json in html if not on first line': function () {
    fs.exists.withArgs('some/test.html').yields(true);
    fs.readFile.withArgs('some/test.html').yields(null,
        new Buffer('<pre>\n{\n  "some": "json"\n}\n</pre>'));
    var spy = sinon.spy();

    fileReader.read('some/test', {}, spy);

    sinon.assert.calledOnce(spy);
    sinon.assert.calledWithMatch(spy, null, {
      html : '<pre>\n{\n  "some": "json"\n}\n</pre>'
    });
  }
Example #15
0
  'igores json in markdown if not on first line': function () {
    fs.exists.withArgs('some/test.md').yields(true);
    fs.readFile.withArgs('some/test.md').yields(null,
        new Buffer('\n{\n  "some": "json"\n}\n'));
    var spy = sinon.spy();

    fileReader.read('some/test', {}, spy);

    sinon.assert.calledOnce(spy);
    sinon.assert.calledWithMatch(spy, null, {
      md : '<p>{\n  &quot;some&quot;: &quot;json&quot;\n}</p>'
    });
  },
Example #16
0
    it('uses file stream when reporting', function() {
      var tapReporterSpy = sandbox.spy(require('../../lib/reporters'), 'tap');
      var reporter = new Reporter(mockApp('tap'), process.stdout, 'report.xml');

      expect(reporter.reportFileStream).to.not.be.undefined();
      expect(reporter.reportFileStream).to.not.equal(process.stdout,
          'expected report file stream to not be process.stdout');

      sinon.assert.calledWithMatch(tapReporterSpy,
        sinon.match.any,
        sinon.match.same(reporter.reportFileStream),
        sinon.match.any,
        sinon.match.any);
    });
Example #17
0
 it("embed image on image type and image selected", () => {
   sinon.stub(Bridge, "existingContentToLink", () => {
     return true;
   });
   sinon.stub(Bridge, "existingContentToLinkIsImg", () => {
     return true;
   });
   actions.embedUploadResult({ "content-type": "image/png" }, "images");
   sinon.assert.calledWithMatch(Bridge.insertImage, {
     "content-type": "image/png"
   });
   Bridge.existingContentToLink.restore();
   Bridge.existingContentToLinkIsImg.restore();
 });
Example #18
0
  'reads multiline json at top of html': function () {
    fs.exists.withArgs('some/test.html').yields(true);
    fs.readFile.withArgs('some/test.html').yields(null,
        new Buffer('{\n  "some": "json"\n}\n\n<em>html</em>'));
    var spy = sinon.spy();

    fileReader.read('some/test', {}, spy);

    sinon.assert.calledOnce(spy);
    sinon.assert.calledWithMatch(spy, null, {
      html : '<em>html</em>',
      some : 'json'
    });
  },
Example #19
0
  'reads multiline json at top of markdown': function () {
    fs.exists.withArgs('some/test.md').yields(true);
    fs.readFile.withArgs('some/test.md').yields(null,
        new Buffer('{\n  "some": "json"\n}\n\n_markdown_'));
    var spy = sinon.spy();

    fileReader.read('some/test', {}, spy);

    sinon.assert.calledOnce(spy);
    sinon.assert.calledWithMatch(spy, null, {
      md   : '<p><em>markdown</em></p>',
      some : 'json'
    });
  },
Example #20
0
 it("link image on image type and text selected", () => {
   sinon.stub(Bridge, "existingContentToLink", () => {
     return true;
   });
   sinon.stub(Bridge, "existingContentToLinkIsImg", () => {
     return false;
   });
   actions.embedUploadResult({ "content-type": "image/png" }, "files");
   sinon.assert.calledWithMatch(Bridge.insertLink, {
     embed: { type: "image" }
   });
   Bridge.existingContentToLink.restore();
   Bridge.existingContentToLinkIsImg.restore();
 });
Example #21
0
 .then(() => {
   sinon.assert.called(stubs.signAddon);
   sinon.assert.calledWithMatch(stubs.signAddon, {
     apiKey: stubs.signingConfig.apiKey,
     apiProxy: stubs.signingConfig.apiProxy,
     apiSecret: stubs.signingConfig.apiSecret,
     apiUrlPrefix: stubs.signingConfig.apiUrlPrefix,
     downloadDir: artifactsDir,
     id: applications.gecko.id,
     timeout: stubs.signingConfig.timeout,
     version: stubs.preValidatedManifest.version,
     xpiPath: stubs.buildResult.extensionPath,
   });
 });
Example #22
0
 it('installs instrumentation middleware', function() {
     var app = server.create({
         rootDir: '/some/dir'
     });
     assert.equal(app, mockApp);
     sinon.assert.notCalled(app.post);
     sinon.assert.calledWith(app.use, jsonMiddleware);
     sinon.assert.calledOnce(app.use); 
     app.useIstanbul();
     sinon.assert.calledWith(app.use, instrumentMiddleware);
     sinon.assert.calledWithMatch(makeInstrumentMiddleware, {
         rootDir: '/some/dir'
     });
 });
Example #23
0
      it("should call the onError handler", () => {
        const onError = sandbox.spy();
        const {node} = createFormComponent({schema, onError});

        Simulate.change(node.querySelector("input[type=text]"), {
          target: {value: "short"}
        });

        Simulate.submit(node);

        sinon.assert.calledWithMatch(onError, sinon.match(value => {
          return value.length === 1 &&
                 value[0].message === "does not meet minimum length of 8";
        }));
      });
Example #24
0
  'adds name and path to file object': function () {
    fs.exists.withArgs('some/test.json').yields(true);
    fs.readFile.withArgs('some/test.json').yields(null, new Buffer('{}'));
    var spy = sinon.spy();

    fileReader.read('some/test', {}, spy);

    sinon.assert.calledOnce(spy);
    sinon.assert.calledWithMatch(spy, null, {
      file   : {
        name : 'test',
        path : 'some/test.html'
      }
    });
  },
Example #25
0
    it("should dispatch an error on unconfigured collection", () => {
      const collections = {
        unconfigured: {
          name: "unconfigured",
          synced: false,
        }
      };
      const dispatch = sandbox.spy();
      const getState = () => ({collections, settings});

      actions.select("unconfigured")(dispatch, getState);

      sinon.assert.calledWithMatch(notifyError,
        {message: `The "unconfigured" collection is not configured.`});
    });
Example #26
0
  'allows to define a custom suffix to be used in the path': function () {
    fs.exists.withArgs('some/test.json').yields(true);
    fs.readFile.withArgs('some/test.json').yields(null,
        new Buffer('{"file":{"suffix":"rss"}}'));
    var spy = sinon.spy();

    fileReader.read('some/test', {}, spy);

    sinon.assert.calledOnce(spy);
    sinon.assert.calledWithMatch(spy, null, {
      file   : {
        name : 'test',
        path : 'some/test.rss'
      }
    });
  },
Example #27
0
 it('accepts an optional `match` function which overrides the default', function() {
     var match = function() {};
     var app = server.create({
         rootDir: '/some/dir',
         match: match
     });
     assert.equal(app, mockApp);
     sinon.assert.notCalled(app.post);
     sinon.assert.calledWith(app.use, jsonMiddleware);
     sinon.assert.calledOnce(app.use); 
     app.useIstanbul();
     sinon.assert.calledWith(app.use, instrumentMiddleware);
     sinon.assert.calledWithMatch(makeInstrumentMiddleware, {
         rootDir: '/some/dir',
         match: match
     });
 });
Example #28
0
    it('adds option when create clicked with valid input', () => {
      const spy = sinon.spy();
      const el = mount(
        <AddOptionButton onAdd={spy}/>
      );

      el.find('button#add-option-button').simulate('click');
      el.find('div#add-option-popover .input-section-name').simulate('change', { target: { value: 'test_section' } });
      el.find('div#add-option-popover .input-option-name').simulate('change', { target: { value: 'test_option' } });
      el.find('div#add-option-popover .input-value').simulate('change', { target: { value: 'test_value' } });
      el.find('div#add-option-popover .btn-create').simulate('click');
      sinon.assert.calledWithMatch(spy, {
        sectionName: 'test_section',
        optionName: 'test_option',
        value: 'test_value'
      });
    });
Example #29
0
  'combines json and markdown results': function () {
    fs.exists.withArgs('some/test.json').yields(true);
    fs.exists.withArgs('some/test.md').yields(true);
    fs.readFile.withArgs('some/test.json').yields(null,
        new Buffer('{"some":"json"}'));
    fs.readFile.withArgs('some/test.md').yields(null,
        new Buffer('_markdown_'));
    var spy = sinon.spy();

    fileReader.read('some/test', {}, spy);

    sinon.assert.calledOnce(spy);
    sinon.assert.calledWithMatch(spy, null, {
      some : 'json',
      md   : '<p><em>markdown</em></p>'
    });
  },
Example #30
0
 it("should not dismiss an undismissable message", () => {
   addNotification("Some dismissable message", {
     type: "info",
     autoDismiss: false,
     dismissAfter: 2
   })(dispatch);
   sinon.assert.calledWithMatch(dispatch, {
     type: "NOTIFICATION_ADD",
     notification: {
       id: sinon.match.string,
       message: "Some dismissable message",
       type: "info"
     }
   });
   sandbox.clock.tick(3);
   expect(dispatch.calledOnce).to.be.true;
 });