|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const path = require('path') |
| 4 | +const execa = require('execa') |
| 5 | +const { createFactory } = require('ipfsd-ctl') |
| 6 | +const df = createFactory({ |
| 7 | + ipfsClientModule: require('ipfs-client'), |
| 8 | + ipfsBin: require.resolve('ipfs/src/cli.js') |
| 9 | +}) |
| 10 | +const { |
| 11 | + startServer |
| 12 | +} = require('test-ipfs-example/utils') |
| 13 | +const pkg = require('./package.json') |
| 14 | + |
| 15 | +async function testUI (url, http, grpc, id) { |
| 16 | + 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')], { |
| 17 | + cwd: path.resolve(__dirname, '../'), |
| 18 | + env: { |
| 19 | + ...process.env, |
| 20 | + CI: true, |
| 21 | + IPFS_EXAMPLE_TEST_URL: url, |
| 22 | + IPFS_GRPC_API_MULTIADDR: grpc, |
| 23 | + IPFS_HTTP_API_MULTIADDR: http |
| 24 | + }, |
| 25 | + all: true |
| 26 | + }) |
| 27 | + proc.all.on('data', (data) => { |
| 28 | + process.stdout.write(data) |
| 29 | + }) |
| 30 | + |
| 31 | + await proc |
| 32 | +} |
| 33 | + |
| 34 | +async function runTest () { |
| 35 | + const app = await startServer(__dirname) |
| 36 | + const daemon = await df.spawn({ |
| 37 | + type: 'js', |
| 38 | + test: true, |
| 39 | + ipfsOptions: { |
| 40 | + config: { |
| 41 | + Addresses: { |
| 42 | + API: '/ip4/127.0.0.1/tcp/0', |
| 43 | + RPC: '/ip4/127.0.0.1/tcp/0' |
| 44 | + }, |
| 45 | + API: { |
| 46 | + HTTPHeaders: { |
| 47 | + 'Access-Control-Allow-Origin': [ |
| 48 | + app.url |
| 49 | + ] |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + }) |
| 55 | + |
| 56 | + try { |
| 57 | + await testUI(app.url, daemon.apiAddr, daemon.grpcAddr, daemon.api.peerId.id) |
| 58 | + } finally { |
| 59 | + await daemon.stop() |
| 60 | + await app.stop() |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +module.exports = runTest |
| 65 | + |
| 66 | +module.exports[pkg.name] = function (browser) { |
| 67 | + browser |
| 68 | + .url(process.env.IPFS_EXAMPLE_TEST_URL) |
| 69 | + .waitForElementVisible('#grpc-input') |
| 70 | + .clearValue('#grpc-input') |
| 71 | + .setValue('#grpc-input', process.env.IPFS_GRPC_API_MULTIADDR) |
| 72 | + .pause(1000) |
| 73 | + .waitForElementVisible('#http-input') |
| 74 | + .clearValue('#http-input') |
| 75 | + .setValue('#http-input', process.env.IPFS_HTTP_API_MULTIADDR) |
| 76 | + .pause(1000) |
| 77 | + .click('#connect-submit') |
| 78 | + |
| 79 | + browser.expect.element('#output').text.to.contain('Added file: file-0.txt QmUDLiEJwL3vUhhXNXDF2RrCnVkSB2LemWYffpCCPcQCeU') |
| 80 | + |
| 81 | + browser.end() |
| 82 | +} |
0 commit comments