Skip to content

Commit

Permalink
[test:input] Set up HTTP request mocking (#136)
Browse files Browse the repository at this point in the history
* [site:test] Fix browser tests again

expect.js doesn't play nicely with Babel, so it
shouldn't be transformed by Babelify.^1 Note that
the ignore option in Babelify is buggy ^2, so
this might not work on your end.

^1 Automattic/expect.js#149
^2 babel/babelify#265

* [test:input] Set up HTTP request mocking

Set up proper HTTP request mocking by mocking
exports with mock-require. Not possible in the
browser, but it wasn't before, so this counts
as an improvement.

Previously done by nock, but this didn't work for
requests made through sync-request, as that
spawns a child process over which nock has no
control.

See #68
See 509d911836c7cb7adbc57440ce21a703308e01ff
Close #134

* [test:input] Increase coverage of input plugins

See #123

* [package] Add non-npm patch to dependencies

See babel/babelify#267
  • Loading branch information
larsgw committed Nov 2, 2018
1 parent 6063205 commit 2b81604
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/logger.js
@@ -1,5 +1,5 @@
/* istanbul ignore else: coverage tools always in testing environment */
if (process.env.MOCHA === '1') {
if (process.env.TEST_MOCHA === 'true') {
// If testing from CLI, use noop logger, to not interfere with the mocha reporter
// (see issues mochajs/mocha#1998, mochajs/mocha#2107, etc.)

Expand Down
6 changes: 6 additions & 0 deletions src/parse/interface/index.js
@@ -1,3 +1,9 @@
import * as dataType from './dataType'
import * as graph from './graph'
import * as parser from './parser'

export const util = {...dataType, ...graph, ...parser}

export * from './register'

export * from './chain'
Expand Down
11 changes: 7 additions & 4 deletions src/parse/interface/parser.js
Expand Up @@ -3,7 +3,7 @@ import {type, typeMatcher} from './type'
export class TypeParser {
validDataTypes = ['String', 'Array', 'SimpleObject', 'ComplexObject', 'Primitive']

constructor (data = {}) {
constructor (data) {
this.data = data
}

Expand Down Expand Up @@ -47,6 +47,9 @@ export class TypeParser {
}

validate () {
if (this.data !== null && typeof this.data !== 'object') {
throw new TypeError(`typeParser was ${typeof this.data}; expected object`)
}
this.validateDataType()
this.validateParseType()
this.validatePropertyConstraint()
Expand All @@ -61,7 +64,7 @@ export class TypeParser {
parsePropertyConstraint () {
let constraints = [].concat(this.data.propertyConstraint || [])

return constraints.map(({props = [], match = 'every', value = () => true}) => {
return constraints.map(({props, match = 'every', value = () => true}) => {
props = [].concat(props)

return input => props[match](prop => prop in input && value(input[prop]))
Expand Down Expand Up @@ -129,7 +132,7 @@ export class TypeParser {
}

export class DataParser {
constructor (parser = {}, {async} = {}) {
constructor (parser, {async} = {}) {
this.parser = parser
this.async = async
}
Expand All @@ -140,7 +143,7 @@ export class DataParser {

validate () {
const parser = this.parser
if (parser && typeof parser !== 'function') {
if (typeof parser !== 'function') {
throw new TypeError(`parser was ${typeof parser}; expected function`)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/parse/interface/register.js
Expand Up @@ -145,7 +145,7 @@ export const hasFormat = (format) => format in formats
export const listFormat = () => Object.keys(formats)

// BEGIN compat
export const add = (...args) => {
export const add = /* istanbul ignore next: deprecated */ (...args) => {
logger.warn('This method is deprecated; use addFormat')
return addFormat(...args)
}
Expand Down
8 changes: 1 addition & 7 deletions src/parse/interface/type.js
Expand Up @@ -65,12 +65,6 @@ const matchType = (typeList = [], data) => {
export const type = (input) => {
const dataType = dataTypeOf(input)

if (!dataTypes.hasOwnProperty(dataType)) {
// TODO if no parsers registered, this warning is always thrown
logger.warn('[set]', 'Data type has no formats listed')
return parseNativeTypes(input, dataType)
}

// Empty array should be @csl/list+object too
if (dataType === 'Array' && input.length === 0) {
// Off-load to parseNativeTypes() to not repeat the name
Expand Down Expand Up @@ -174,7 +168,7 @@ export const listTypeParser = () => Object.keys(types)
*
* @return {Object} tree structure
*/
export const treeTypeParser = () => {
export const treeTypeParser = /* istanbul ignore next: debugging */ () => {
const attachNode = name => ({name, children: types[name].extensions.map(attachNode)})
return {
name: 'Type tree',
Expand Down

0 comments on commit 2b81604

Please sign in to comment.