Skip to content

Commit

Permalink
Update development methodologies to the current year
Browse files Browse the repository at this point in the history
  • Loading branch information
queicherius committed Sep 25, 2018
1 parent 7798863 commit 026de8f
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 222 deletions.
7 changes: 1 addition & 6 deletions .babelrc 100644 → 100755
@@ -1,14 +1,9 @@
{
"presets": [
["env", {"targets": {"browsers": ["last 2 versions", "> 5%"], "node": 6}, "loose": true}],
"stage-0"
],
"env": {
"test": {
"plugins": [
["istanbul", {"include": ["src/**"]}],
"rewire"
]
}
}
}
}
6 changes: 1 addition & 5 deletions .gitignore 100644 → 100755
Expand Up @@ -3,10 +3,6 @@ npm-debug.log*

# Coverage directories
coverage/
.nyc_output/

# Compiled code
build/

# Dependencies
node_modules/
Expand All @@ -19,4 +15,4 @@ node_modules/

# Operating System
.DS_Store
Thumbs.db
Thumbs.db
22 changes: 0 additions & 22 deletions .npmignore

This file was deleted.

6 changes: 3 additions & 3 deletions .travis.yml 100644 → 100755
@@ -1,8 +1,8 @@
language: node_js
node_js:
- "6"
after_script: "$(npm bin)/codecov"
- "8"
after_script: "curl -s https://codecov.io/bash | bash"
branches:
only:
- master
- /^greenkeeper.*$/
- /^greenkeeper.*$/
Empty file modified LICENCE 100644 → 100755
Empty file.
6 changes: 3 additions & 3 deletions README.md 100644 → 100755
Expand Up @@ -16,7 +16,7 @@ This module can be used for Node.js as well as browsers using [Browserify](https
## Usage

```js
import fetch from 'lets-fetch'
const fetch = require('lets-fetch')

// Async / await
async function myFunction () {
Expand Down Expand Up @@ -110,8 +110,8 @@ fetch.retryWait(tries => tries * 100)
If you want to mock `lets-fetch` in your tests, you can replace it with the included basic mock module, e.g. using [rewire](https://github.com/speedskater/babel-plugin-rewire).

```js
import mock from 'lets-fetch/mock'
import myModule from './test.js'
const mock = require('lets-fetch/mock')
const myModule = require('./test.js')

// Overwrite the "fetch" variable in the module to test
myModule.__set__('fetch', mock)
Expand Down
4 changes: 2 additions & 2 deletions mock.js 100644 → 100755
@@ -1,4 +1,4 @@
// This is just a helper file to support the syntax sugar:
// import mock from 'lets-fetch/mock'
// const mock = require('lets-fetch/mock')

module.exports = require('./build/mock.js')
module.exports = require('./src/mock.js')
16 changes: 8 additions & 8 deletions package.json 100644 → 100755
Expand Up @@ -2,11 +2,9 @@
"name": "lets-fetch",
"version": "2.1.0",
"description": "Single and parallel requests with retrying and error handling.",
"main": "./build/index.js",
"main": "./src/index.js",
"scripts": {
"build": "abc build",
"test": "abc test && abc lint",
"version": "abc build"
"test": "jest --coverage && standard"
},
"author": "queicherius@gmail.com",
"license": "MIT",
Expand All @@ -15,11 +13,13 @@
"url": "https://github.com/queicherius/lets-fetch"
},
"dependencies": {
"isomorphic-fetch": "^2.2.1",
"promise-control-flow": "^1.2.3"
"node-fetch": "^2.2.0",
"promise-control-flow": "^1.2.5"
},
"devDependencies": {
"abc-environment": "^2.0.0",
"fetch-mock": "^5.5.0"
"babel-plugin-rewire": "^1.2.0",
"fetch-mock": "5.5.0",
"jest": "^23.6.0",
"standard": "^12.0.1"
}
}
18 changes: 9 additions & 9 deletions src/index.js 100644 → 100755
@@ -1,5 +1,5 @@
import fetch from 'isomorphic-fetch'
import flow from 'promise-control-flow'
const fetch = require('node-fetch')
const flow = require('promise-control-flow')

const defaultOptions = {
type: 'json',
Expand All @@ -11,22 +11,22 @@ const defaultOptions = {
let internalRetry = () => false
let internalRetryWait = () => false

export default {retry, retryWait, single, many}
module.exports = { retry, retryWait, single, many }

// Set a custom decider function that decides to retry
// based on the number of tries and the previous error
export function retry (decider) {
function retry (decider) {
internalRetry = decider
}

// Set a custom function that sets how long we should
// sleep between each failed request
export function retryWait (callback) {
function retryWait (callback) {
internalRetryWait = callback
}

// Request a single url
export function single (url, options = {}) {
function single (url, options = {}) {
let tries = 1

// Execute the request and retry if there are errors (and the
Expand All @@ -43,8 +43,8 @@ export function single (url, options = {}) {
}

// Send a request using the underlying fetch API
export function request (url, options) {
options = {...defaultOptions, ...options}
function request (url, options) {
options = { ...defaultOptions, ...options }
let savedContent
let savedResponse

Expand Down Expand Up @@ -96,7 +96,7 @@ export function request (url, options) {
}

// Request multiple pages
export function many (urls, options = {}) {
function many (urls, options = {}) {
let flowMethod = (options.waitTime) ? flow.series : flow.parallel

// Call the single method while respecting the wait time in between tasks
Expand Down
26 changes: 13 additions & 13 deletions src/mock.js 100644 → 100755
@@ -1,12 +1,12 @@
import fetch from './index.js'
import flow from 'promise-control-flow'
const fetch = require('./index.js')
const flow = require('promise-control-flow')

let reqResponses = []
let reqOptions = []
let reqUrls = []
let mockingEnabled = true

export default {
module.exports = {
addResponse,
addResponseError,
reset,
Expand All @@ -19,46 +19,46 @@ export default {
many
}

export function addResponse (content) {
function addResponse (content) {
reqResponses.push(content)
}

export function addResponseError (response, content) {
function addResponseError (response, content) {
const responseError = new Error('Status ' + response.status)
responseError.response = response
responseError.content = content

reqResponses.push(responseError)
}

export function reset () {
function reset () {
reqResponses = []
reqOptions = []
reqUrls = []
fetch.retry(() => false)
}

export function urls () {
function urls () {
return reqUrls
}

export function options () {
function options () {
return reqOptions
}

export function lastUrl () {
function lastUrl () {
return reqUrls[reqUrls.length - 1]
}

export function lastOption () {
function lastOption () {
return reqOptions[reqOptions.length - 1]
}

export function enableMocking (bool) {
function enableMocking (bool) {
mockingEnabled = bool
}

export function single (url, opt) {
function single (url, opt) {
reqUrls.push(url)
reqOptions.push(opt)

Expand All @@ -77,7 +77,7 @@ export function single (url, opt) {
})
}

export function many (urls, opt) {
function many (urls, opt) {
if (!mockingEnabled) {
reqUrls = reqUrls.concat(urls)
reqOptions = reqOptions.concat(opt)
Expand Down

0 comments on commit 026de8f

Please sign in to comment.