Skip to content

Commit

Permalink
test: update proxy setup (#429)
Browse files Browse the repository at this point in the history
* build: remove --no-clean flag

* test: update proxy

* test: use a different facebook video url

* build: force
  • Loading branch information
Kikobeats authored Jun 29, 2021
1 parent 8ddcca0 commit 583107d
Show file tree
Hide file tree
Showing 22 changed files with 42 additions and 33 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ jobs:
run: npm install --no-package-lock
- name: Test
run: npm test
env:
PROXY_USERNAME: ${{ secrets.PROXY_USERNAME }}
PROXY_PASSWORD: ${{ secrets.PROXY_PASSWORD }}
PROXY_HOST: ${{ secrets.PROXY_HOST }}
- name: Report
run: mkdir -p coverage && npx nyc report --reporter=text-lcov > coverage/lcov.info
- name: Coverage
Expand Down
2 changes: 1 addition & 1 deletion packages/metascraper-amazon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"index.js"
],
"scripts": {
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --no-clean --temp-dir ../../.nyc_output mocha test"
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --temp-dir ../../.nyc_output mocha test"
},
"license": "MIT"
}
2 changes: 1 addition & 1 deletion packages/metascraper-audio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"index.js"
],
"scripts": {
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --no-clean --temp-dir ../../.nyc_output mocha test"
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --temp-dir ../../.nyc_output mocha test"
},
"license": "MIT"
}
2 changes: 1 addition & 1 deletion packages/metascraper-clearbit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"index.js"
],
"scripts": {
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --no-clean --temp-dir ../../.nyc_output mocha test"
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --temp-dir ../../.nyc_output mocha test"
},
"license": "MIT",
"mocha": {
Expand Down
2 changes: 1 addition & 1 deletion packages/metascraper-description/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"index.js"
],
"scripts": {
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --no-clean --temp-dir ../../.nyc_output mocha test"
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --temp-dir ../../.nyc_output mocha test"
},
"license": "MIT"
}
2 changes: 1 addition & 1 deletion packages/metascraper-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"index.js"
],
"scripts": {
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --no-clean --temp-dir ../../.nyc_output mocha test"
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --temp-dir ../../.nyc_output mocha test"
},
"license": "MIT"
}
2 changes: 1 addition & 1 deletion packages/metascraper-iframe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"src"
],
"scripts": {
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --no-clean --temp-dir ../../.nyc_output mocha test"
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --temp-dir ../../.nyc_output mocha test"
},
"license": "MIT",
"mocha": {
Expand Down
2 changes: 1 addition & 1 deletion packages/metascraper-instagram/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"index.js"
],
"scripts": {
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --no-clean --temp-dir ../../.nyc_output mocha test"
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --temp-dir ../../.nyc_output mocha test"
},
"license": "MIT",
"mocha": {
Expand Down
2 changes: 1 addition & 1 deletion packages/metascraper-lang/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"index.js"
],
"scripts": {
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --no-clean --temp-dir ../../.nyc_output mocha test"
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --temp-dir ../../.nyc_output mocha test"
},
"license": "MIT"
}
2 changes: 1 addition & 1 deletion packages/metascraper-logo-favicon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"index.js"
],
"scripts": {
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --no-clean --temp-dir ../../.nyc_output mocha test"
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --temp-dir ../../.nyc_output mocha test"
},
"license": "MIT",
"mocha": {
Expand Down
2 changes: 1 addition & 1 deletion packages/metascraper-media-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"src"
],
"scripts": {
"test": "NODE_PATH=.. TZ=UTC DEBUG=metascraper*,-metascraper-media-provider:provider* NODE_ENV=test nyc --silent --no-clean --temp-dir ../../.nyc_output mocha test"
"test": "NODE_PATH=.. TZ=UTC DEBUG=metascraper*,-metascraper-media-provider:provider* NODE_ENV=test nyc --silent --temp-dir ../../.nyc_output mocha test"
},
"license": "MIT",
"mocha": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = ({
getProxy = constant(false),
onError = noop,
timeout = 30000,
retry = 5,
retry = 2,
userAgent,
...props
}) => {
Expand All @@ -38,7 +38,7 @@ module.exports = ({
let data = {}
let isTimeout = false

const condition = () => !isTimeout && isEmpty(data) && retryCount < retry
const condition = () => !isTimeout && isEmpty(data) && retryCount <= retry

const task = async () => {
await pDoWhilst(async () => {
Expand Down
29 changes: 17 additions & 12 deletions packages/metascraper-media-provider/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,32 @@

const debug = require('debug-logfmt')('metascraper-media-provider:test')
const { getDomainWithoutSuffix } = require('tldts')
const parseProxy = require('parse-proxy-uri')
const parseProxyUri = require('parse-proxy-uri')
const snapshot = require('snap-shot')
const should = require('should')
const isCI = require('is-ci')

const proxy = parseProxy(process.env.PROXY_URI)
const { PROXY_PASSWORD, PROXY_USERNAME, PROXY_HOST } = process.env

const PROXY_DOMAINS = ['vimeo']
const proxy =
PROXY_PASSWORD && PROXY_USERNAME && PROXY_HOST
? parseProxyUri(
`socks5://${PROXY_USERNAME}:${PROXY_PASSWORD}@${PROXY_HOST}`
)
: undefined

const PROXY_DOMAINS = ['vimeo', 'facebook']
const PROXY_URLS = ['https://api.twitter.com/1.1/guest/activate.json']

const getProxy = ({ url, retryCount = 1 }) => {
if (retryCount === 0) return false
const getProxy = ({ url, retryCount }) => {
if (retryCount !== 1) return false
if (PROXY_URLS.includes(url)) return proxy
if (PROXY_DOMAINS.includes(getDomainWithoutSuffix(url))) return proxy
return false
}

const metascraper = require('metascraper')([
require('..')({ getProxy, timeout: 10000 }),
require('..')({ getProxy, timeout: 15000 }),
require('metascraper-publisher')(),
require('metascraper-author')(),
require('metascraper-date')(),
Expand Down Expand Up @@ -68,7 +75,7 @@ describe('metascraper-media-provider', () => {
})
})
})
;(isCI ? describe.skip : describe)('vimeo', () => {
;(isCI ? describe.skip : describe.only)('vimeo', () => {
;[
// TODO: uncomment when the issue is resolved
// https://github.com/ytdl-org/youtube-dl/issues/29205
Expand Down Expand Up @@ -121,10 +128,9 @@ describe('metascraper-media-provider', () => {
should(isUrl(metadata.video)).be.false()
})
})

describe('facebook', () => {
;(isCI ? describe.skip : describe)('facebook', () => {
;[
'https://www.facebook.com/afcajax/videos/1686831701364171',
'https://www.facebook.com/natgeo/videos/10156364216738951/',
'https://www.facebook.com/cnn/videos/10157803903591509/'
].forEach(url => {
it(url, async () => {
Expand All @@ -146,8 +152,7 @@ describe('metascraper-media-provider', () => {
})
})
})

describe('facebook', () => {
;(isCI ? describe.skip : describe)('facebook', () => {
;[
'https://www.facebook.com/afcajax/videos/1686831701364171',
'https://www.facebook.com/cnn/videos/10157803903591509/'
Expand Down
2 changes: 1 addition & 1 deletion packages/metascraper-publisher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"index.js"
],
"scripts": {
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --no-clean --temp-dir ../../.nyc_output mocha test"
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --temp-dir ../../.nyc_output mocha test"
},
"license": "MIT"
}
2 changes: 1 addition & 1 deletion packages/metascraper-readability/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"index.js"
],
"scripts": {
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --no-clean --temp-dir ../../.nyc_output mocha test"
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --temp-dir ../../.nyc_output mocha test"
},
"license": "MIT",
"mocha": {
Expand Down
2 changes: 1 addition & 1 deletion packages/metascraper-soundcloud/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"index.js"
],
"scripts": {
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --no-clean --temp-dir ../../.nyc_output mocha test"
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --temp-dir ../../.nyc_output mocha test"
},
"license": "MIT"
}
2 changes: 1 addition & 1 deletion packages/metascraper-spotify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"index.js"
],
"scripts": {
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --no-clean --temp-dir ../../.nyc_output mocha test"
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --temp-dir ../../.nyc_output mocha test"
},
"license": "MIT"
}
2 changes: 1 addition & 1 deletion packages/metascraper-telegram/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"index.js"
],
"scripts": {
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --no-clean --temp-dir ../../.nyc_output mocha test"
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --temp-dir ../../.nyc_output mocha test"
},
"license": "MIT",
"mocha": {
Expand Down
2 changes: 1 addition & 1 deletion packages/metascraper-uol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"index.js"
],
"scripts": {
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --no-clean --temp-dir ../../.nyc_output mocha test"
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --temp-dir ../../.nyc_output mocha test"
},
"license": "MIT"
}
2 changes: 1 addition & 1 deletion packages/metascraper-video/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"index.js"
],
"scripts": {
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --no-clean --temp-dir ../../.nyc_output mocha test"
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --temp-dir ../../.nyc_output mocha test"
},
"license": "MIT"
}
2 changes: 1 addition & 1 deletion packages/metascraper-youtube/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"index.js"
],
"scripts": {
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --no-clean --temp-dir ../../.nyc_output mocha test"
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --temp-dir ../../.nyc_output mocha test"
},
"license": "MIT"
}
2 changes: 1 addition & 1 deletion packages/metascraper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"src"
],
"scripts": {
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --no-clean --temp-dir ../../.nyc_output mocha test"
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc --silent --temp-dir ../../.nyc_output mocha test"
},
"license": "MIT",
"mocha": {
Expand Down

0 comments on commit 583107d

Please sign in to comment.