This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: update http client examples (#3172)
Moves http client examples to the examples folder and adds tests to prevent regressions.
- Loading branch information
1 parent
f3f8d2a
commit 5b5eabc
Showing
77 changed files
with
753 additions
and
435 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "example-http-client-browser-pubsub-example", | ||
"version": "0.0.0", | ||
"description": "An example demonstrating pubsub in the browser", | ||
"private": true, | ||
"main": "index.js", | ||
"scripts": { | ||
"build": "parcel build index.html --public-url ./", | ||
"start": "parcel index.html -p 8888", | ||
"test": "test-ipfs-example" | ||
}, | ||
"author": "Alan Shaw", | ||
"license": "MIT", | ||
"dependencies": { | ||
"ipfs-http-client": "^44.3.0" | ||
}, | ||
"browserslist": [ | ||
"last 2 versions and not dead and > 2%" | ||
], | ||
"devDependencies": { | ||
"execa": "^4.0.0", | ||
"go-ipfs": "^0.6.0", | ||
"ipfs": "^0.47.0", | ||
"ipfsd-ctl": "^4.1.1", | ||
"parcel-bundler": "^1.12.4", | ||
"test-ipfs-example": "^2.0.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
'use strict' | ||
|
||
const path = require('path') | ||
const execa = require('execa') | ||
const { createFactory } = require('ipfsd-ctl') | ||
const df = createFactory({ | ||
ipfsHttpModule: require('ipfs-http-client'), | ||
}, { | ||
js: { | ||
ipfsBin: require.resolve('ipfs/src/cli/bin.js') | ||
}, | ||
go: { | ||
ipfsBin: require('go-ipfs').path(), | ||
args: ['--enable-pubsub-experiment'] | ||
} | ||
}) | ||
const { | ||
startServer | ||
} = require('test-ipfs-example/utils') | ||
const pkg = require('./package.json') | ||
|
||
async function testUI (url, id, apiAddr, peerAddr, topic) { | ||
const proc = execa(require.resolve('test-ipfs-example/node_modules/.bin/nightwatch'), ['--config', require.resolve('test-ipfs-example/nightwatch.conf.js'), path.join(__dirname, 'test.js')], { | ||
cwd: path.resolve(__dirname, '../'), | ||
env: { | ||
...process.env, | ||
CI: true, | ||
IPFS_EXAMPLE_TEST_URL: url, | ||
IPFS_API_ADDRESS: apiAddr, | ||
IPFS_ID: id, | ||
IPFS_PEER_ADDRESS: peerAddr, | ||
IPFS_TOPIC: topic | ||
}, | ||
all: true | ||
}) | ||
proc.all.on('data', (data) => { | ||
process.stdout.write(data) | ||
}) | ||
|
||
await proc | ||
} | ||
|
||
async function runTest () { | ||
const app1 = await startServer(__dirname) | ||
const app2 = await startServer(__dirname) | ||
const js = await df.spawn({ | ||
type: 'js', | ||
test: true, | ||
ipfsOptions: { | ||
config: { | ||
Addresses: { | ||
API: '/ip4/127.0.0.1/tcp/0' | ||
}, | ||
API: { | ||
HTTPHeaders: { | ||
'Access-Control-Allow-Origin': [ | ||
app1.url | ||
] | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
const go = await df.spawn({ | ||
type: 'go', | ||
test: true, | ||
ipfsOptions: { | ||
config: { | ||
Addresses: { | ||
API: '/ip4/127.0.0.1/tcp/0' | ||
}, | ||
API: { | ||
HTTPHeaders: { | ||
'Access-Control-Allow-Origin': [ | ||
app2.url | ||
] | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
|
||
const topic = `topic-${Math.random()}` | ||
|
||
try { | ||
await Promise.all([ | ||
testUI(app1.url, js.api.peerId.id, js.apiAddr, go.api.peerId.addresses[0].toString(), topic), | ||
testUI(app2.url, go.api.peerId.id, go.apiAddr, js.api.peerId.addresses[0].toString(), topic) | ||
]) | ||
} finally { | ||
await js.stop() | ||
await go.stop() | ||
await app1.stop() | ||
await app2.stop() | ||
} | ||
} | ||
|
||
module.exports = runTest | ||
|
||
module.exports[pkg.name] = function (browser) { | ||
browser | ||
.url(process.env.IPFS_EXAMPLE_TEST_URL) | ||
.waitForElementVisible('#api-url') | ||
.clearValue('#api-url') | ||
.setValue('#api-url', process.env.IPFS_API_ADDRESS) | ||
.pause(1000) | ||
.click('#node-connect') | ||
|
||
browser.expect.element('#console').text.to.contain(`Connecting to ${process.env.IPFS_API_ADDRESS}\nSuccess!`) | ||
|
||
// connect to peer | ||
browser | ||
.waitForElementVisible('#peer-addr') | ||
.clearValue('#peer-addr') | ||
.setValue('#peer-addr', process.env.IPFS_PEER_ADDRESS) | ||
.pause(1000) | ||
.click('#peer-connect') | ||
|
||
browser.expect.element('#console').text.to.contain(`Connecting to peer ${process.env.IPFS_PEER_ADDRESS}\nSuccess!`) | ||
|
||
// subscribe to topic | ||
browser | ||
.waitForElementVisible('#topic') | ||
.clearValue('#topic') | ||
.setValue('#topic', process.env.IPFS_TOPIC) | ||
.pause(1000) | ||
.click('#subscribe') | ||
|
||
browser.expect.element('#console').text.to.contain(`Subscribing to ${process.env.IPFS_TOPIC}...\nSuccess!`) | ||
|
||
// send a message | ||
browser | ||
.waitForElementVisible('#message') | ||
.clearValue('#message') | ||
.setValue('#message', 'hello') | ||
.pause(1000) | ||
.click('#send') | ||
|
||
const remotePeerId = process.env.IPFS_PEER_ADDRESS.split('/').pop() | ||
|
||
browser.expect.element('#console').text.to.contain(`from ${remotePeerId}:\n"hello"`) | ||
|
||
browser.end() | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "example-http-client-bundle-webpack", | ||
"version": "1.0.0", | ||
"description": "Bundle js-ipfs-http-client with Webpack", | ||
"scripts": { | ||
"clean": "rm -rf ./dist", | ||
"build": "webpack", | ||
"start": "node server.js", | ||
"test": "test-ipfs-example" | ||
}, | ||
"author": "Victor Bjelkholm <victor@ipfs.io>", | ||
"license": "MIT", | ||
"keywords": [], | ||
"dependencies": { | ||
"ipfs-http-client": "^44.3.0", | ||
"react": "^16.8.6", | ||
"react-dom": "^16.8.6" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.2.2", | ||
"@babel/preset-env": "^7.3.1", | ||
"@babel/preset-react": "^7.0.0", | ||
"babel-loader": "^8.0.5", | ||
"copy-webpack-plugin": "^5.0.4", | ||
"execa": "^4.0.0", | ||
"ipfs": "^0.47.0", | ||
"ipfsd-ctl": "^4.1.1", | ||
"react-hot-loader": "^4.12.21", | ||
"test-ipfs-example": "^2.0.3", | ||
"webpack": "^4.43.0", | ||
"webpack-dev-server": "^3.11.0" | ||
}, | ||
"browserslist": [ | ||
"last 2 versions and not dead and > 2%" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict' | ||
|
||
const webpack = require('webpack') | ||
const WebpackDevServer = require('webpack-dev-server') | ||
const config = require('./webpack.config') | ||
|
||
const wds = new WebpackDevServer(webpack(config), { | ||
hot: true, | ||
historyApiFallback: true | ||
}) | ||
|
||
wds.listen(8888, 'localhost', (err) => { | ||
if (err) { | ||
throw err | ||
} | ||
|
||
console.log('Listening at localhost:8888') | ||
}) |
Oops, something went wrong.