Skip to content
Snippets Groups Projects
Select Git revision
  • 50eee211dd38f84e8bb2e0449bddf6917c51e5e6
  • main default protected
  • release-0.14
  • 14-env
  • fix-version-3
  • automated-updates-fix-action
  • release-0.15
  • automated-updates-main
  • release-0.13
  • automated-updates-release-0.13
  • release-0.10
  • release-0.11
  • release-0.12
  • fix-versions-action
  • versions-fix
  • release-0.9
  • release-0.8
  • release-0.7
  • release-0.6
  • release-0.5
  • release-0.4
  • v0.15.0
  • v0.14.0
  • v0.13.0
  • v0.12.0
  • v0.11.0
  • v0.10.0
  • v0.9.0
  • v0.8.0
  • v0.7.0
  • v0.6.0
  • v0.5.0
  • v0.4.0
  • v0.3.0
  • v0.2.0
  • v0.1.0
36 results

tools.go

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')
      })
    })