Example #1
0
describe('WaffleLabel', function() {
  test(WaffleLabel.render, () => {
    given({ count: 'absent' }).expect({ message: 'absent' })
    given({ count: 0, label: 'feature' }).expect({
      message: '0',
      color: '78bdf2',
      label: 'feature',
    })
    given({ count: 1007, color: 'fbca04', label: 'bug' }).expect({
      message: metric(1007),
      color: 'fbca04',
      label: 'bug',
    })
    given({ count: 123, label: 'task' }).expect({
      message: metric(123),
      color: '78bdf2',
      label: 'task',
    })
  })

  test(WaffleLabel.prototype.transform, () => {
    given({ json: [] }).expect({ count: 'absent' })
    given({ json: fakeData, label: 'not-there' }).expect({ count: 0 })
    given({ json: fakeData, label: 'bug' }).expect({
      count: 5,
      color: 'fbca04',
    })
  })
})
Example #2
0
describe('GithubTag', function() {
  const tagFixture = [
    { name: 'cheese' }, // any old string
    { name: 'v1.3-beta3' }, // semver pre-release
    { name: 'v1.2' }, // semver release
  ]

  test(GithubTag.transform, () => {
    given({ json: tagFixture, usingSemver: true, includePre: false }).expect(
      'v1.2'
    )
    given({ json: tagFixture, usingSemver: true, includePre: true }).expect(
      'v1.3-beta3'
    )
    given({ json: tagFixture, usingSemver: false, includePre: false }).expect(
      'cheese'
    )
  })

  test(GithubTag.render, () => {
    given({ usingSemver: false, version: '1.2.3' }).expect({
      message: 'v1.2.3',
      color: 'blue',
    })
    given({ usingSemver: true, version: '2.0.0' }).expect({
      message: 'v2.0.0',
      color: 'blue',
    })
  })
})
Example #3
0
describe('Text PHP version', function() {
  test(minorVersion, () => {
    given('7').expect('7.0')
    given('7.1').expect('7.1')
    given('5.3.3').expect('5.3')
    given('hhvm').expect('')
  })

  test(versionReduction, () => {
    given(['5.3', '5.4', '5.5'], phpReleases).expect('5.3 - 5.5')
    given(['5.4', '5.5', '5.6', '7.0', '7.1'], phpReleases).expect('5.4 - 7.1')
    given(['5.5', '5.6', '7.0', '7.1', '7.2'], phpReleases).expect('>= 5.5')
    given(['5.5', '5.6', '7.1', '7.2'], phpReleases).expect(
      '5.5, 5.6, 7.1, 7.2'
    )
    given(['7.0', '7.1', '7.2'], phpReleases).expect('>= 7')
    given(
      ['5.0', '5.1', '5.2', '5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2'],
      phpReleases
    ).expect('>= 5')
    given(['7.1', '7.2'], phpReleases).expect('>= 7.1')
    given(['7.1'], phpReleases).expect('7.1')
    given(['8.1'], phpReleases).expect('')
    given([]).expect('')
  })
})
Example #4
0
describe('JenkinsBuild', function() {
  test(JenkinsBuild.prototype.transform, () => {
    forCases([
      given({ json: { color: 'red_anime' } }),
      given({ json: { color: 'yellow_anime' } }),
      given({ json: { color: 'blue_anime' } }),
      given({ json: { color: 'green_anime' } }),
      given({ json: { color: 'grey_anime' } }),
      given({ json: { color: 'disabled_anime' } }),
      given({ json: { color: 'aborted_anime' } }),
      given({ json: { color: 'notbuilt_anime' } }),
    ]).expect({
      status: 'building',
    })
    forCases([
      given({ json: { color: 'grey' } }),
      given({ json: { color: 'disabled' } }),
      given({ json: { color: 'aborted' } }),
      given({ json: { color: 'notbuilt' } }),
    ]).expect({
      status: 'not built',
    })
    forCases([
      given({ json: { color: 'blue' } }),
      given({ json: { color: 'green' } }),
    ]).expect({
      status: 'passing',
    })
    given({ json: { color: 'red' } }).expect({ status: 'failing' })
    given({ json: { color: 'yellow' } }).expect({ status: 'unstable' })
  })

  test(JenkinsBuild.render, () => {
    given({ status: 'unstable' }).expect({
      message: 'unstable',
      color: 'yellow',
    })
    given({ status: 'passing' }).expect(
      renderBuildStatusBadge({ status: 'passing' })
    )
    given({ status: 'failing' }).expect(
      renderBuildStatusBadge({ status: 'failing' })
    )
    given({ status: 'building' }).expect(
      renderBuildStatusBadge({ status: 'building' })
    )
    given({ status: 'not built' }).expect(
      renderBuildStatusBadge({ status: 'not built' })
    )
  })
})
Example #5
0
describe('Logo helpers', function() {
  test(svg2base64, () => {
    given('data:image/svg+xml;base64,PHN2ZyB4bWxu').expect(
      'data:image/svg+xml;base64,PHN2ZyB4bWxu'
    )
    given('<svg xmlns="http://www.w3.org/2000/svg"/>').expect(
      'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciLz4='
    )
    given(undefined).expect(undefined)
  })

  test(isDataUri, () => {
    given('data:image/svg+xml;base64,PHN2ZyB4bWxu').expect(true)
    forCases([given('data:foobar'), given('foobar')]).expect(false)
  })
})
Example #6
0
    describe('No named params are declared', function() {
      class ServiceWithZeroNamedParams extends BaseService {
        static get url() {
          return {
            base: 'foo',
            format: '(?:[^/]+)',
          }
        }
      }

      const namedParams = str => {
        const match = ServiceWithZeroNamedParams._regex.exec(str)
        return ServiceWithZeroNamedParams._namedParamsForMatch(match)
      }

      test(namedParams, () => {
        forCases([
          given('/foo/bar.bar.bar.svg'),
          given('/foo/bar.bar.bar.png'),
          given('/foo/bar.bar.bar.gif'),
          given('/foo/bar.bar.bar.jpg'),
          given('/foo/bar.bar.bar.json'),
        ]).expect({})
      })
    })
Example #7
0
describe('Composer version comparison', function() {
  test(compare, () => {
    // composer version scheme ordering
    given('0.9.0', '1.0.0-alpha').expect(-1)
    given('1.0.0-alpha', '1.0.0-alpha2').expect(-1)
    given('1.0.0-alpha2', '1.0.0-beta').expect(-1)
    given('1.0.0-beta', '1.0.0-beta2').expect(-1)
    given('1.0.0-beta2', '1.0.0-RC').expect(-1)
    given('1.0.0-RC', '1.0.0-RC2').expect(-1)
    given('1.0.0-RC2', '1.0.0').expect(-1)
    given('1.0.0', '1.0.0-patch').expect(-1)
    given('1.0.0-patch', '1.0.0-dev').expect(-1)
    given('1.0.0-dev', '1.0.1').expect(-1)
    given('1.0.1', '1.0.x-dev').expect(-1)

    // short versions should compare equal to long versions
    given('1.0.0-p', '1.0.0-patch').expect(0)
    given('1.0.0-a', '1.0.0-alpha').expect(0)
    given('1.0.0-a2', '1.0.0-alpha2').expect(0)
    given('1.0.0-b', '1.0.0-beta').expect(0)
    given('1.0.0-b2', '1.0.0-beta2').expect(0)

    // numeric suffixes
    given('1.0.0-b1', '1.0.0-b2').expect(-1)
    given('1.0.0-b10', '1.0.0-b11').expect(-1)
    given('1.0.0-a1', '1.0.0-a2').expect(-1)
    given('1.0.0-a10', '1.0.0-a11').expect(-1)
    given('1.0.0-RC1', '1.0.0-RC2').expect(-1)
    given('1.0.0-RC10', '1.0.0-RC11').expect(-1)
  })
})
Example #8
0
describe('URL resolver', function() {
  test(resolveUrl, () => {
    forCases([
      given('/foo/bar'),
      given('/foo/bar', '/'),
      given('/foo/bar', '/baz'),
      given('/foo/bar', '/baz/'),
      given('/foo/bar', ''),
      given('/foo/bar', undefined),
    ]).expect('/foo/bar')

    given('foo/bar', '/baz/').expect('/baz/foo/bar')

    forCases([
      given('http://foo/bar'),
      given('bar', 'http://foo/'),
      given('/bar', 'http://foo/'),
    ]).expect('http://foo/bar')

    given('/foo/bar', '/baz', { baz: 'bazinga' }).expect('/foo/bar?baz=bazinga')

    given('/foo/bar?thing=1', undefined, { other: '2' }).expect(
      '/foo/bar?thing=1&other=2'
    )
  })
})
describe('LuaRocks-specific helpers', function() {
  test(compareVersionLists, () => {
    forCases([
      given([1, 2], [1, 2]),
      given([1, 2, 0], [1, 2]),
      given([1, 2], [1, 2, 0, 0]),
      given([-1, -2], [-1, -2, 0, 0]),
      given([], []),
    ]).describe('when given [%s] and [%s]')
      .expect(0)
      .should('should be equal');

    forCases([
      given([1, 2], [2, 1]),
      given([3, 2], [3, 2, 1]),
      given([-3, -2], [3, 2]),
      given([3, 2, -1], [3, 2]),
      given([-1], []),
      given([], [1]),
    ]).describe('when given [%s] and [%s]')
      .expect(-1)
      .should('should be less');

    forCases([
      given([1, 2, 1, 2], [1, 2, 0, 2]),
      given([5, 2, 0, 1], [5, 2]),
      given([-5, 2], [-6, 3, 1]),
      given([1, 2], [1, 2, -1, 1]),
      given([1, 2, 0, -1], [1, 2, -1, 1]),
      given([], [-1, 2]),
      given([1, -1], []),
    ]).describe('when given [%s] and [%s]')
      .expect(1)
      .should('should be greater');
  });

  test(parseVersion, () => {
    given('1.2.3-1').expect([1, 2, 3, 1]);
    given('10.02-3').expect([10, 2, 3]);
    given('3.0rc1-2').expect([3, 0, -1399, 2]);
    given('2.0-alpha').expect([2, 0, -3100]);
    given('2.0-beta').expect([2, 0, -3000]);
    given('2.0-beta5').expect([2, 0, -2995]);
  });
});
Example #10
0
describe('Badge URL functions', function() {
  test(resolveBadgeUrl, () => {
    given('/badge/foo-bar-blue.svg', undefined).expect(
      '/badge/foo-bar-blue.svg'
    )
    given('/badge/foo-bar-blue.svg', 'http://example.com').expect(
      'http://example.com/badge/foo-bar-blue.svg'
    )
  })

  test(resolveBadgeUrlWithLongCache, () => {
    given('/badge/foo-bar-blue.svg', undefined).expect(
      '/badge/foo-bar-blue.svg?maxAge=2592000'
    )
    given('/badge/foo-bar-blue.svg', 'http://example.com').expect(
      'http://example.com/badge/foo-bar-blue.svg?maxAge=2592000'
    )
  })

  test(staticBadgeUrl, () => {
    given('http://img.example.com', 'foo', 'bar', 'blue', {
      style: 'plastic',
    }).expect('http://img.example.com/badge/foo-bar-blue.svg?style=plastic')
  })

  test(dynamicBadgeUrl, () => {
    const dataUrl = 'http://example.com/foo.json'
    const query = '$.bar'
    const prefix = 'value: '

    given('http://img.example.com', 'json', 'foo', dataUrl, query, {
      prefix,
      style: 'plastic',
    }).expect(
      [
        'http://img.example.com/badge/dynamic/json.svg',
        '?label=foo',
        `&url=${encodeURIComponent(dataUrl)}`,
        `&query=${encodeURIComponent(query)}`,
        `&prefix=${encodeURIComponent(prefix)}`,
        '&style=plastic',
      ].join('')
    )
  })
})
Example #11
0
 describe('color aliases', function() {
   test(testColor, () => {
     forCases([
       given('#4c1', 'color'),
       given('#4c1', 'colorB'),
       given('#4c1', 'colorscheme'),
     ]).expect('#4c1')
   })
 })
Example #12
0
describe('Version helpers', function () {
  test(latest, () => {
    // semver-compatible versions.
    given(['1.0.0', '1.0.2', '1.0.1']).expect('1.0.2');
    given(['1.0.0', '2.0.0', '3.0.0']).expect('3.0.0');
    given(['0.0.1', '0.0.10', '0.0.2', '0.0.20']).expect('0.0.20');

    // Simple dotted versions.
    given(['1.0.0', 'v1.0.2', 'r1.0.1', 'release-2.0.0']).expect('release-2.0.0');
    given(['1.0.0', 'v2.0.0', 'r1.0.1', 'release-1.0.3']).expect('v2.0.0');
    given(['2.0.0', 'v1.0.3', 'r1.0.1', 'release-1.0.3']).expect('2.0.0');
    given(['1.0.0', 'v1.0.2', 'r2.0.0', 'release-1.0.3']).expect('r2.0.0');

    // Versions with 'v' prefix.
    given(['0.1', '0.3', '0.2']).expect('0.3');
    given(['0.1', '0.5', '0.12', '0.21']).expect('0.21');
    given(['1.0', '2.0', '3.0']).expect('3.0');

    // Versions with '-release' prefix
    given(['v1.0.0', 'v1.0.2', 'v1.0.1']).expect('v1.0.2');
    given(['v1.0.0', 'v3.0.0', 'v2.0.0']).expect('v3.0.0');

    // Versions with '-release' prefix
    given(['release-1.0.0', 'release-1.0.2', 'release-1.0.20', 'release-1.0.3']).expect('release-1.0.20');

    // Simple (one-number) versions
    given(['2', '10', '1']).expect('10');
  });

  test(slice, () => {
    given('2.4.7', 'major').expect('2');
    given('2.4.7', 'minor').expect('2.4');
    given('2.4.7', 'patch').expect('2.4.7');
    given('2.4.7-alpha.1', 'major').expect('2-alpha.1');
    given('2.4.7-alpha.1', 'minor').expect('2.4-alpha.1');
    given('2.4.7-alpha.1', 'patch').expect('2.4.7-alpha.1');
  });

  test(rangeStart, () => {
    given('^2.4.7').expect('2.4.7');
  });
});
Example #13
0
describe('Service definition helpers', function() {
  test(findCategory, () => {
    given('build').expect({ id: 'build', name: 'Build' })
    given('foo').expect(undefined)
  })

  it('getDefinitionsForCategory', function() {
    expect(getDefinitionsForCategory('build'))
      .to.have.length.greaterThan(10)
      .and.lessThan(50)
  })
})
Example #14
0
describe('SonarQualityGate', function() {
  test(SonarQualityGate.render, () => {
    given({ qualityState: 'OK' }).expect({
      message: 'passed',
      color: 'success',
    })
    given({ qualityState: 'ERROR' }).expect({
      message: 'failed',
      color: 'critical',
    })
  })
})
Example #15
0
describe('license helpers', function() {
  test(licenseToColor, () => {
    forCases([given('MIT'), given('BSD')]).expect('green')
    forCases([given('MPL-2.0'), given('MPL')]).expect('orange')
    forCases([given('Unlicense'), given('CC0')]).expect('7cd958')
    forCases([given('unknown-license'), given(null)]).expect('lightgrey')

    given(['CC0-1.0', 'MPL-2.0']).expect('7cd958')
    given(['MPL-2.0', 'CC0-1.0']).expect('7cd958')
    given(['MIT', 'MPL-2.0']).expect('green')
    given(['MPL-2.0', 'MIT']).expect('green')
    given(['OFL-1.1', 'MPL-2.0']).expect('orange')
    given(['MPL-2.0', 'OFL-1.1']).expect('orange')
    given(['CC0-1.0', 'MIT', 'MPL-2.0']).expect('7cd958')
    given(['UNKNOWN-1.0', 'MIT']).expect('green')
    given(['UNKNOWN-1.0', 'UNKNOWN-2.0']).expect('lightgrey')
  })

  test(renderLicenseBadge, () => {
    forCases([
      given({ license: undefined }),
      given({ licenses: [] }),
      given({}),
    ]).expect({
      message: 'missing',
      color: 'red',
    })
    forCases([
      given({ license: 'WTFPL' }),
      given({ licenses: ['WTFPL'] }),
    ]).expect({
      message: 'WTFPL',
      color: '7cd958',
    })
    given({ licenses: ['MPL-2.0', 'MIT'] }).expect({
      message: 'MPL-2.0, MIT',
      color: 'green',
    })
  })
})
Example #16
0
    context('A named param is declared', function() {
      const regexExec = str => DummyService._regex.exec(str)
      const getNamedParamA = str => {
        const [, namedParamA] = regexExec(str)
        return namedParamA
      }
      const namedParams = str => {
        const match = regexExec(str)
        return DummyService._namedParamsForMatch(match)
      }

      test(regexExec, () => {
        forCases([
          given('/foo/bar.bar.bar.zip'),
          given('/foo/bar/bar.svg'),
        ]).expect(null)
      })

      test(getNamedParamA, () => {
        forCases([
          given('/foo/bar.bar.bar.svg'),
          given('/foo/bar.bar.bar.png'),
          given('/foo/bar.bar.bar.gif'),
          given('/foo/bar.bar.bar.jpg'),
          given('/foo/bar.bar.bar.json'),
        ]).expect('bar.bar.bar')
      })

      test(namedParams, () => {
        forCases([
          given('/foo/bar.bar.bar.svg'),
          given('/foo/bar.bar.bar.png'),
          given('/foo/bar.bar.bar.gif'),
          given('/foo/bar.bar.bar.jpg'),
          given('/foo/bar.bar.bar.json'),
        ]).expect({ namedParamA: 'bar.bar.bar' })
      })
    })
Example #17
0
describe('ContinuousPhp', function() {
  test(ContinuousPhp.render, () => {
    given({ status: 'unstable' }).expect({
      label: 'build',
      message: 'unstable',
      color: 'yellow',
    })
    given({ status: 'running' }).expect({
      label: 'build',
      message: 'running',
      color: 'blue',
    })
  })
})
describe('Pull request inference', function() {
  test(parseGithubPullRequestUrl, () => {
    forCases([
      given('https://github.com/badges/shields/pull/1234'),
      given('https://github.com/badges/shields/pull/1234', { verifyBaseUrl: 'https://github.com' }),
    ]).expect({
      baseUrl: 'https://github.com',
      owner: 'badges',
      repo: 'shields',
      pullRequest: 1234,
      slug: 'badges/shields#1234',
    });

    given('https://github.com/badges/shields/pull/1234', { verifyBaseUrl: 'https://example.com' })
      .expectError('Expected base URL to be https://example.com but got https://github.com');
  });

  test(inferPullRequest, () => {
    const expected = {
      owner: 'badges',
      repo: 'shields',
      pullRequest: 1234,
      slug: 'badges/shields#1234',
    };

    given({
      CIRCLECI: '1',
      CI_PULL_REQUEST: 'https://github.com/badges/shields/pull/1234',
    }).expect(Object.assign({ baseUrl: 'https://github.com' }, expected));

    given({
      TRAVIS: '1',
      TRAVIS_REPO_SLUG: 'badges/shields',
      TRAVIS_PULL_REQUEST: '1234',
    }).expect(expected);
  });
});
Example #19
0
  describe('color test', function() {
    test(testColor, () => {
      // valid hex
      forCases([
        given('#4c1'),
        given('#4C1'),
        given('4C1'),
        given('4c1'),
      ]).expect('#4c1')
      forCases([
        given('#abc123'),
        given('#ABC123'),
        given('abc123'),
        given('ABC123'),
      ]).expect('#abc123')
      // valid rgb(a)
      given('rgb(0,128,255)').expect('rgb(0,128,255)')
      given('rgba(0,128,255,0)').expect('rgba(0,128,255,0)')
      // valid hsl(a)
      given('hsl(100, 56%, 10%)').expect('hsl(100, 56%, 10%)')
      given('hsla(25,20%,0%,0.1)').expect('hsla(25,20%,0%,0.1)')
      // CSS named color.
      given('papayawhip').expect('papayawhip')
      // Shields named color.
      given('red').expect('red')
      given('green').expect('green')
      given('blue').expect('blue')
      given('yellow').expect('yellow')

      forCases(
        // invalid hex
        given('#123red'), // contains letter above F
        given('#red'), // contains letter above F
        // invalid rgb(a)
        given('rgb(220,128,255,0.5)'), // has alpha
        given('rgba(0,0,255)'), // no alpha
        // invalid hsl(a)
        given('hsl(360,50%,50%,0.5)'), // has alpha
        given('hsla(0,50%,101%)'), // no alpha
        // neither a css named color nor colorscheme
        given('notacolor'),
        given('bluish'),
        given('almostred'),
        given('brightmaroon'),
        given('cactus')
      ).expect(undefined)
    })
  })
Example #20
0
  it('should have parity with render()', async function() {
    const nodeVersionRange = '>= 6.0.0'

    const expectedNoTag = await NodeVersion.renderStaticExample({
      nodeVersionRange,
    })
    const expectedLatestTag = await NodeVersion.renderStaticExample({
      nodeVersionRange,
      tag: 'latest',
    })

    test(NodeVersion.renderStaticExample, () => {
      given({ nodeVersionRange }).expect(expectedNoTag)
      given({ nodeVersionRange, tag: 'latest' }).expect(expectedLatestTag)
    })
  })
describe('ScrutinizerCoverage', function() {
  test(ScrutinizerCoverage.render, () => {
    given({ coverage: 39 }).expect({
      message: '39%',
      color: 'red',
    })
    given({ coverage: 40 }).expect({
      message: '40%',
      color: 'yellow',
    })
    given({ coverage: 60 }).expect({
      message: '60%',
      color: 'yellow',
    })
    given({ coverage: 61 }).expect({
      message: '61%',
      color: 'brightgreen',
    })
  })

  context('transform()', function() {
    it('throws NotFound error when there is no coverage data', function() {
      try {
        ScrutinizerCoverage.prototype.transform({
          branch: 'master',
          json: {
            applications: {
              master: {
                index: {
                  _embedded: {
                    project: {
                      metric_values: {},
                    },
                  },
                },
              },
            },
          },
        })
        expect.fail('Expected to throw')
      } catch (e) {
        expect(e).to.be.an.instanceof(NotFound)
        expect(e.prettyMessage).to.equal('coverage not found')
      }
    })
  })
})
Example #22
0
describe('Test result helpers', function() {
  function renderBothStyles(props) {
    const { message: standardMessage, color } = renderTestResultBadge(props)
    const compactMessage = renderTestResultMessage({
      ...props,
      isCompact: true,
    })
    return { standardMessage, compactMessage, color }
  }

  test(renderBothStyles, () => {
    given({ passed: 12, failed: 3, skipped: 3, total: 18 }).expect({
      standardMessage: '12 passed, 3 failed, 3 skipped',
      compactMessage: '✔ 12 | ✘ 3 | ➟ 3',
      color: 'red',
    })
    given({ passed: 12, failed: 3, skipped: 0, total: 15 }).expect({
      standardMessage: '12 passed, 3 failed',
      compactMessage: '✔ 12 | ✘ 3',
      color: 'red',
    })
    given({ passed: 12, failed: 0, skipped: 3, total: 15 }).expect({
      standardMessage: '12 passed, 3 skipped',
      compactMessage: '✔ 12 | ➟ 3',
      color: 'green',
    })
    given({ passed: 0, failed: 0, skipped: 3, total: 3 }).expect({
      standardMessage: '0 passed, 3 skipped',
      compactMessage: '✔ 0 | ➟ 3',
      color: 'yellow',
    })
    given({ passed: 12, failed: 0, skipped: 0, total: 12 }).expect({
      standardMessage: '12 passed',
      compactMessage: '✔ 12',
      color: 'brightgreen',
    })
    given({ passed: 0, failed: 0, skipped: 0, total: 0 }).expect({
      standardMessage: 'no tests',
      compactMessage: 'no tests',
      color: 'yellow',
    })
  })
})
Example #23
0
describe('Website status helpers', function() {
  const customOptions = {
    upMessage: 'groovy',
    upColor: 'papayawhip',
    downMessage: 'no good',
    downColor: 'gray',
  }

  test(renderWebsiteStatus, () => {
    given({ isUp: true }).expect({ message: 'up', color: 'brightgreen' })
    given({ isUp: false }).expect({ message: 'down', color: 'red' })
    given({ isUp: true, ...customOptions }).expect({
      message: 'groovy',
      color: 'papayawhip',
    })
    given({ isUp: false, ...customOptions }).expect({
      message: 'no good',
      color: 'gray',
    })
  })
})
describe('Badge example functions', function() {
  const exampleMatchesQuery = (example, query) =>
    predicateFromQuery(query)(example)

  test(exampleMatchesQuery, () => {
    forCases([given({ examples: [{ title: 'node version' }] }, 'npm')]).expect(
      false
    )

    forCases([
      given(
        { examples: [{ title: 'node version', keywords: ['npm'] }] },
        'node'
      ),
      given(
        { examples: [{ title: 'node version', keywords: ['npm'] }] },
        'npm'
      ),
      // https://github.com/badges/shields/issues/1578
      given({ examples: [{ title: 'c++ is the best language' }] }, 'c++'),
    ]).expect(true)
  })
})
describe('GithubIssueDetail', function() {
  test(GithubIssueDetail.render, () => {
    given({
      which: 'state',
      value: { state: 'open' },
      number: '12',
      isPR: true,
    }).expect({
      label: 'pull request 12',
      message: 'open',
      color: stateColor('open'),
    })
    given({
      which: 'state',
      value: { state: 'closed' },
      number: '15',
      isPR: false,
    }).expect({
      label: 'issue 15',
      message: 'closed',
      color: stateColor('closed'),
    })
    given({
      which: 'title',
      value: 'refactor [FooService]',
      number: '232',
      isPR: true,
    }).expect({
      label: 'pull request 232',
      message: 'refactor [FooService]',
    })
    given({
      which: 'title',
      value: 'Packagist: invalid response data',
      number: '345',
      isPR: false,
    }).expect({
      label: 'issue 345',
      message: 'Packagist: invalid response data',
    })
    given({
      which: 'author',
      value: 'calebcartwright',
    }).expect({
      label: 'author',
      message: 'calebcartwright',
    })
    given({
      which: 'label',
      value: { names: ['feature'], colors: ['a2eeef'] },
    }).expect({
      color: 'a2eeef',
      message: 'feature',
      label: 'label',
    })
    given({
      which: 'label',
      value: { names: ['service-badge', 'bug'], colors: ['a2eeef', 'ee0701'] },
    }).expect({
      color: undefined,
      message: 'service-badge | bug',
      label: 'label',
    })
    given({ which: 'comments', value: 27 }).expect({
      label: 'comments',
      message: metric(27),
      color: commentsColor('closed'),
    })
    given({
      which: 'age',
      value: '2019-04-01T20:09:31Z',
    }).expect({
      label: 'created',
      message: formatDate('2019-04-01T20:09:31Z'),
      color: age('2019-04-01T20:09:31Z'),
    })
    given({
      which: 'last-update',
      value: '2019-04-02T20:09:31Z',
    }).expect({
      label: 'updated',
      message: formatDate('2019-04-02T20:09:31Z'),
      color: age('2019-04-02T20:09:31Z'),
    })
  })

  test(GithubIssueDetail.prototype.transform, () => {
    given({
      which: 'state',
      json: { state: 'closed' },
    }).expect({
      // Since it's a PR, the "merged" value is not crucial here.
      value: { state: 'closed', merged: true },
      isPR: false,
    })
    given({
      which: 'state',
      kind: 'pulls',
      json: { state: 'closed', merged_at: null },
    }).expect({
      value: { state: 'closed', merged: false },
      isPR: true,
    })
    given({
      which: 'state',
      kind: 'pulls',
      json: { state: 'closed', merged_at: 'I am not null' },
    }).expect({
      value: { state: 'closed', merged: true },
      isPR: true,
    })
    given({
      which: 'title',
      json: { pull_request: {}, title: 'refactor [Codecov]' },
    }).expect({
      value: 'refactor [Codecov]',
      isPR: true,
    })
    given({
      which: 'author',
      json: { user: { login: '******' } },
    }).expect({
      value: 'dependabot',
      isPR: false,
    })
    given({
      which: 'label',
      json: {
        pull_request: {},
        labels: [
          { name: 'service-badge', color: 'a2eeef' },
          { name: 'bug', color: 'ee0701' },
        ],
      },
    }).expect({
      value: {
        names: ['service-badge', 'bug'],
        colors: ['a2eeef', 'ee0701'],
      },
      isPR: true,
    })
    given({
      which: 'label',
      json: { labels: [{ name: 'bug', color: 'ee0701' }] },
    }).expect({
      value: {
        names: ['bug'],
        colors: ['ee0701'],
      },
      isPR: false,
    })
    given({
      which: 'comments',
      json: { comments: 100 },
    }).expect({
      value: 100,
      isPR: false,
    })
    given({
      which: 'age',
      json: { created_at: '2019-04-01T20:09:31Z' },
    }).expect({
      value: '2019-04-01T20:09:31Z',
      isPR: false,
    })
    given({
      which: 'last-update',
      json: { updated_at: '2019-04-02T20:09:31Z' },
    }).expect({
      value: '2019-04-02T20:09:31Z',
      isPR: false,
    })
  })

  context('transform()', function() {
    it('throws InvalidResponse error when issue has no labels', function() {
      try {
        GithubIssueDetail.prototype.transform({
          which: 'label',
          json: { labels: [] },
        })
        expect.fail('Expected to throw')
      } catch (e) {
        expect(e).to.be.an.instanceof(InvalidResponse)
        expect(e.prettyMessage).to.equal('no labels found')
      }
    })
  })
})
import { test, given } from 'sazerac'
import generateAllMarkup, {
  markdown,
  reStructuredText,
  asciiDoc,
} from './generate-image-markup'

test(markdown, () => {
  given('https://img.shields.io/badge.svg', undefined, 'Example').expect(
    '![Example](https://img.shields.io/badge.svg)'
  )
  given(
    'https://img.shields.io/badge.svg',
    'https://example.com/example',
    'Example'
  ).expect(
    '[![Example](https://img.shields.io/badge.svg)](https://example.com/example)'
  )
})

test(reStructuredText, () => {
  given('https://img.shields.io/badge.svg', undefined, 'Example').expect(
    '.. image:: https://img.shields.io/badge.svg   :alt: Example'
  )
  given(
    'https://img.shields.io/badge.svg',
    'https://example.com/example',
    'Example'
  ).expect(
    '.. image:: https://img.shields.io/badge.svg   :alt: Example   :target: https://example.com/example'
  )
Example #27
0
describe('Logo helpers', function() {
  test(prependPrefix, () => {
    given('data:image/svg+xml;base64,PHN2ZyB4bWxu', 'data:').expect(
      'data:image/svg+xml;base64,PHN2ZyB4bWxu'
    )
    given('foobar', 'data:').expect('data:foobar')
    given(undefined, 'data:').expect(undefined)
  })

  test(isDataUrl, () => {
    given('data:image/svg+xml;base64,PHN2ZyB4bWxu').expect(true)
    forCases([given('data:foobar'), given('foobar')]).expect(false)
  })

  test(prepareNamedLogo, () => {
    // NPM uses multiple colors so the color param should be ignored
    const npmLogo =
      'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MCA0MCI+PHBhdGggZD0iTTAgMGg0MHY0MEgwVjB6IiBmaWxsPSIjY2IwMDAwIi8+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTcgN2gyNnYyNmgtN1YxNGgtNnYxOUg3eiIvPjwvc3ZnPgo='
    given({ name: 'npm' }).expect(npmLogo)
    given({ name: 'npm', color: 'blue' }).expect(npmLogo)

    // dependabot only uses one color so the color param should be respected
    given({ name: 'dependabot' }).expect(
      'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDov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areNamedLogo({ name: 'javascript' })
      const decodedLogo = Buffer.from(
        logo.replace('data:image/svg+xml;base64,', ''),
        'base64'
      ).toString('ascii')
      expect(decodedLogo).to.contain('fill="#F7DF1E"')
    })
    it('recolors logo if light logo on light background', function() {
      const logo = prepareNamedLogo({ name: 'javascript', style: 'social' })
      const decodedLogo = Buffer.from(
        logo.replace('data:image/svg+xml;base64,', ''),
        'base64'
      ).toString('ascii')
      expect(decodedLogo).to.contain('fill="#333"')
    })

    it('preserves color if dark logo on light background', function() {
      const logo = prepareNamedLogo({ name: 'nuget', style: 'social' })
      const decodedLogo = Buffer.from(
        logo.replace('data:image/svg+xml;base64,', ''),
        'base64'
      ).toString('ascii')
      expect(decodedLogo).to.contain('fill="#004880"')
    })
    it('recolors logo if dark logo on dark background', function() {
      const logo = prepareNamedLogo({ name: 'nuget' })
      const decodedLogo = Buffer.from(
        logo.replace('data:image/svg+xml;base64,', ''),
        'base64'
      ).toString('ascii')
      expect(decodedLogo).to.contain('fill="whitesmoke"')
    })

    it('preserves color if medium logo on dark background', function() {
      const logo = prepareNamedLogo({ name: 'skype' })
      const decodedLogo = Buffer.from(
        logo.replace('data:image/svg+xml;base64,', ''),
        'base64'
      ).toString('ascii')
      expect(decodedLogo).to.contain('fill="#00AFF0"')
    })
    it('preserves color if medium logo on light background', function() {
      const logo = prepareNamedLogo({ name: 'skype', style: 'social' })
      const decodedLogo = Buffer.from(
        logo.replace('data:image/svg+xml;base64,', ''),
        'base64'
      ).toString('ascii')
      expect(decodedLogo).to.contain('fill="#00AFF0"')
    })
  })

  test(makeLogo, () => {
    forCases([
      given('npm', { logo: 'image/svg+xml;base64,PHN2ZyB4bWxu' }),
      given('npm', { logo: 'data:image/svg+xml;base64,PHN2ZyB4bWxu' }),
      given('npm', { logo: 'data:image/svg xml;base64,PHN2ZyB4bWxu' }),
      given('npm', { logo: 'data:image/svg+xml;base64,PHN2ZyB\n4bWxu' }),
    ]).expect('data:image/svg+xml;base64,PHN2ZyB4bWxu')
    forCases([given('npm', { logo: '' }), given(undefined, {})]).expect(
      undefined
    )
    given('npm', {}).expect(
      'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MCA0MCI+PHBhdGggZD0iTTAgMGg0MHY0MEgwVjB6IiBmaWxsPSIjY2IwMDAwIi8+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTcgN2gyNnYyNmgtN1YxNGgtNnYxOUg3eiIvPjwvc3ZnPgo='
    )
  })
})
Example #28
0
describe('Badge data helpers', function() {
  test(hasPrefix, () => {
    forCases([
      given('data:image/svg+xml;base64,PHN2ZyB4bWxu', 'data:'),
      given('data:foobar', 'data:'),
    ]).expect(true);
    given('foobar', 'data:').expect(false);
  });

  test(isDataUri, () => {
    given('data:image/svg+xml;base64,PHN2ZyB4bWxu').expect(true);
    forCases([
      given('data:foobar'),
      given('foobar'),
    ]).expect(false);
  });

  test(isSixHex, () => {
    given('f00bae').expect(true);
    forCases([
      given('f00bar'),
      given(''),
      given(undefined),
    ]).expect(false);
  });

  test(makeLabel, () => {
    given('my badge', {}).expect('my badge');
    given('my badge', { label: 'no, my badge' }).expect('no, my badge');
  });

  test(makeLogo, () => {
    forCases([
      given('gratipay', { logo: 'image/svg+xml;base64,PHN2ZyB4bWxu' }),
      given('gratipay', { logo: 'data:image/svg+xml;base64,PHN2ZyB4bWxu' }),
    ]).expect('data:image/svg+xml;base64,PHN2ZyB4bWxu');
    forCases([
      given('gratipay', { logo: '' }),
      given(undefined, {}),
    ]).expect(undefined);
    given('gratipay', {}).assert('should be truthy', assert.ok);
  });

  test(makeBadgeData, () => {
    given('my badge', {
      label: 'no, my badge',
      style: 'flat-square',
      logo: 'image/svg+xml;base64,PHN2ZyB4bWxu',
      logoWidth: '25',
      link: 'https://example.com/',
      colorA: 'blue',
      colorB: 'f00bae',
    }).expect({
      text: ['no, my badge', 'n/a'],
      colorscheme: 'lightgrey',
      template: 'flat-square',
      logo: 'data:image/svg+xml;base64,PHN2ZyB4bWxu',
      logoWidth: 25,
      links: ['https://example.com/'],
      colorA: 'blue',
      colorB: '#f00bae',
    });
  });

  test(setBadgeColor, () => {
    given({}, 'red').expect({ colorscheme: 'red' });
    given({}, 'f00f00').expect({ colorB: '#f00f00' });
    given({ colorB: '#f00f00', colorscheme: 'blue' }, 'red').expect({ colorscheme: 'red' });
    given({ colorB: '#b00b00', colorscheme: 'blue' }, 'f00f00').expect({ colorB: '#f00f00' });
  });
});