Exemplo n.º 1
0
  function fetch () {
    console.log('Fetching "' + fixture.url + '"...')

    return popsicle.request({
      url: fixture.url,
      options: {
        jar: popsicle.jar()
      }
    })
      .then(function (res) {
        return mkdir(dir)
          .then(function () {
            console.log('Writing "' + fixture.name + '"...')

            const meta = {
              url: res.url,
              headers: res.headers,
              status: res.status,
              statusText: res.statusText
            }

            return Promise.all([
              writeFile(join(dir, 'meta.json'), JSON.stringify(meta, null, 2)),
              writeFile(join(dir, 'body'), res.body)
            ])
          })
      })
  }
Exemplo n.º 2
0
        it('should authenticate', function () {
          var url = localOAuth2.token.getUri()
          var jar = popsicle.jar()

          return popsicle.default({
            url: url,
            options: {
              jar: jar
            }
          })
            .then(function (res) {
              return popsicle.post({
                url: url,
                body: res.body,
                options: {
                  jar: jar,
                  followRedirects: false
                }
              })
            })
            .then(function (res) {
              expect(res.status).to.equal(302)

              return localOAuth2.token.getToken(res.get('Location'))
            })
            .then(function (user) {
              return user.request({ url: server.url('/secured/oauth2') })
            })
            .then(expectHelloWorld)
        })
Exemplo n.º 3
0
    it('scrapeHtml(html, rules)', () => {
      const url = 'http://www.nytimes.com/2016/05/25/us/politics/republican-primary-schedule.html'
      const request = popsicle.request({
        url,
        options: { jar: popsicle.jar() }
      })

      return request.then((res) => {
        const html = res.body
        return Metascraper.scrapeHtml(html).then((metadata) => {
          assert.deepEqual(metadata, {
            author: 'Jeremy W. Peters',
            date: '2016-05-24T00:00:00.000Z',
            description: 'Iowa and New Hampshire could lose their coveted status as gatekeepers to the presidency, and independents could be barred from voting in Republican contests.',
            image: 'https://static01.nyt.com/images/2016/05/25/us/25PRIMARYweb/25PRIMARYweb-facebookJumbo.jpg',
            publisher: 'NYTimes',
            title: 'Reeling From 2016 Chaos, G.O.P. Mulls Overhaul of Primaries',
            url: 'http://www.nytimes.com/2016/05/25/us/politics/republican-primary-schedule.html',
          })
        })
      })
    })