Skip to content
Snippets Groups Projects
Select Git revision
  • e063c8f9317c0ad4ad0c67312a1aa66ef9bca91c
  • main default protected
  • feat/gnupg
  • next
  • fix/36615b-branch-reuse-no-cache
  • renovate/main-redis-5.x
  • chore/punycode
  • refactor/pin-new-value
  • feat/36219--git-x509-signing
  • feat/structured-logger
  • hotfix/39.264.1
  • feat/skip-dangling
  • gh-readonly-queue/next/pr-36034-7a061c4ca1024a19e2c295d773d9642625d1c2be
  • hotfix/39.238.3
  • refactor/gitlab-auto-approve
  • feat/template-strings
  • gh-readonly-queue/next/pr-35654-137d934242c784e0c45d4b957362214f0eade1d7
  • fix/32307-global-extends-merging
  • fix/32307-global-extends-repositories
  • gh-readonly-queue/next/pr-35009-046ebf7cb84ab859f7fefceb5fa53a54ce9736f8
  • gh-readonly-queue/next/pr-35009-9d5e583b7d7251148ab0d11ee8dd38149618d162
  • 41.43.5
  • 41.43.4
  • 41.43.3
  • 41.43.2
  • 41.43.1
  • 41.43.0
  • 41.42.12
  • 41.42.11
  • 41.42.10
  • 41.42.9
  • 41.42.8
  • 41.42.7
  • 41.42.6
  • 41.42.5
  • 41.42.4
  • 41.42.3
  • 41.42.2
  • 41.42.1
  • 41.42.0
  • 41.41.0
41 results

get-updated.spec.ts

Blame
  • server.spec.js 3.85 KiB
    'use strict'
    
    const { expect } = require('chai')
    const isSvg = require('is-svg')
    const portfinder = require('portfinder')
    const got = require('../got-test-client')
    const { createTestServer } = require('./in-process-server-test-helpers')
    
    describe('The server', function() {
      let server, baseUrl
      before('Start the server', async function() {
        // Fixes https://github.com/badges/shields/issues/2611
        this.timeout(10000)
        const port = await portfinder.getPortPromise()
        server = createTestServer({ port })
        baseUrl = server.baseUrl
        await server.start()
      })
      after('Shut down the server', async function() {
        if (server) {
          await server.stop()
        }
        server = undefined
      })
    
      it('should produce colorscheme badges', async function() {
        const { statusCode, body } = await got(`${baseUrl}:fruit-apple-green.svg`)
        expect(statusCode).to.equal(200)
        expect(body)
          .to.satisfy(isSvg)
          .and.to.include('fruit')
          .and.to.include('apple')
      })
    
      it('should redirect colorscheme PNG badges as configured', async function() {
        const { statusCode, headers } = await got(
          `${baseUrl}:fruit-apple-green.png`,
          {
            followRedirect: false,
          }
        )
        expect(statusCode).to.equal(301)
        expect(headers.location).to.equal(
          'http://raster.example.com/:fruit-apple-green.png'
        )
      })
    
      it('should preserve label case', async function() {
        const { statusCode, body } = await got(`${baseUrl}:fRuiT-apple-green.svg`)
        expect(statusCode).to.equal(200)
        expect(body)
          .to.satisfy(isSvg)
          .and.to.include('fRuiT')
      })
    
      // https://github.com/badges/shields/pull/1319
      it('should not crash with a numeric logo', async function() {
        const { statusCode, body } = await got(
          `${baseUrl}:fruit-apple-green.svg?logo=1`
        )
        expect(statusCode).to.equal(200)
        expect(body)
          .to.satisfy(isSvg)
          .and.to.include('fruit')
          .and.to.include('apple')
      })
    
      it('should not crash with a numeric link', async function() {
        const { statusCode, body } = await got(
          `${baseUrl}:fruit-apple-green.svg?link=1`
        )
        expect(statusCode).to.equal(200)
        expect(body)
          .to.satisfy(isSvg)
          .and.to.include('fruit')
          .and.to.include('apple')
      })
    
      it('should not crash with a boolean link', async function() {
        const { statusCode, body } = await got(
          `${baseUrl}:fruit-apple-green.svg?link=true`
        )
        expect(statusCode).to.equal(200)
        expect(body)
          .to.satisfy(isSvg)
          .and.to.include('fruit')
          .and.to.include('apple')
      })
    
      it('should return the 404 badge for unknown badges', async function() {
        const { statusCode, body } = await got(
          `${baseUrl}this/is/not/a/badge.svg`,
          { throwHttpErrors: false }
        )
        expect(statusCode).to.equal(404)
        expect(body)
          .to.satisfy(isSvg)
          .and.to.include('404')
          .and.to.include('badge not found')
      })
    
      it('should return the 404 html page for rando links', async function() {
        const { statusCode, body } = await got(
          `${baseUrl}this/is/most/definitely/not/a/badge.js`,
          { throwHttpErrors: false }
        )
        expect(statusCode).to.equal(404)
        expect(body).to.include('blood, toil, tears and sweat')
      })
    
      it('should redirect the root as configured', async function() {
        const { statusCode, headers } = await got(baseUrl, {
          followRedirect: false,
        })
    
        expect(statusCode).to.equal(302)
        // This value is set in `config/test.yml`
        expect(headers.location).to.equal('http://badge-server.example.com')
      })
    
      it('should return the 410 badge for obsolete formats', async function() {
        const { statusCode, body } = await got(`${baseUrl}npm/v/express.jpg`, {
          throwHttpErrors: false,
        })
        expect(statusCode).to.equal(404)
        expect(body)
          .to.satisfy(isSvg)
          .and.to.include('410')
          .and.to.include('jpg no longer available')
      })
    })