mirror of
https://github.com/badges/shields.git
synced 2025-04-18 19:44:04 +03:00
Migrate from CommonJS to ESM (#6651)
This commit is contained in:
parent
23678fe2f5
commit
23c0406bed
@ -236,7 +236,7 @@ jobs:
|
||||
|
||||
e2e:
|
||||
docker:
|
||||
- image: cypress/base:14
|
||||
- image: cypress/base:14.16.0
|
||||
steps:
|
||||
- checkout
|
||||
|
||||
|
@ -2,6 +2,6 @@
|
||||
/build
|
||||
/coverage
|
||||
/__snapshots__
|
||||
/public
|
||||
public
|
||||
badge-maker/node_modules/
|
||||
!.github/
|
||||
|
@ -136,7 +136,6 @@ rules:
|
||||
# Shields additions.
|
||||
no-var: 'error'
|
||||
prefer-const: 'error'
|
||||
strict: 'error'
|
||||
arrow-body-style: ['error', 'as-needed']
|
||||
no-extension-in-require/main: 'error'
|
||||
object-shorthand: ['error', 'properties']
|
||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -104,7 +104,8 @@ service-definitions.yml
|
||||
!/config/local*.template.yml
|
||||
|
||||
# Gatsby
|
||||
/.cache
|
||||
/frontend/.cache
|
||||
/frontend/public
|
||||
/public
|
||||
|
||||
# Cypress
|
||||
|
@ -3,4 +3,3 @@ require:
|
||||
- '@babel/polyfill'
|
||||
- '@babel/register'
|
||||
- mocha-yaml-loader
|
||||
- frontend/mocha-ignore-pngs
|
||||
|
@ -2,10 +2,10 @@ package.json
|
||||
package-lock.json
|
||||
/__snapshots__
|
||||
/.next
|
||||
/.cache
|
||||
.cache
|
||||
/api-docs
|
||||
/build
|
||||
/public
|
||||
public
|
||||
/coverage
|
||||
private/*.json
|
||||
/.nyc_output
|
||||
|
@ -1,8 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
const { URL } = require('url')
|
||||
const queryString = require('query-string')
|
||||
const { compile } = require('path-to-regexp')
|
||||
// Avoid "Attempted import error: 'URL' is not exported from 'url'" in frontend.
|
||||
import url from 'url'
|
||||
import queryString from 'query-string'
|
||||
import { compile } from 'path-to-regexp'
|
||||
|
||||
function badgeUrlFromPath({
|
||||
baseUrl = '',
|
||||
@ -147,13 +146,13 @@ function dynamicBadgeUrl({
|
||||
function rasterRedirectUrl({ rasterUrl }, badgeUrl) {
|
||||
// Ensure we're always using the `rasterUrl` by using just the path from
|
||||
// the request URL.
|
||||
const { pathname, search } = new URL(badgeUrl, 'https://bogus.test')
|
||||
const result = new URL(pathname, rasterUrl)
|
||||
const { pathname, search } = new url.URL(badgeUrl, 'https://bogus.test')
|
||||
const result = new url.URL(pathname, rasterUrl)
|
||||
result.search = search
|
||||
return result
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export {
|
||||
badgeUrlFromPath,
|
||||
badgeUrlFromPattern,
|
||||
encodeField,
|
||||
|
@ -1,14 +1,12 @@
|
||||
'use strict'
|
||||
|
||||
const { test, given } = require('sazerac')
|
||||
const {
|
||||
import { test, given } from 'sazerac'
|
||||
import {
|
||||
badgeUrlFromPath,
|
||||
badgeUrlFromPattern,
|
||||
encodeField,
|
||||
staticBadgeUrl,
|
||||
queryStringStaticBadgeUrl,
|
||||
dynamicBadgeUrl,
|
||||
} = require('./make-badge-url')
|
||||
} from './make-badge-url.js'
|
||||
|
||||
describe('Badge URL generation functions', function () {
|
||||
test(badgeUrlFromPath, () => {
|
||||
|
@ -1,5 +1,3 @@
|
||||
'use strict'
|
||||
|
||||
// Escapes `t` using the format specified in
|
||||
// <https://github.com/espadrine/gh-badges/issues/12#issuecomment-31518129>
|
||||
function escapeFormat(t) {
|
||||
@ -13,6 +11,4 @@ function escapeFormat(t) {
|
||||
)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
escapeFormat,
|
||||
}
|
||||
export { escapeFormat }
|
||||
|
@ -1,7 +1,5 @@
|
||||
'use strict'
|
||||
|
||||
const { test, given } = require('sazerac')
|
||||
const { escapeFormat } = require('./path-helpers')
|
||||
import { test, given } from 'sazerac'
|
||||
import { escapeFormat } from './path-helpers.js'
|
||||
|
||||
describe('Badge URL helper functions', function () {
|
||||
test(escapeFormat, () => {
|
||||
|
@ -1,7 +1,5 @@
|
||||
'use strict'
|
||||
|
||||
const { URL } = require('url')
|
||||
const { InvalidParameter } = require('./errors')
|
||||
import { URL } from 'url'
|
||||
import { InvalidParameter } from './errors.js'
|
||||
|
||||
class AuthHelper {
|
||||
constructor(
|
||||
@ -207,4 +205,4 @@ class AuthHelper {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { AuthHelper }
|
||||
export { AuthHelper }
|
||||
|
@ -1,9 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
const { expect } = require('chai')
|
||||
const { test, given, forCases } = require('sazerac')
|
||||
const { AuthHelper } = require('./auth-helper')
|
||||
const { InvalidParameter } = require('./errors')
|
||||
import { expect } from 'chai'
|
||||
import { test, given, forCases } from 'sazerac'
|
||||
import { AuthHelper } from './auth-helper.js'
|
||||
import { InvalidParameter } from './errors.js'
|
||||
|
||||
describe('AuthHelper', function () {
|
||||
describe('constructor checks', function () {
|
||||
|
@ -2,12 +2,10 @@
|
||||
* @module
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
const { print } = require('graphql/language/printer')
|
||||
const BaseService = require('./base')
|
||||
const { InvalidResponse, ShieldsRuntimeError } = require('./errors')
|
||||
const { parseJson } = require('./json')
|
||||
import { print } from 'graphql/language/printer.js'
|
||||
import BaseService from './base.js'
|
||||
import { InvalidResponse, ShieldsRuntimeError } from './errors.js'
|
||||
import { parseJson } from './json.js'
|
||||
|
||||
function defaultTransformErrors(errors) {
|
||||
return new InvalidResponse({ prettyMessage: errors[0].message })
|
||||
@ -93,4 +91,4 @@ class BaseGraphqlService extends BaseService {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BaseGraphqlService
|
||||
export default BaseGraphqlService
|
||||
|
@ -1,11 +1,9 @@
|
||||
'use strict'
|
||||
|
||||
const Joi = require('joi')
|
||||
const { expect } = require('chai')
|
||||
const gql = require('graphql-tag')
|
||||
const sinon = require('sinon')
|
||||
const BaseGraphqlService = require('./base-graphql')
|
||||
const { InvalidResponse } = require('./errors')
|
||||
import Joi from 'joi'
|
||||
import { expect } from 'chai'
|
||||
import gql from 'graphql-tag'
|
||||
import sinon from 'sinon'
|
||||
import BaseGraphqlService from './base-graphql.js'
|
||||
import { InvalidResponse } from './errors.js'
|
||||
|
||||
const dummySchema = Joi.object({
|
||||
requiredString: Joi.string().required(),
|
||||
|
@ -2,10 +2,8 @@
|
||||
* @module
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
const BaseService = require('./base')
|
||||
const { parseJson } = require('./json')
|
||||
import BaseService from './base.js'
|
||||
import { parseJson } from './json.js'
|
||||
|
||||
/**
|
||||
* Services which query a JSON endpoint should extend BaseJsonService
|
||||
@ -54,4 +52,4 @@ class BaseJsonService extends BaseService {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BaseJsonService
|
||||
export default BaseJsonService
|
||||
|
@ -1,9 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
const Joi = require('joi')
|
||||
const { expect } = require('chai')
|
||||
const sinon = require('sinon')
|
||||
const BaseJsonService = require('./base-json')
|
||||
import Joi from 'joi'
|
||||
import { expect } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import BaseJsonService from './base-json.js'
|
||||
|
||||
const dummySchema = Joi.object({
|
||||
requiredString: Joi.string().required(),
|
||||
|
@ -1,17 +1,15 @@
|
||||
'use strict'
|
||||
|
||||
const makeBadge = require('../../badge-maker/lib/make-badge')
|
||||
const BaseService = require('./base')
|
||||
const {
|
||||
import makeBadge from '../../badge-maker/lib/make-badge.js'
|
||||
import BaseService from './base.js'
|
||||
import {
|
||||
serverHasBeenUpSinceResourceCached,
|
||||
setCacheHeadersForStaticResource,
|
||||
} = require('./cache-headers')
|
||||
const { makeSend } = require('./legacy-result-sender')
|
||||
const { MetricHelper } = require('./metric-helper')
|
||||
const coalesceBadge = require('./coalesce-badge')
|
||||
const { prepareRoute, namedParamsForMatch } = require('./route')
|
||||
} from './cache-headers.js'
|
||||
import { makeSend } from './legacy-result-sender.js'
|
||||
import { MetricHelper } from './metric-helper.js'
|
||||
import coalesceBadge from './coalesce-badge.js'
|
||||
import { prepareRoute, namedParamsForMatch } from './route.js'
|
||||
|
||||
module.exports = class BaseStaticService extends BaseService {
|
||||
export default class BaseStaticService extends BaseService {
|
||||
static register({ camp, metricInstance }, serviceConfig) {
|
||||
const { regex, captureNames } = prepareRoute(this.route)
|
||||
|
||||
|
@ -2,13 +2,11 @@
|
||||
* @module
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
// See available emoji at http://emoji.muan.co/
|
||||
const emojic = require('emojic')
|
||||
const BaseService = require('./base')
|
||||
const trace = require('./trace')
|
||||
const { InvalidResponse } = require('./errors')
|
||||
import emojic from 'emojic'
|
||||
import BaseService from './base.js'
|
||||
import trace from './trace.js'
|
||||
import { InvalidResponse } from './errors.js'
|
||||
|
||||
const defaultValueMatcher = />([^<>]+)<\/text><\/g>/
|
||||
const leadingWhitespace = /(?:\r\n\s*|\r\s*|\n\s*)/g
|
||||
@ -90,4 +88,4 @@ class BaseSvgScrapingService extends BaseService {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BaseSvgScrapingService
|
||||
export default BaseSvgScrapingService
|
||||
|
@ -1,10 +1,8 @@
|
||||
'use strict'
|
||||
|
||||
const { expect } = require('chai')
|
||||
const sinon = require('sinon')
|
||||
const Joi = require('joi')
|
||||
const makeBadge = require('../../badge-maker/lib/make-badge')
|
||||
const BaseSvgScrapingService = require('./base-svg-scraping')
|
||||
import { expect } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import Joi from 'joi'
|
||||
import makeBadge from '../../badge-maker/lib/make-badge.js'
|
||||
import BaseSvgScrapingService from './base-svg-scraping.js'
|
||||
|
||||
const schema = Joi.object({
|
||||
message: Joi.string().required(),
|
||||
|
@ -2,14 +2,12 @@
|
||||
* @module
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
// See available emoji at http://emoji.muan.co/
|
||||
const emojic = require('emojic')
|
||||
const fastXmlParser = require('fast-xml-parser')
|
||||
const BaseService = require('./base')
|
||||
const trace = require('./trace')
|
||||
const { InvalidResponse } = require('./errors')
|
||||
import emojic from 'emojic'
|
||||
import fastXmlParser from 'fast-xml-parser'
|
||||
import BaseService from './base.js'
|
||||
import trace from './trace.js'
|
||||
import { InvalidResponse } from './errors.js'
|
||||
|
||||
/**
|
||||
* Services which query a XML endpoint should extend BaseXmlService
|
||||
@ -68,4 +66,4 @@ class BaseXmlService extends BaseService {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BaseXmlService
|
||||
export default BaseXmlService
|
||||
|
@ -1,9 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
const Joi = require('joi')
|
||||
const { expect } = require('chai')
|
||||
const sinon = require('sinon')
|
||||
const BaseXmlService = require('./base-xml')
|
||||
import Joi from 'joi'
|
||||
import { expect } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import BaseXmlService from './base-xml.js'
|
||||
|
||||
const dummySchema = Joi.object({
|
||||
requiredString: Joi.string().required(),
|
||||
|
@ -2,13 +2,11 @@
|
||||
* @module
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
const emojic = require('emojic')
|
||||
const yaml = require('js-yaml')
|
||||
const BaseService = require('./base')
|
||||
const { InvalidResponse } = require('./errors')
|
||||
const trace = require('./trace')
|
||||
import emojic from 'emojic'
|
||||
import yaml from 'js-yaml'
|
||||
import BaseService from './base.js'
|
||||
import { InvalidResponse } from './errors.js'
|
||||
import trace from './trace.js'
|
||||
|
||||
/**
|
||||
* Services which query a YAML endpoint should extend BaseYamlService
|
||||
@ -72,4 +70,4 @@ class BaseYamlService extends BaseService {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BaseYamlService
|
||||
export default BaseYamlService
|
||||
|
@ -1,9 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
const Joi = require('joi')
|
||||
const { expect } = require('chai')
|
||||
const sinon = require('sinon')
|
||||
const BaseYamlService = require('./base-yaml')
|
||||
import Joi from 'joi'
|
||||
import { expect } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import BaseYamlService from './base-yaml.js'
|
||||
|
||||
const dummySchema = Joi.object({
|
||||
requiredString: Joi.string().required(),
|
||||
|
@ -1,36 +1,35 @@
|
||||
'use strict'
|
||||
/**
|
||||
* @module
|
||||
*/
|
||||
|
||||
// See available emoji at http://emoji.muan.co/
|
||||
const emojic = require('emojic')
|
||||
const Joi = require('joi')
|
||||
const log = require('../server/log')
|
||||
const { AuthHelper } = require('./auth-helper')
|
||||
const { MetricHelper, MetricNames } = require('./metric-helper')
|
||||
const { assertValidCategory } = require('./categories')
|
||||
const checkErrorResponse = require('./check-error-response')
|
||||
const coalesceBadge = require('./coalesce-badge')
|
||||
const {
|
||||
import emojic from 'emojic'
|
||||
import Joi from 'joi'
|
||||
import log from '../server/log.js'
|
||||
import { AuthHelper } from './auth-helper.js'
|
||||
import { MetricHelper, MetricNames } from './metric-helper.js'
|
||||
import { assertValidCategory } from './categories.js'
|
||||
import checkErrorResponse from './check-error-response.js'
|
||||
import coalesceBadge from './coalesce-badge.js'
|
||||
import {
|
||||
NotFound,
|
||||
InvalidResponse,
|
||||
Inaccessible,
|
||||
ImproperlyConfigured,
|
||||
InvalidParameter,
|
||||
Deprecated,
|
||||
} = require('./errors')
|
||||
const { validateExample, transformExample } = require('./examples')
|
||||
const {
|
||||
} from './errors.js'
|
||||
import { validateExample, transformExample } from './examples.js'
|
||||
import {
|
||||
makeFullUrl,
|
||||
assertValidRoute,
|
||||
prepareRoute,
|
||||
namedParamsForMatch,
|
||||
getQueryParamNames,
|
||||
} = require('./route')
|
||||
const { assertValidServiceDefinition } = require('./service-definitions')
|
||||
const trace = require('./trace')
|
||||
const validate = require('./validate')
|
||||
} from './route.js'
|
||||
import { assertValidServiceDefinition } from './service-definitions.js'
|
||||
import trace from './trace.js'
|
||||
import validate from './validate.js'
|
||||
|
||||
const defaultBadgeDataSchema = Joi.object({
|
||||
label: Joi.string(),
|
||||
@ -565,4 +564,4 @@ class BaseService {
|
||||
* An HTML string that is included in the badge popup.
|
||||
*/
|
||||
|
||||
module.exports = BaseService
|
||||
export default BaseService
|
||||
|
@ -1,23 +1,22 @@
|
||||
'use strict'
|
||||
|
||||
const Joi = require('joi')
|
||||
const chai = require('chai')
|
||||
const { expect } = chai
|
||||
const sinon = require('sinon')
|
||||
const prometheus = require('prom-client')
|
||||
const PrometheusMetrics = require('../server/prometheus-metrics')
|
||||
const trace = require('./trace')
|
||||
const {
|
||||
import Joi from 'joi'
|
||||
import chai from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import prometheus from 'prom-client'
|
||||
import chaiAsPromised from 'chai-as-promised'
|
||||
import PrometheusMetrics from '../server/prometheus-metrics.js'
|
||||
import trace from './trace.js'
|
||||
import {
|
||||
NotFound,
|
||||
Inaccessible,
|
||||
InvalidResponse,
|
||||
InvalidParameter,
|
||||
Deprecated,
|
||||
} = require('./errors')
|
||||
const BaseService = require('./base')
|
||||
const { MetricHelper, MetricNames } = require('./metric-helper')
|
||||
require('../register-chai-plugins.spec')
|
||||
chai.use(require('chai-as-promised'))
|
||||
} from './errors.js'
|
||||
import BaseService from './base.js'
|
||||
import { MetricHelper, MetricNames } from './metric-helper.js'
|
||||
import '../register-chai-plugins.spec.js'
|
||||
const { expect } = chai
|
||||
chai.use(chaiAsPromised)
|
||||
|
||||
const queryParamSchema = Joi.object({
|
||||
queryParamA: Joi.string(),
|
||||
|
@ -1,8 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('assert')
|
||||
const Joi = require('joi')
|
||||
const coalesce = require('./coalesce')
|
||||
import assert from 'assert'
|
||||
import Joi from 'joi'
|
||||
import coalesce from './coalesce.js'
|
||||
|
||||
const serverStartTimeGMTString = new Date().toGMTString()
|
||||
const serverStartTimestamp = Date.now()
|
||||
@ -104,7 +102,7 @@ function serverHasBeenUpSinceResourceCached(req) {
|
||||
)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export {
|
||||
coalesceCacheLength,
|
||||
setCacheHeaders,
|
||||
setHeadersForCacheLength,
|
||||
|
@ -1,19 +1,16 @@
|
||||
'use strict'
|
||||
|
||||
const { test, given } = require('sazerac')
|
||||
const chai = require('chai')
|
||||
const { expect } = require('chai')
|
||||
const sinon = require('sinon')
|
||||
const httpMocks = require('node-mocks-http')
|
||||
const {
|
||||
import { test, given } from 'sazerac'
|
||||
import chai, { expect } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import httpMocks from 'node-mocks-http'
|
||||
import chaiDatetime from 'chai-datetime'
|
||||
import {
|
||||
coalesceCacheLength,
|
||||
setHeadersForCacheLength,
|
||||
setCacheHeaders,
|
||||
setCacheHeadersForStaticResource,
|
||||
serverHasBeenUpSinceResourceCached,
|
||||
} = require('./cache-headers')
|
||||
|
||||
chai.use(require('chai-datetime'))
|
||||
} from './cache-headers.js'
|
||||
chai.use(chaiDatetime)
|
||||
|
||||
describe('Cache header functions', function () {
|
||||
let res
|
||||
|
@ -1,7 +1,5 @@
|
||||
'use strict'
|
||||
|
||||
const Joi = require('joi')
|
||||
const categories = require('../../services/categories')
|
||||
import Joi from 'joi'
|
||||
import categories from '../../services/categories.js'
|
||||
|
||||
const isRealCategory = Joi.equal(...categories.map(({ id }) => id)).required()
|
||||
|
||||
@ -13,7 +11,4 @@ function assertValidCategory(category, message = undefined) {
|
||||
Joi.assert(category, isValidCategory, message)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
isValidCategory,
|
||||
assertValidCategory,
|
||||
}
|
||||
export { isValidCategory, assertValidCategory }
|
||||
|
@ -1,12 +1,10 @@
|
||||
'use strict'
|
||||
|
||||
const { NotFound, InvalidResponse, Inaccessible } = require('./errors')
|
||||
import { NotFound, InvalidResponse, Inaccessible } from './errors.js'
|
||||
|
||||
const defaultErrorMessages = {
|
||||
404: 'not found',
|
||||
}
|
||||
|
||||
module.exports = function checkErrorResponse(errorMessages = {}) {
|
||||
export default function checkErrorResponse(errorMessages = {}) {
|
||||
return async function ({ buffer, res }) {
|
||||
let error
|
||||
errorMessages = { ...defaultErrorMessages, ...errorMessages }
|
||||
|
@ -1,8 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
const { expect } = require('chai')
|
||||
const { NotFound, InvalidResponse, Inaccessible } = require('./errors')
|
||||
const checkErrorResponse = require('./check-error-response')
|
||||
import { expect } from 'chai'
|
||||
import { NotFound, InvalidResponse, Inaccessible } from './errors.js'
|
||||
import checkErrorResponse from './check-error-response.js'
|
||||
|
||||
describe('async error handler', function () {
|
||||
const buffer = Buffer.from('some stuff')
|
||||
|
@ -1,12 +1,10 @@
|
||||
'use strict'
|
||||
|
||||
const {
|
||||
import {
|
||||
decodeDataUrlFromQueryParam,
|
||||
prepareNamedLogo,
|
||||
} = require('../../lib/logos')
|
||||
const { svg2base64 } = require('../../lib/svg-helpers')
|
||||
const coalesce = require('./coalesce')
|
||||
const toArray = require('./to-array')
|
||||
} from '../../lib/logos.js'
|
||||
import { svg2base64 } from '../../lib/svg-helpers.js'
|
||||
import coalesce from './coalesce.js'
|
||||
import toArray from './to-array.js'
|
||||
|
||||
// Translate modern badge data to the legacy schema understood by the badge
|
||||
// maker. Allow the user to override the label, color, logo, etc. through the
|
||||
@ -34,7 +32,7 @@ const toArray = require('./to-array')
|
||||
// 3. In the case of the `social` style only, the last precedence is the
|
||||
// service's default logo. The `logoColor` can be overridden by the query
|
||||
// string.
|
||||
module.exports = function coalesceBadge(
|
||||
export default function coalesceBadge(
|
||||
overrides,
|
||||
serviceData,
|
||||
// These two parameters were kept separate to make tests clearer.
|
||||
|
@ -1,8 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
const { expect } = require('chai')
|
||||
const { getShieldsIcon, getSimpleIcon } = require('../../lib/logos')
|
||||
const coalesceBadge = require('./coalesce-badge')
|
||||
import { expect } from 'chai'
|
||||
import { getShieldsIcon, getSimpleIcon } from '../../lib/logos.js'
|
||||
import coalesceBadge from './coalesce-badge.js'
|
||||
|
||||
describe('coalesceBadge', function () {
|
||||
describe('Label', function () {
|
||||
|
@ -1,5 +1,3 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = function coalesce(...candidates) {
|
||||
export default function coalesce(...candidates) {
|
||||
return candidates.find(c => c !== undefined && c !== null)
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
'use strict'
|
||||
|
||||
const { test, given } = require('sazerac')
|
||||
const coalesce = require('./coalesce')
|
||||
import { test, given } from 'sazerac'
|
||||
import coalesce from './coalesce.js'
|
||||
|
||||
// Sticking with our one-line spread implementation, and defaulting to
|
||||
// `undefined` instead of `null`, though h/t to
|
||||
|
@ -1,11 +1,9 @@
|
||||
'use strict'
|
||||
|
||||
const Joi = require('joi')
|
||||
const camelcase = require('camelcase')
|
||||
const BaseService = require('./base')
|
||||
const { isValidCategory } = require('./categories')
|
||||
const { Deprecated } = require('./errors')
|
||||
const { isValidRoute } = require('./route')
|
||||
import Joi from 'joi'
|
||||
import camelcase from 'camelcase'
|
||||
import BaseService from './base.js'
|
||||
import { isValidCategory } from './categories.js'
|
||||
import { Deprecated } from './errors.js'
|
||||
import { isValidRoute } from './route.js'
|
||||
|
||||
const attrSchema = Joi.object({
|
||||
route: isValidRoute,
|
||||
@ -44,4 +42,4 @@ function deprecatedService(attrs) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = deprecatedService
|
||||
export default deprecatedService
|
||||
|
@ -1,7 +1,5 @@
|
||||
'use strict'
|
||||
|
||||
const { expect } = require('chai')
|
||||
const deprecatedService = require('./deprecated-service')
|
||||
import { expect } from 'chai'
|
||||
import deprecatedService from './deprecated-service.js'
|
||||
|
||||
describe('DeprecatedService', function () {
|
||||
const route = {
|
||||
|
@ -4,8 +4,6 @@
|
||||
* @module
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
/**
|
||||
* Base error class
|
||||
*
|
||||
@ -210,7 +208,7 @@ class Deprecated extends ShieldsRuntimeError {
|
||||
* badge when we catch and render the exception (Optional)
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
export {
|
||||
ShieldsRuntimeError,
|
||||
NotFound,
|
||||
ImproperlyConfigured,
|
||||
|
@ -1,10 +1,8 @@
|
||||
'use strict'
|
||||
|
||||
const Joi = require('joi')
|
||||
const { pathToRegexp, compile } = require('path-to-regexp')
|
||||
const categories = require('../../services/categories')
|
||||
const coalesceBadge = require('./coalesce-badge')
|
||||
const { makeFullUrl } = require('./route')
|
||||
import Joi from 'joi'
|
||||
import { pathToRegexp, compile } from 'path-to-regexp'
|
||||
import categories from '../../services/categories.js'
|
||||
import coalesceBadge from './coalesce-badge.js'
|
||||
import { makeFullUrl } from './route.js'
|
||||
|
||||
const optionalObjectOfKeyValues = Joi.object().pattern(
|
||||
/./,
|
||||
@ -155,7 +153,4 @@ function transformExample(inExample, index, ServiceClass) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
validateExample,
|
||||
transformExample,
|
||||
}
|
||||
export { validateExample, transformExample }
|
||||
|
@ -1,8 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
const { expect } = require('chai')
|
||||
const { test, given } = require('sazerac')
|
||||
const { validateExample, transformExample } = require('./examples')
|
||||
import { expect } from 'chai'
|
||||
import { test, given } from 'sazerac'
|
||||
import { validateExample, transformExample } from './examples.js'
|
||||
|
||||
describe('validateExample function', function () {
|
||||
it('passes valid examples', function () {
|
||||
|
@ -1,4 +1,3 @@
|
||||
'use strict'
|
||||
/**
|
||||
* @module
|
||||
*/
|
||||
@ -49,4 +48,4 @@ function mergeQueries(...queries) {
|
||||
return merged
|
||||
}
|
||||
|
||||
module.exports = { mergeQueries }
|
||||
export { mergeQueries }
|
||||
|
@ -1,11 +1,9 @@
|
||||
'use strict'
|
||||
import { expect } from 'chai'
|
||||
import gql from 'graphql-tag'
|
||||
import { print } from 'graphql/language/printer.js'
|
||||
import { mergeQueries } from './graphql.js'
|
||||
|
||||
const { expect } = require('chai')
|
||||
const gql = require('graphql-tag')
|
||||
const { print } = require('graphql/language/printer')
|
||||
const { mergeQueries } = require('./graphql')
|
||||
|
||||
require('../register-chai-plugins.spec')
|
||||
import '../register-chai-plugins.spec.js'
|
||||
|
||||
describe('mergeQueries function', function () {
|
||||
it('merges valid gql queries', function () {
|
||||
|
@ -1,23 +1,21 @@
|
||||
'use strict'
|
||||
|
||||
const BaseService = require('./base')
|
||||
const BaseJsonService = require('./base-json')
|
||||
const BaseGraphqlService = require('./base-graphql')
|
||||
const BaseStaticService = require('./base-static')
|
||||
const BaseSvgScrapingService = require('./base-svg-scraping')
|
||||
const BaseXmlService = require('./base-xml')
|
||||
const BaseYamlService = require('./base-yaml')
|
||||
const deprecatedService = require('./deprecated-service')
|
||||
const redirector = require('./redirector')
|
||||
const {
|
||||
import BaseService from './base.js'
|
||||
import BaseJsonService from './base-json.js'
|
||||
import BaseGraphqlService from './base-graphql.js'
|
||||
import BaseStaticService from './base-static.js'
|
||||
import BaseSvgScrapingService from './base-svg-scraping.js'
|
||||
import BaseXmlService from './base-xml.js'
|
||||
import BaseYamlService from './base-yaml.js'
|
||||
import deprecatedService from './deprecated-service.js'
|
||||
import redirector from './redirector.js'
|
||||
import {
|
||||
NotFound,
|
||||
InvalidResponse,
|
||||
Inaccessible,
|
||||
InvalidParameter,
|
||||
Deprecated,
|
||||
} = require('./errors')
|
||||
} from './errors.js'
|
||||
|
||||
module.exports = {
|
||||
export {
|
||||
BaseService,
|
||||
BaseJsonService,
|
||||
BaseGraphqlService,
|
||||
|
@ -1,9 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
// See available emoji at http://emoji.muan.co/
|
||||
const emojic = require('emojic')
|
||||
const { InvalidResponse } = require('./errors')
|
||||
const trace = require('./trace')
|
||||
import emojic from 'emojic'
|
||||
import { InvalidResponse } from './errors.js'
|
||||
import trace from './trace.js'
|
||||
|
||||
function parseJson(buffer) {
|
||||
const logTrace = (...args) => trace.logTrace('fetch', ...args)
|
||||
@ -23,6 +21,4 @@ function parseJson(buffer) {
|
||||
return json
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
parseJson,
|
||||
}
|
||||
export { parseJson }
|
||||
|
@ -1,15 +1,9 @@
|
||||
'use strict'
|
||||
|
||||
const request = require('request')
|
||||
const makeBadge = require('../../badge-maker/lib/make-badge')
|
||||
const { setCacheHeaders } = require('./cache-headers')
|
||||
const {
|
||||
Inaccessible,
|
||||
InvalidResponse,
|
||||
ShieldsRuntimeError,
|
||||
} = require('./errors')
|
||||
const { makeSend } = require('./legacy-result-sender')
|
||||
const coalesceBadge = require('./coalesce-badge')
|
||||
import request from 'request'
|
||||
import makeBadge from '../../badge-maker/lib/make-badge.js'
|
||||
import { setCacheHeaders } from './cache-headers.js'
|
||||
import { Inaccessible, InvalidResponse, ShieldsRuntimeError } from './errors.js'
|
||||
import { makeSend } from './legacy-result-sender.js'
|
||||
import coalesceBadge from './coalesce-badge.js'
|
||||
|
||||
const userAgent = 'Shields.io/2003a'
|
||||
|
||||
@ -206,8 +200,4 @@ function handleRequest(cacheHeaderConfig, handlerOptions) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
handleRequest,
|
||||
promisify,
|
||||
userAgent,
|
||||
}
|
||||
export { handleRequest, promisify, userAgent }
|
||||
|
@ -1,12 +1,10 @@
|
||||
'use strict'
|
||||
|
||||
const { expect } = require('chai')
|
||||
const nock = require('nock')
|
||||
const portfinder = require('portfinder')
|
||||
const Camp = require('@shields_io/camp')
|
||||
const got = require('../got-test-client')
|
||||
const coalesceBadge = require('./coalesce-badge')
|
||||
const { handleRequest } = require('./legacy-request-handler')
|
||||
import { expect } from 'chai'
|
||||
import nock from 'nock'
|
||||
import portfinder from 'portfinder'
|
||||
import Camp from '@shields_io/camp'
|
||||
import got from '../got-test-client.js'
|
||||
import coalesceBadge from './coalesce-badge.js'
|
||||
import { handleRequest } from './legacy-request-handler.js'
|
||||
|
||||
async function performTwoRequests(baseUrl, first, second) {
|
||||
expect((await got(`${baseUrl}${first}`)).statusCode).to.equal(200)
|
||||
|
@ -1,6 +1,4 @@
|
||||
'use strict'
|
||||
|
||||
const stream = require('stream')
|
||||
import stream from 'stream'
|
||||
|
||||
function streamFromString(str) {
|
||||
const newStream = new stream.Readable()
|
||||
@ -32,6 +30,4 @@ function makeSend(format, askres, end) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
makeSend,
|
||||
}
|
||||
export { makeSend }
|
||||
|
@ -1,3 +1 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = []
|
||||
export default []
|
||||
|
@ -1,4 +1,2 @@
|
||||
/* eslint-disable */
|
||||
'use strict'
|
||||
|
||||
class BadService {}
|
||||
class BadService {} // lgtm [js/unused-local-variable]
|
||||
|
@ -1,3 +1 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {}
|
||||
export {}
|
||||
|
@ -1,3 +1 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = undefined
|
||||
export default undefined
|
||||
|
@ -1,9 +1,10 @@
|
||||
'use strict'
|
||||
|
||||
const BaseJsonService = require('../base-json')
|
||||
import BaseJsonService from '../base-json.js'
|
||||
|
||||
class BadBaseService {}
|
||||
class GoodService extends BaseJsonService {}
|
||||
class GoodService extends BaseJsonService {
|
||||
static category = 'build'
|
||||
static route = { base: 'it/is', pattern: 'good' }
|
||||
}
|
||||
class BadService extends BadBaseService {}
|
||||
|
||||
module.exports = [GoodService, BadService]
|
||||
export default [GoodService, BadService]
|
||||
|
@ -1,5 +1,3 @@
|
||||
'use strict'
|
||||
|
||||
class BadService {}
|
||||
|
||||
module.exports = BadService
|
||||
export default BadService
|
||||
|
@ -1,6 +1,4 @@
|
||||
'use strict'
|
||||
|
||||
class BadBaseService {}
|
||||
class BadService extends BadBaseService {}
|
||||
|
||||
module.exports = BadService
|
||||
export default BadService
|
||||
|
@ -1,6 +1,4 @@
|
||||
'use strict'
|
||||
|
||||
const BaseJsonService = require('../base-json')
|
||||
import BaseJsonService from '../base-json.js'
|
||||
|
||||
class GoodServiceOne extends BaseJsonService {
|
||||
static category = 'build'
|
||||
@ -11,4 +9,4 @@ class GoodServiceTwo extends BaseJsonService {
|
||||
static route = { base: 'good', pattern: 'two' }
|
||||
}
|
||||
|
||||
module.exports = [GoodServiceOne, GoodServiceTwo]
|
||||
export default [GoodServiceOne, GoodServiceTwo]
|
||||
|
@ -1,10 +1,8 @@
|
||||
'use strict'
|
||||
|
||||
const BaseJsonService = require('../base-json')
|
||||
import BaseJsonService from '../base-json.js'
|
||||
|
||||
class GoodService extends BaseJsonService {
|
||||
static category = 'build'
|
||||
static route = { base: 'it/is', pattern: 'good' }
|
||||
}
|
||||
|
||||
module.exports = GoodService
|
||||
export default GoodService
|
||||
|
@ -1,6 +1,4 @@
|
||||
'use strict'
|
||||
|
||||
const BaseJsonService = require('../base-json')
|
||||
import BaseJsonService from '../base-json.js'
|
||||
|
||||
class GoodServiceOne extends BaseJsonService {
|
||||
static category = 'build'
|
||||
@ -11,4 +9,4 @@ class GoodServiceTwo extends BaseJsonService {
|
||||
static route = { base: 'good', pattern: 'two' }
|
||||
}
|
||||
|
||||
module.exports = { GoodServiceOne, GoodServiceTwo }
|
||||
export { GoodServiceOne, GoodServiceTwo }
|
||||
|
@ -1,13 +1,17 @@
|
||||
'use strict'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
import glob from 'glob'
|
||||
import countBy from 'lodash.countby'
|
||||
import categories from '../../services/categories.js'
|
||||
import BaseService from './base.js'
|
||||
import { assertValidServiceDefinitionExport } from './service-definitions.js'
|
||||
|
||||
const path = require('path')
|
||||
const glob = require('glob')
|
||||
const countBy = require('lodash.countby')
|
||||
const categories = require('../../services/categories')
|
||||
const BaseService = require('./base')
|
||||
const { assertValidServiceDefinitionExport } = require('./service-definitions')
|
||||
|
||||
const serviceDir = path.join(__dirname, '..', '..', 'services')
|
||||
const serviceDir = path.join(
|
||||
path.dirname(fileURLToPath(import.meta.url)),
|
||||
'..',
|
||||
'..',
|
||||
'services'
|
||||
)
|
||||
|
||||
class InvalidService extends Error {
|
||||
constructor(message) {
|
||||
@ -16,54 +20,38 @@ class InvalidService extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
function loadServiceClasses(servicePaths) {
|
||||
async function loadServiceClasses(servicePaths) {
|
||||
if (!servicePaths) {
|
||||
servicePaths = glob.sync(path.join(serviceDir, '**', '*.service.js'))
|
||||
}
|
||||
|
||||
let serviceClasses = []
|
||||
servicePaths.forEach(servicePath => {
|
||||
const module = require(servicePath)
|
||||
const serviceClasses = []
|
||||
for await (const servicePath of servicePaths) {
|
||||
const currentServiceClasses = Object.values(
|
||||
await import(`file://${servicePath}`)
|
||||
).flatMap(element =>
|
||||
typeof element === 'object' ? Object.values(element) : element
|
||||
)
|
||||
|
||||
const theseServiceClasses = []
|
||||
if (
|
||||
!module ||
|
||||
(module.constructor === Array && module.length === 0) ||
|
||||
(module.constructor === Object && Object.keys(module).length === 0)
|
||||
) {
|
||||
if (currentServiceClasses.length === 0) {
|
||||
throw new InvalidService(
|
||||
`Expected ${servicePath} to export a service or a collection of services`
|
||||
)
|
||||
} else if (module.prototype instanceof BaseService) {
|
||||
theseServiceClasses.push(module)
|
||||
} else if (module.constructor === Array || module.constructor === Object) {
|
||||
for (const key in module) {
|
||||
const serviceClass = module[key]
|
||||
if (serviceClass.prototype instanceof BaseService) {
|
||||
theseServiceClasses.push(serviceClass)
|
||||
} else {
|
||||
throw new InvalidService(
|
||||
`Expected ${servicePath} to export a service or a collection of services; one of them was ${serviceClass}`
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new InvalidService(
|
||||
`Expected ${servicePath} to export a service or a collection of services; got ${module}`
|
||||
)
|
||||
}
|
||||
|
||||
// Decorate each service class with the directory that contains it.
|
||||
theseServiceClasses.forEach(serviceClass => {
|
||||
serviceClass.serviceFamily = servicePath
|
||||
.replace(serviceDir, '')
|
||||
.split(path.sep)[1]
|
||||
currentServiceClasses.forEach(serviceClass => {
|
||||
if (serviceClass && serviceClass.prototype instanceof BaseService) {
|
||||
// Decorate each service class with the directory that contains it.
|
||||
serviceClass.serviceFamily = servicePath
|
||||
.replace(serviceDir, '')
|
||||
.split(path.sep)[1]
|
||||
serviceClass.validateDefinition()
|
||||
return serviceClasses.push(serviceClass)
|
||||
}
|
||||
throw new InvalidService(
|
||||
`Expected ${servicePath} to export a service or a collection of services; one of them was ${serviceClass}`
|
||||
)
|
||||
})
|
||||
|
||||
serviceClasses = serviceClasses.concat(theseServiceClasses)
|
||||
})
|
||||
|
||||
serviceClasses.forEach(ServiceClass => ServiceClass.validateDefinition())
|
||||
}
|
||||
|
||||
return serviceClasses
|
||||
}
|
||||
@ -80,8 +68,8 @@ function assertNamesUnique(names, { message }) {
|
||||
}
|
||||
}
|
||||
|
||||
function checkNames() {
|
||||
const services = loadServiceClasses()
|
||||
async function checkNames() {
|
||||
const services = await loadServiceClasses()
|
||||
assertNamesUnique(
|
||||
services.map(({ name }) => name),
|
||||
{
|
||||
@ -90,8 +78,8 @@ function checkNames() {
|
||||
)
|
||||
}
|
||||
|
||||
function collectDefinitions() {
|
||||
const services = loadServiceClasses()
|
||||
async function collectDefinitions() {
|
||||
const services = (await loadServiceClasses())
|
||||
// flatMap.
|
||||
.map(ServiceClass => ServiceClass.getDefinition())
|
||||
.reduce((accum, these) => accum.concat(these), [])
|
||||
@ -103,13 +91,15 @@ function collectDefinitions() {
|
||||
return result
|
||||
}
|
||||
|
||||
function loadTesters() {
|
||||
return glob
|
||||
.sync(path.join(serviceDir, '**', '*.tester.js'))
|
||||
.map(path => require(path))
|
||||
async function loadTesters() {
|
||||
return Promise.all(
|
||||
glob
|
||||
.sync(path.join(serviceDir, '**', '*.tester.js'))
|
||||
.map(async path => await import(`file://${path}`))
|
||||
)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export {
|
||||
InvalidService,
|
||||
loadServiceClasses,
|
||||
checkNames,
|
||||
|
@ -1,59 +1,67 @@
|
||||
'use strict'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
import chai from 'chai'
|
||||
import chaiAsPromised from 'chai-as-promised'
|
||||
import { loadServiceClasses, InvalidService } from './loader.js'
|
||||
chai.use(chaiAsPromised)
|
||||
|
||||
const { expect } = require('chai')
|
||||
const { loadServiceClasses, InvalidService } = require('./loader')
|
||||
const { expect } = chai
|
||||
const fixturesDir = path.join(
|
||||
path.dirname(fileURLToPath(import.meta.url)),
|
||||
'loader-test-fixtures'
|
||||
)
|
||||
|
||||
describe('loadServiceClasses function', function () {
|
||||
it('throws if module exports empty', function () {
|
||||
expect(() =>
|
||||
loadServiceClasses(['./loader-test-fixtures/empty-undefined.fixture.js'])
|
||||
).to.throw(InvalidService)
|
||||
expect(() =>
|
||||
loadServiceClasses(['./loader-test-fixtures/empty-array.fixture.js'])
|
||||
).to.throw()
|
||||
expect(() =>
|
||||
loadServiceClasses(['./loader-test-fixtures/empty-object.fixture.js'])
|
||||
).to.throw(InvalidService)
|
||||
expect(() =>
|
||||
loadServiceClasses(['./loader-test-fixtures/empty-no-export.fixture.js'])
|
||||
).to.throw(InvalidService)
|
||||
expect(() =>
|
||||
it('throws if module exports empty', async function () {
|
||||
await expect(
|
||||
loadServiceClasses([path.join(fixturesDir, 'empty-undefined.fixture.js')])
|
||||
).to.be.rejectedWith(InvalidService)
|
||||
await expect(
|
||||
loadServiceClasses([path.join(fixturesDir, 'empty-array.fixture.js')])
|
||||
).to.be.rejectedWith(InvalidService)
|
||||
await expect(
|
||||
loadServiceClasses([path.join(fixturesDir, 'empty-object.fixture.js')])
|
||||
).to.be.rejectedWith(InvalidService)
|
||||
await expect(
|
||||
loadServiceClasses([path.join(fixturesDir, 'empty-no-export.fixture.js')])
|
||||
).to.be.rejectedWith(InvalidService)
|
||||
await expect(
|
||||
loadServiceClasses([
|
||||
'./loader-test-fixtures/valid-array.fixture.js',
|
||||
'./loader-test-fixtures/valid-class.fixture.js',
|
||||
'./loader-test-fixtures/empty-array.fixture.js',
|
||||
path.join(fixturesDir, 'valid-array.fixture.js'),
|
||||
path.join(fixturesDir, 'valid-class.fixture.js'),
|
||||
path.join(fixturesDir, 'empty-array.fixture.js'),
|
||||
])
|
||||
).to.throw(InvalidService)
|
||||
).to.be.rejectedWith(InvalidService)
|
||||
})
|
||||
|
||||
it('throws if module exports invalid', function () {
|
||||
expect(() =>
|
||||
loadServiceClasses(['./loader-test-fixtures/invalid-no-base.fixture.js'])
|
||||
).to.throw(InvalidService)
|
||||
expect(() =>
|
||||
it('throws if module exports invalid', async function () {
|
||||
await expect(
|
||||
loadServiceClasses([path.join(fixturesDir, 'invalid-no-base.fixture.js')])
|
||||
).to.be.rejectedWith(InvalidService)
|
||||
await expect(
|
||||
loadServiceClasses([
|
||||
'./loader-test-fixtures/invalid-wrong-base.fixture.js',
|
||||
path.join(fixturesDir, 'invalid-wrong-base.fixture.js'),
|
||||
])
|
||||
).to.throw(InvalidService)
|
||||
expect(() =>
|
||||
loadServiceClasses(['./loader-test-fixtures/invalid-mixed.fixture.js'])
|
||||
).to.throw(InvalidService)
|
||||
expect(() =>
|
||||
).to.be.rejectedWith(InvalidService)
|
||||
await expect(
|
||||
loadServiceClasses([path.join(fixturesDir, 'invalid-mixed.fixture.js')])
|
||||
).to.be.rejectedWith(InvalidService)
|
||||
await expect(
|
||||
loadServiceClasses([
|
||||
'./loader-test-fixtures/valid-array.fixture.js',
|
||||
'./loader-test-fixtures/valid-class.fixture.js',
|
||||
'./loader-test-fixtures/invalid-no-base.fixture.js',
|
||||
path.join(fixturesDir, 'valid-array.fixture.js'),
|
||||
path.join(fixturesDir, 'valid-class.fixture.js'),
|
||||
path.join(fixturesDir, 'invalid-no-base.fixture.js'),
|
||||
])
|
||||
).to.throw(InvalidService)
|
||||
).to.be.rejectedWith(InvalidService)
|
||||
})
|
||||
|
||||
it('registers services if module exports valid service classes', function () {
|
||||
expect(
|
||||
it('registers services if module exports valid service classes', async function () {
|
||||
await expect(
|
||||
loadServiceClasses([
|
||||
'./loader-test-fixtures/valid-array.fixture.js',
|
||||
'./loader-test-fixtures/valid-object.fixture.js',
|
||||
'./loader-test-fixtures/valid-class.fixture.js',
|
||||
path.join(fixturesDir, 'valid-array.fixture.js'),
|
||||
path.join(fixturesDir, 'valid-object.fixture.js'),
|
||||
path.join(fixturesDir, 'valid-class.fixture.js'),
|
||||
])
|
||||
).to.have.length(5)
|
||||
).to.eventually.have.length(5)
|
||||
})
|
||||
})
|
||||
|
@ -1,6 +1,4 @@
|
||||
'use strict'
|
||||
|
||||
const { performance } = require('perf_hooks')
|
||||
import { performance } from 'perf_hooks'
|
||||
|
||||
class MetricHelper {
|
||||
constructor({ metricInstance }, { category, serviceFamily, name }) {
|
||||
@ -59,4 +57,4 @@ const MetricNames = Object.freeze({
|
||||
SERVICE_RESPONSE_SIZE: Symbol('service-response-size'),
|
||||
})
|
||||
|
||||
module.exports = { MetricHelper, MetricNames }
|
||||
export { MetricHelper, MetricNames }
|
||||
|
@ -1,18 +1,16 @@
|
||||
'use strict'
|
||||
|
||||
const camelcase = require('camelcase')
|
||||
const emojic = require('emojic')
|
||||
const Joi = require('joi')
|
||||
const queryString = require('query-string')
|
||||
const BaseService = require('./base')
|
||||
const {
|
||||
import camelcase from 'camelcase'
|
||||
import emojic from 'emojic'
|
||||
import Joi from 'joi'
|
||||
import queryString from 'query-string'
|
||||
import BaseService from './base.js'
|
||||
import {
|
||||
serverHasBeenUpSinceResourceCached,
|
||||
setCacheHeadersForStaticResource,
|
||||
} = require('./cache-headers')
|
||||
const { isValidCategory } = require('./categories')
|
||||
const { MetricHelper } = require('./metric-helper')
|
||||
const { isValidRoute, prepareRoute, namedParamsForMatch } = require('./route')
|
||||
const trace = require('./trace')
|
||||
} from './cache-headers.js'
|
||||
import { isValidCategory } from './categories.js'
|
||||
import { MetricHelper } from './metric-helper.js'
|
||||
import { isValidRoute, prepareRoute, namedParamsForMatch } from './route.js'
|
||||
import trace from './trace.js'
|
||||
|
||||
const attrSchema = Joi.object({
|
||||
name: Joi.string().min(3),
|
||||
@ -32,7 +30,7 @@ const attrSchema = Joi.object({
|
||||
overrideTransformedQueryParams: Joi.bool().optional(),
|
||||
}).required()
|
||||
|
||||
module.exports = function redirector(attrs) {
|
||||
export default function redirector(attrs) {
|
||||
const {
|
||||
name,
|
||||
category,
|
||||
|
@ -1,10 +1,8 @@
|
||||
'use strict'
|
||||
|
||||
const Camp = require('@shields_io/camp')
|
||||
const portfinder = require('portfinder')
|
||||
const { expect } = require('chai')
|
||||
const got = require('../got-test-client')
|
||||
const redirector = require('./redirector')
|
||||
import Camp from '@shields_io/camp'
|
||||
import portfinder from 'portfinder'
|
||||
import { expect } from 'chai'
|
||||
import got from '../got-test-client.js'
|
||||
import redirector from './redirector.js'
|
||||
|
||||
describe('Redirector', function () {
|
||||
const route = {
|
||||
|
@ -1,8 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
const escapeStringRegexp = require('escape-string-regexp')
|
||||
const Joi = require('joi')
|
||||
const { pathToRegexp } = require('path-to-regexp')
|
||||
import escapeStringRegexp from 'escape-string-regexp'
|
||||
import Joi from 'joi'
|
||||
import { pathToRegexp } from 'path-to-regexp'
|
||||
|
||||
function makeFullUrl(base, partialUrl) {
|
||||
return `/${[base, partialUrl].filter(Boolean).join('/')}`
|
||||
@ -74,7 +72,7 @@ function getQueryParamNames({ queryParamSchema }) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export {
|
||||
makeFullUrl,
|
||||
isValidRoute,
|
||||
assertValidRoute,
|
||||
|
@ -1,13 +1,11 @@
|
||||
'use strict'
|
||||
|
||||
const { expect } = require('chai')
|
||||
const Joi = require('joi')
|
||||
const { test, given, forCases } = require('sazerac')
|
||||
const {
|
||||
import { expect } from 'chai'
|
||||
import Joi from 'joi'
|
||||
import { test, given, forCases } from 'sazerac'
|
||||
import {
|
||||
prepareRoute,
|
||||
namedParamsForMatch,
|
||||
getQueryParamNames,
|
||||
} = require('./route')
|
||||
} from './route.js'
|
||||
|
||||
describe('Route helpers', function () {
|
||||
context('A `pattern` with a named param is declared', function () {
|
||||
|
@ -1,6 +1,4 @@
|
||||
'use strict'
|
||||
|
||||
const Joi = require('joi')
|
||||
import Joi from 'joi'
|
||||
|
||||
// This should be kept in sync with the schema in
|
||||
// `frontend/lib/service-definitions/index.ts`.
|
||||
@ -72,7 +70,7 @@ function assertValidServiceDefinitionExport(examples, message = undefined) {
|
||||
Joi.assert(examples, serviceDefinitionExport, message)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export {
|
||||
serviceDefinition,
|
||||
assertValidServiceDefinition,
|
||||
serviceDefinitionExport,
|
||||
|
@ -1,6 +1,4 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = function toArray(val) {
|
||||
export default function toArray(val) {
|
||||
if (val === undefined) {
|
||||
return []
|
||||
} else if (Object(val) instanceof Array) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
const chalk = require('chalk')
|
||||
const config = require('config').util.toObject()
|
||||
import chalk from 'chalk'
|
||||
import config from 'config'
|
||||
const objectConfig = config.util.toObject()
|
||||
|
||||
// Config is loaded globally but it would be better to inject it. To do that,
|
||||
// there needs to be one instance of the service created at registration time,
|
||||
@ -10,7 +9,7 @@ const config = require('config').util.toObject()
|
||||
// thereby gaining access to the injected config.
|
||||
const {
|
||||
services: { trace: enableTraceLogging },
|
||||
} = config.public
|
||||
} = objectConfig.public
|
||||
|
||||
function _formatLabelForStage(stage, label) {
|
||||
const colorFn = {
|
||||
@ -37,6 +36,6 @@ function logTrace(stage, symbol, label, content, { deep = false } = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
logTrace,
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
const emojic = require('emojic')
|
||||
const Joi = require('joi')
|
||||
const trace = require('./trace')
|
||||
import emojic from 'emojic'
|
||||
import Joi from 'joi'
|
||||
import trace from './trace.js'
|
||||
|
||||
function validate(
|
||||
{
|
||||
@ -50,4 +48,4 @@ function validate(
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = validate
|
||||
export default validate
|
||||
|
@ -1,11 +1,9 @@
|
||||
'use strict'
|
||||
|
||||
const Joi = require('joi')
|
||||
const { expect } = require('chai')
|
||||
const sinon = require('sinon')
|
||||
const trace = require('./trace')
|
||||
const { InvalidParameter } = require('./errors')
|
||||
const validate = require('./validate')
|
||||
import Joi from 'joi'
|
||||
import { expect } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import trace from './trace.js'
|
||||
import { InvalidParameter } from './errors.js'
|
||||
import validate from './validate.js'
|
||||
|
||||
describe('validate', function () {
|
||||
const schema = Joi.object({
|
||||
|
@ -1,6 +1,4 @@
|
||||
'use strict'
|
||||
|
||||
const got = require('got')
|
||||
import got from 'got'
|
||||
|
||||
// https://github.com/nock/nock/issues/1523
|
||||
module.exports = got.extend({ retry: 0 })
|
||||
export default got.extend({ retry: 0 })
|
||||
|
@ -1,6 +1,5 @@
|
||||
'use strict'
|
||||
|
||||
const { Inaccessible, InvalidResponse } = require('../base-service/errors')
|
||||
import requestModule from 'request'
|
||||
import { Inaccessible, InvalidResponse } from '../base-service/errors.js'
|
||||
|
||||
// Map from URL to { timestamp: last fetch time, data: data }.
|
||||
let regularUpdateCache = Object.create(null)
|
||||
@ -11,8 +10,8 @@ let regularUpdateCache = Object.create(null)
|
||||
//
|
||||
// To use this from a service:
|
||||
//
|
||||
// const { promisify } = require('util')
|
||||
// const { regularUpdate } = require('../../core/legacy/regular-update')
|
||||
// import { promisify } from 'util'
|
||||
// import { regularUpdate } from '../../core/legacy/regular-update.js'
|
||||
//
|
||||
// function getThing() {
|
||||
// return promisify(regularUpdate)({
|
||||
@ -32,7 +31,7 @@ function regularUpdate(
|
||||
json = true,
|
||||
scraper = buffer => buffer,
|
||||
options = {},
|
||||
request = require('request'),
|
||||
request = requestModule,
|
||||
},
|
||||
cb
|
||||
) {
|
||||
@ -95,7 +94,4 @@ function clearRegularUpdateCache() {
|
||||
regularUpdateCache = Object.create(null)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
regularUpdate,
|
||||
clearRegularUpdateCache,
|
||||
}
|
||||
export { regularUpdate, clearRegularUpdateCache }
|
||||
|
@ -1,6 +1,5 @@
|
||||
'use strict'
|
||||
|
||||
const { use } = require('chai')
|
||||
|
||||
use(require('chai-string'))
|
||||
use(require('sinon-chai'))
|
||||
import { use } from 'chai'
|
||||
import chaiString from 'chai-string'
|
||||
import sinonChai from 'sinon-chai'
|
||||
use(chaiString)
|
||||
use(sinonChai)
|
||||
|
@ -1,18 +1,14 @@
|
||||
'use strict'
|
||||
|
||||
const merge = require('deepmerge')
|
||||
const config = require('config').util.toObject()
|
||||
const portfinder = require('portfinder')
|
||||
const Server = require('./server')
|
||||
import merge from 'deepmerge'
|
||||
import config from 'config'
|
||||
import portfinder from 'portfinder'
|
||||
import Server from './server.js'
|
||||
|
||||
async function createTestServer(customConfig = {}) {
|
||||
const mergedConfig = merge(config, customConfig)
|
||||
const mergedConfig = merge(config.util.toObject(), customConfig)
|
||||
if (!mergedConfig.public.bind.port) {
|
||||
mergedConfig.public.bind.port = await portfinder.getPortPromise()
|
||||
}
|
||||
return new Server(mergedConfig)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
createTestServer,
|
||||
}
|
||||
export { createTestServer }
|
||||
|
@ -1,11 +1,10 @@
|
||||
'use strict'
|
||||
const os = require('os')
|
||||
const got = require('got')
|
||||
const generateInstanceId = require('./instance-id-generator')
|
||||
const { promClientJsonToInfluxV2 } = require('./metrics/format-converters')
|
||||
const log = require('./log')
|
||||
import os from 'os'
|
||||
import got from 'got'
|
||||
import generateInstanceId from './instance-id-generator.js'
|
||||
import { promClientJsonToInfluxV2 } from './metrics/format-converters.js'
|
||||
import log from './log.js'
|
||||
|
||||
module.exports = class InfluxMetrics {
|
||||
export default class InfluxMetrics {
|
||||
constructor(metricInstance, config) {
|
||||
this._metricInstance = metricInstance
|
||||
this._config = config
|
||||
|
@ -1,11 +1,10 @@
|
||||
'use strict'
|
||||
const os = require('os')
|
||||
const nock = require('nock')
|
||||
const sinon = require('sinon')
|
||||
const { expect } = require('chai')
|
||||
const log = require('./log')
|
||||
const InfluxMetrics = require('./influx-metrics')
|
||||
require('../register-chai-plugins.spec')
|
||||
import os from 'os'
|
||||
import nock from 'nock'
|
||||
import sinon from 'sinon'
|
||||
import { expect } from 'chai'
|
||||
import log from './log.js'
|
||||
import InfluxMetrics from './influx-metrics.js'
|
||||
import '../register-chai-plugins.spec.js'
|
||||
describe('Influx metrics', function () {
|
||||
const metricInstance = {
|
||||
metrics() {
|
||||
|
@ -1,8 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
function generateInstanceId() {
|
||||
// from https://gist.github.com/gordonbrander/2230317
|
||||
return Math.random().toString(36).substr(2, 9)
|
||||
}
|
||||
|
||||
module.exports = generateInstanceId
|
||||
export default generateInstanceId
|
||||
|
@ -1,5 +1,4 @@
|
||||
'use strict'
|
||||
const Sentry = require('@sentry/node')
|
||||
import Sentry from '@sentry/node'
|
||||
|
||||
const listeners = []
|
||||
|
||||
@ -23,27 +22,32 @@ function date() {
|
||||
)
|
||||
}
|
||||
|
||||
module.exports = function log(...msg) {
|
||||
const log = (...msg) => {
|
||||
const d = date()
|
||||
listeners.forEach(f => f(d, ...msg))
|
||||
console.log(d, ...msg)
|
||||
}
|
||||
|
||||
module.exports.error = function error(err) {
|
||||
const error = err => {
|
||||
const d = date()
|
||||
listeners.forEach(f => f(d, err))
|
||||
Sentry.captureException(err)
|
||||
console.error(d, err)
|
||||
}
|
||||
|
||||
module.exports.addListener = function addListener(func) {
|
||||
listeners.push(func)
|
||||
}
|
||||
const addListener = func => listeners.push(func)
|
||||
|
||||
module.exports.removeListener = function removeListener(func) {
|
||||
const removeListener = func => {
|
||||
const index = listeners.indexOf(func)
|
||||
if (index < 0) {
|
||||
return
|
||||
}
|
||||
listeners.splice(index, 1)
|
||||
}
|
||||
|
||||
export default {
|
||||
log,
|
||||
error,
|
||||
addListener,
|
||||
removeListener,
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
'use strict'
|
||||
const groupBy = require('lodash.groupby')
|
||||
import groupBy from 'lodash.groupby'
|
||||
|
||||
function promClientJsonToInfluxV2(metrics, extraLabels = {}) {
|
||||
return metrics
|
||||
@ -24,4 +23,4 @@ function promClientJsonToInfluxV2(metrics, extraLabels = {}) {
|
||||
.join('\n')
|
||||
}
|
||||
|
||||
module.exports = { promClientJsonToInfluxV2 }
|
||||
export { promClientJsonToInfluxV2 }
|
||||
|
@ -1,8 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
const { expect } = require('chai')
|
||||
const prometheus = require('prom-client')
|
||||
const { promClientJsonToInfluxV2 } = require('./format-converters')
|
||||
import { expect } from 'chai'
|
||||
import prometheus from 'prom-client'
|
||||
import { promClientJsonToInfluxV2 } from './format-converters.js'
|
||||
|
||||
describe('Metric format converters', function () {
|
||||
describe('prom-client JSON to InfluxDB line protocol (version 2)', function () {
|
||||
|
@ -1,9 +1,7 @@
|
||||
'use strict'
|
||||
import decamelize from 'decamelize'
|
||||
import prometheus from 'prom-client'
|
||||
|
||||
const decamelize = require('decamelize')
|
||||
const prometheus = require('prom-client')
|
||||
|
||||
module.exports = class PrometheusMetrics {
|
||||
export default class PrometheusMetrics {
|
||||
constructor({ register } = {}) {
|
||||
this.register = register || new prometheus.Registry()
|
||||
this.counters = {
|
||||
|
@ -1,10 +1,8 @@
|
||||
'use strict'
|
||||
|
||||
const { expect } = require('chai')
|
||||
const Camp = require('@shields_io/camp')
|
||||
const portfinder = require('portfinder')
|
||||
const got = require('../got-test-client')
|
||||
const Metrics = require('./prometheus-metrics')
|
||||
import { expect } from 'chai'
|
||||
import Camp from '@shields_io/camp'
|
||||
import portfinder from 'portfinder'
|
||||
import got from '../got-test-client.js'
|
||||
import Metrics from './prometheus-metrics.js'
|
||||
|
||||
describe('Prometheus metrics route', function () {
|
||||
let port, baseUrl, camp, metrics
|
||||
|
@ -1,5 +1,3 @@
|
||||
'use strict'
|
||||
|
||||
function constEq(a, b) {
|
||||
if (a.length !== b.length) {
|
||||
return false
|
||||
@ -17,4 +15,4 @@ function makeSecretIsValid(shieldsSecret) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { makeSecretIsValid }
|
||||
export { makeSecretIsValid }
|
||||
|
@ -1,27 +1,26 @@
|
||||
'use strict'
|
||||
/**
|
||||
* @module
|
||||
*/
|
||||
|
||||
const path = require('path')
|
||||
const url = require('url')
|
||||
import path from 'path'
|
||||
import url, { fileURLToPath } from 'url'
|
||||
import cloudflareMiddleware from 'cloudflare-middleware'
|
||||
import bytes from 'bytes'
|
||||
import Camp from '@shields_io/camp'
|
||||
import originalJoi from 'joi'
|
||||
import makeBadge from '../../badge-maker/lib/make-badge.js'
|
||||
import GithubConstellation from '../../services/github/github-constellation.js'
|
||||
import { setRoutes } from '../../services/suggest.js'
|
||||
import { loadServiceClasses } from '../base-service/loader.js'
|
||||
import { makeSend } from '../base-service/legacy-result-sender.js'
|
||||
import { handleRequest } from '../base-service/legacy-request-handler.js'
|
||||
import { clearRegularUpdateCache } from '../legacy/regular-update.js'
|
||||
import { rasterRedirectUrl } from '../badge-urls/make-badge-url.js'
|
||||
import { nonNegativeInteger } from '../../services/validators.js'
|
||||
import log from './log.js'
|
||||
import PrometheusMetrics from './prometheus-metrics.js'
|
||||
import InfluxMetrics from './influx-metrics.js'
|
||||
const { URL } = url
|
||||
const cloudflareMiddleware = require('cloudflare-middleware')
|
||||
const bytes = require('bytes')
|
||||
const Camp = require('@shields_io/camp')
|
||||
const originalJoi = require('joi')
|
||||
const makeBadge = require('../../badge-maker/lib/make-badge')
|
||||
const GithubConstellation = require('../../services/github/github-constellation')
|
||||
const suggest = require('../../services/suggest')
|
||||
const { loadServiceClasses } = require('../base-service/loader')
|
||||
const { makeSend } = require('../base-service/legacy-result-sender')
|
||||
const { handleRequest } = require('../base-service/legacy-request-handler')
|
||||
const { clearRegularUpdateCache } = require('../legacy/regular-update')
|
||||
const { rasterRedirectUrl } = require('../badge-urls/make-badge-url')
|
||||
const { nonNegativeInteger } = require('../../services/validators')
|
||||
const log = require('./log')
|
||||
const PrometheusMetrics = require('./prometheus-metrics')
|
||||
const InfluxMetrics = require('./influx-metrics')
|
||||
|
||||
const Joi = originalJoi
|
||||
.extend(base => ({
|
||||
@ -143,7 +142,12 @@ const publicConfigSchema = Joi.object({
|
||||
requestTimeoutSeconds: nonNegativeInteger,
|
||||
requestTimeoutMaxAgeSeconds: nonNegativeInteger,
|
||||
documentRoot: Joi.string().default(
|
||||
path.resolve(__dirname, '..', '..', 'public')
|
||||
path.resolve(
|
||||
path.dirname(fileURLToPath(import.meta.url)),
|
||||
'..',
|
||||
'..',
|
||||
'public'
|
||||
)
|
||||
),
|
||||
requireCloudflare: Joi.boolean().required(),
|
||||
}).required()
|
||||
@ -399,11 +403,11 @@ class Server {
|
||||
* Iterate all the service classes defined in /services,
|
||||
* load each service and register a Scoutcamp route for each service.
|
||||
*/
|
||||
registerServices() {
|
||||
async registerServices() {
|
||||
const { config, camp, metricInstance } = this
|
||||
const { apiProvider: githubApiProvider } = this.githubConstellation
|
||||
|
||||
loadServiceClasses().forEach(serviceClass =>
|
||||
;(await loadServiceClasses()).forEach(serviceClass =>
|
||||
serviceClass.register(
|
||||
{ camp, handleRequest, githubApiProvider, metricInstance },
|
||||
{
|
||||
@ -432,7 +436,7 @@ class Server {
|
||||
requireCloudflare,
|
||||
} = this.config.public
|
||||
|
||||
log(`Server is starting up: ${this.baseUrl}`)
|
||||
log.log(`Server is starting up: ${this.baseUrl}`)
|
||||
|
||||
const camp = (this.camp = Camp.create({
|
||||
documentRoot: this.config.public.documentRoot,
|
||||
@ -460,11 +464,11 @@ class Server {
|
||||
}
|
||||
|
||||
const { apiProvider: githubApiProvider } = this.githubConstellation
|
||||
suggest.setRoutes(allowedOrigin, githubApiProvider, camp)
|
||||
setRoutes(allowedOrigin, githubApiProvider, camp)
|
||||
|
||||
this.registerErrorHandlers()
|
||||
this.registerRedirects()
|
||||
this.registerServices()
|
||||
await this.registerServices()
|
||||
|
||||
camp.timeout = this.config.public.requestTimeoutSeconds * 1000
|
||||
if (this.config.public.requestTimeoutSeconds > 0) {
|
||||
@ -522,4 +526,4 @@ class Server {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Server
|
||||
export default Server
|
||||
|
@ -1,14 +1,13 @@
|
||||
'use strict'
|
||||
|
||||
const path = require('path')
|
||||
const { expect } = require('chai')
|
||||
const isSvg = require('is-svg')
|
||||
const config = require('config')
|
||||
const nock = require('nock')
|
||||
const sinon = require('sinon')
|
||||
const got = require('../got-test-client')
|
||||
const Server = require('./server')
|
||||
const { createTestServer } = require('./in-process-server-test-helpers')
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
import { expect } from 'chai'
|
||||
import isSvg from 'is-svg'
|
||||
import config from 'config'
|
||||
import nock from 'nock'
|
||||
import sinon from 'sinon'
|
||||
import got from '../got-test-client.js'
|
||||
import Server from './server.js'
|
||||
import { createTestServer } from './in-process-server-test-helpers.js'
|
||||
|
||||
describe('The server', function () {
|
||||
describe('running', function () {
|
||||
@ -18,7 +17,10 @@ describe('The server', function () {
|
||||
this.timeout(10000)
|
||||
server = await createTestServer({
|
||||
public: {
|
||||
documentRoot: path.resolve(__dirname, 'test-public'),
|
||||
documentRoot: path.resolve(
|
||||
path.dirname(fileURLToPath(import.meta.url)),
|
||||
'test-public'
|
||||
),
|
||||
},
|
||||
})
|
||||
baseUrl = server.baseUrl
|
||||
|
@ -54,19 +54,31 @@
|
||||
// Relying on npm scripts is safer. Using "pre" makes it impossible to run
|
||||
// the second step without the first.
|
||||
|
||||
'use strict'
|
||||
import minimist from 'minimist'
|
||||
import envFlag from 'node-env-flag'
|
||||
import readAllStdinSync from 'read-all-stdin-sync'
|
||||
import { createTestServer } from '../server/in-process-server-test-helpers.js'
|
||||
import Runner from './runner.js'
|
||||
|
||||
const minimist = require('minimist')
|
||||
const envFlag = require('node-env-flag')
|
||||
const readAllStdinSync = require('read-all-stdin-sync')
|
||||
const { createTestServer } = require('../server/in-process-server-test-helpers')
|
||||
const Runner = require('./runner')
|
||||
|
||||
require('../unhandled-rejection.spec')
|
||||
import('../unhandled-rejection.spec.js')
|
||||
|
||||
const retry = {}
|
||||
retry.count = parseInt(process.env.RETRY_COUNT) || 0
|
||||
retry.backoff = parseInt(process.env.RETRY_BACKOFF) || 0
|
||||
|
||||
const args = minimist(process.argv.slice(3))
|
||||
const stdinOption = args.stdin
|
||||
const onlyOption = args.only
|
||||
let onlyServices
|
||||
if (stdinOption && onlyOption) {
|
||||
console.error('Do not use --only with --stdin')
|
||||
} else if (stdinOption) {
|
||||
const allStdin = readAllStdinSync().trim()
|
||||
onlyServices = allStdin ? allStdin.split('\n') : []
|
||||
} else if (onlyOption) {
|
||||
onlyServices = onlyOption.split(',')
|
||||
}
|
||||
|
||||
let baseUrl, server
|
||||
if (process.env.TESTED_SERVER_URL) {
|
||||
baseUrl = process.env.TESTED_SERVER_URL
|
||||
@ -81,7 +93,7 @@ if (process.env.TESTED_SERVER_URL) {
|
||||
},
|
||||
},
|
||||
})
|
||||
server.start()
|
||||
await server.start()
|
||||
})
|
||||
after('Shut down the server', async function () {
|
||||
if (server) {
|
||||
@ -92,7 +104,7 @@ if (process.env.TESTED_SERVER_URL) {
|
||||
|
||||
const skipIntercepted = envFlag(process.env.SKIP_INTERCEPTED, false)
|
||||
const runner = new Runner({ baseUrl, skipIntercepted, retry })
|
||||
runner.prepare()
|
||||
await runner.prepare()
|
||||
|
||||
// The server's request cache causes side effects between tests.
|
||||
if (!process.env.TESTED_SERVER_URL) {
|
||||
@ -101,21 +113,6 @@ if (!process.env.TESTED_SERVER_URL) {
|
||||
}
|
||||
}
|
||||
|
||||
const args = minimist(process.argv.slice(3))
|
||||
const stdinOption = args.stdin
|
||||
const onlyOption = args.only
|
||||
|
||||
let onlyServices
|
||||
|
||||
if (stdinOption && onlyOption) {
|
||||
console.error('Do not use --only with --stdin')
|
||||
} else if (stdinOption) {
|
||||
const allStdin = readAllStdinSync().trim()
|
||||
onlyServices = allStdin ? allStdin.split('\n') : []
|
||||
} else if (onlyOption) {
|
||||
onlyServices = onlyOption.split(',')
|
||||
}
|
||||
|
||||
if (typeof onlyServices === 'undefined' || onlyServices.includes('*****')) {
|
||||
console.info('Running all service tests.')
|
||||
} else if (onlyServices.length === 0) {
|
||||
|
@ -1,11 +1,10 @@
|
||||
'use strict'
|
||||
/**
|
||||
* @module
|
||||
*/
|
||||
|
||||
const caller = require('caller')
|
||||
const BaseService = require('../base-service/base')
|
||||
const ServiceTester = require('./service-tester')
|
||||
import caller from 'caller'
|
||||
import BaseService from '../base-service/base.js'
|
||||
import ServiceTester from './service-tester.js'
|
||||
|
||||
/**
|
||||
* Automatically create a ServiceTester.
|
||||
@ -19,9 +18,9 @@ const ServiceTester = require('./service-tester')
|
||||
* @returns {module:core/service-test-runner/service-tester~ServiceTester}
|
||||
* ServiceTester instance
|
||||
*/
|
||||
function createServiceTester() {
|
||||
async function createServiceTester() {
|
||||
const servicePath = caller().replace('.tester.js', '.service.js')
|
||||
const ServiceClass = require(servicePath)
|
||||
const ServiceClass = Object.values(await import(servicePath))[0]
|
||||
if (!(ServiceClass.prototype instanceof BaseService)) {
|
||||
throw Error(
|
||||
`${servicePath} does not export a single service. Invoke new ServiceTester() directly.`
|
||||
@ -30,4 +29,4 @@ function createServiceTester() {
|
||||
return ServiceTester.forServiceClass(ServiceClass)
|
||||
}
|
||||
|
||||
module.exports = createServiceTester
|
||||
export default createServiceTester
|
||||
|
@ -1,10 +1,9 @@
|
||||
'use strict'
|
||||
/**
|
||||
* @module
|
||||
*/
|
||||
|
||||
const Joi = require('joi')
|
||||
const { expect } = require('chai')
|
||||
import Joi from 'joi'
|
||||
import { expect } from 'chai'
|
||||
|
||||
/**
|
||||
* Factory which wraps an "icedfrisby-nock" with some additional functionality:
|
||||
@ -85,4 +84,4 @@ const factory = superclass =>
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = factory
|
||||
export default factory
|
||||
|
@ -1,9 +1,8 @@
|
||||
'use strict'
|
||||
/**
|
||||
* @module
|
||||
*/
|
||||
|
||||
const { URL, format: urlFormat } = require('url')
|
||||
import { URL, format as urlFormat } from 'url'
|
||||
|
||||
function formatSlug(owner, repo, pullRequest) {
|
||||
return `${owner}/${repo}#${pullRequest}`
|
||||
@ -98,8 +97,4 @@ function inferPullRequest(env = process.env) {
|
||||
* @property {string} slug owner/repo/#pullRequest
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
parseGithubPullRequestUrl,
|
||||
parseGithubRepoSlug,
|
||||
inferPullRequest,
|
||||
}
|
||||
export { parseGithubPullRequestUrl, parseGithubRepoSlug, inferPullRequest }
|
||||
|
@ -1,10 +1,8 @@
|
||||
'use strict'
|
||||
|
||||
const { test, given, forCases } = require('sazerac')
|
||||
const {
|
||||
import { test, given, forCases } from 'sazerac'
|
||||
import {
|
||||
parseGithubPullRequestUrl,
|
||||
inferPullRequest,
|
||||
} = require('./infer-pull-request')
|
||||
} from './infer-pull-request.js'
|
||||
|
||||
describe('Pull request inference', function () {
|
||||
test(parseGithubPullRequestUrl, () => {
|
||||
|
@ -13,11 +13,9 @@
|
||||
//
|
||||
// TRAVIS=1 TRAVIS_REPO_SLUG=badges/shields TRAVIS_PULL_REQUEST=1108 npm run test:services:pr:prepare
|
||||
|
||||
'use strict'
|
||||
|
||||
const got = require('got')
|
||||
const { inferPullRequest } = require('./infer-pull-request')
|
||||
const servicesForTitle = require('./services-for-title')
|
||||
import got from 'got'
|
||||
import { inferPullRequest } from './infer-pull-request.js'
|
||||
import servicesForTitle from './services-for-title.js'
|
||||
|
||||
async function getTitle(owner, repo, pullRequest) {
|
||||
const {
|
||||
|
@ -1,9 +1,8 @@
|
||||
'use strict'
|
||||
/**
|
||||
* @module
|
||||
*/
|
||||
|
||||
const { loadTesters } = require('../base-service/loader')
|
||||
import { loadTesters } from '../base-service/loader.js'
|
||||
|
||||
/**
|
||||
* Load a collection of ServiceTester objects and register them with Mocha.
|
||||
@ -24,8 +23,10 @@ class Runner {
|
||||
/**
|
||||
* Prepare the runner by loading up all the ServiceTester objects.
|
||||
*/
|
||||
prepare() {
|
||||
this.testers = loadTesters()
|
||||
async prepare() {
|
||||
this.testers = (await loadTesters()).flatMap(testerModule =>
|
||||
Object.values(testerModule)
|
||||
)
|
||||
this.testers.forEach(tester => {
|
||||
tester.beforeEach = () => {
|
||||
this.beforeEach()
|
||||
@ -72,4 +73,4 @@ class Runner {
|
||||
testers.forEach(tester => tester.toss({ baseUrl, skipIntercepted, retry }))
|
||||
}
|
||||
}
|
||||
module.exports = Runner
|
||||
export default Runner
|
||||
|
@ -1,14 +1,13 @@
|
||||
'use strict'
|
||||
/**
|
||||
* @module
|
||||
*/
|
||||
|
||||
const emojic = require('emojic')
|
||||
const trace = require('../base-service/trace')
|
||||
const frisby = require('./icedfrisby-shields')(
|
||||
// eslint-disable-next-line import/order
|
||||
require('icedfrisby-nock')(require('icedfrisby'))
|
||||
)
|
||||
import emojic from 'emojic'
|
||||
import icedfrisbyNockModule from 'icedfrisby-nock'
|
||||
import icedfrisbyModule from 'icedfrisby'
|
||||
import trace from '../base-service/trace.js'
|
||||
import icedfrisbyShieldsModule from './icedfrisby-shields.js'
|
||||
const frisby = icedfrisbyShieldsModule(icedfrisbyNockModule(icedfrisbyModule))
|
||||
|
||||
/**
|
||||
* Encapsulate a suite of tests. Create new tests using create() and register
|
||||
@ -140,4 +139,4 @@ class ServiceTester {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ServiceTester
|
||||
export default ServiceTester
|
||||
|
@ -1,9 +1,8 @@
|
||||
'use strict'
|
||||
/**
|
||||
* @module
|
||||
*/
|
||||
|
||||
const difference = require('lodash.difference')
|
||||
import difference from 'lodash.difference'
|
||||
|
||||
/**
|
||||
* Given a pull request title like
|
||||
@ -31,4 +30,4 @@ function servicesForTitle(title) {
|
||||
return difference(services, ignored)
|
||||
}
|
||||
|
||||
module.exports = servicesForTitle
|
||||
export default servicesForTitle
|
||||
|
@ -1,7 +1,5 @@
|
||||
'use strict'
|
||||
|
||||
const { test, given } = require('sazerac')
|
||||
const servicesForTitle = require('./services-for-title')
|
||||
import { test, given } from 'sazerac'
|
||||
import servicesForTitle from './services-for-title.js'
|
||||
|
||||
describe('Services from PR title', function () {
|
||||
test(servicesForTitle, () => {
|
||||
|
@ -1,9 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
const RedisServer = require('redis-server')
|
||||
const Redis = require('ioredis')
|
||||
const { expect } = require('chai')
|
||||
const RedisTokenPersistence = require('./redis-token-persistence')
|
||||
import RedisServer from 'redis-server'
|
||||
import Redis from 'ioredis'
|
||||
import { expect } from 'chai'
|
||||
import RedisTokenPersistence from './redis-token-persistence.js'
|
||||
|
||||
describe('Redis token persistence', function () {
|
||||
let server
|
||||
|
@ -1,10 +1,8 @@
|
||||
'use strict'
|
||||
import { URL } from 'url'
|
||||
import Redis from 'ioredis'
|
||||
import log from '../server/log.js'
|
||||
|
||||
const { URL } = require('url')
|
||||
const Redis = require('ioredis')
|
||||
const log = require('../server/log')
|
||||
|
||||
module.exports = class RedisTokenPersistence {
|
||||
export default class RedisTokenPersistence {
|
||||
constructor({ url, key }) {
|
||||
this.url = url
|
||||
this.key = key
|
||||
|
@ -1,10 +1,9 @@
|
||||
'use strict'
|
||||
/**
|
||||
* @module
|
||||
*/
|
||||
|
||||
const crypto = require('crypto')
|
||||
const PriorityQueue = require('priorityqueuejs')
|
||||
import crypto from 'crypto'
|
||||
import PriorityQueue from 'priorityqueuejs'
|
||||
|
||||
/**
|
||||
* Compute a one-way hash of the input string.
|
||||
@ -354,8 +353,4 @@ class TokenPool {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
sanitizeToken,
|
||||
Token,
|
||||
TokenPool,
|
||||
}
|
||||
export { sanitizeToken, Token, TokenPool }
|
||||
|
@ -1,9 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
const { expect } = require('chai')
|
||||
const sinon = require('sinon')
|
||||
const times = require('lodash.times')
|
||||
const { Token, TokenPool } = require('./token-pool')
|
||||
import { expect } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import times from 'lodash.times'
|
||||
import { Token, TokenPool } from './token-pool.js'
|
||||
|
||||
function expectPoolToBeExhausted(pool) {
|
||||
expect(() => {
|
||||
|
@ -1,5 +1,3 @@
|
||||
'use strict'
|
||||
|
||||
// Cause unhandled promise rejections to fail unit tests, and print with stack
|
||||
// traces.
|
||||
process.on('unhandledRejection', error => {
|
||||
|
@ -1,5 +1,3 @@
|
||||
'use strict'
|
||||
|
||||
describe('Main page', function () {
|
||||
const backendUrl = Cypress.env('backend_url')
|
||||
const SEARCH_INPUT = 'input[placeholder="search / project URL"]'
|
||||
|
@ -131,7 +131,7 @@ if (allFiles.length > 100) {
|
||||
)
|
||||
}
|
||||
|
||||
if (diff.includes("require('@hapi/joi')")) {
|
||||
if (diff.includes("from '@hapi/joi'")) {
|
||||
fail(
|
||||
[
|
||||
`Found import of '@hapi/joi' in \`${file}\`. <br>`,
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user