mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-10 13:55:45 +00:00
ad01d1402c
Implement scripts to collect coverage reports (JSON format) from all packages in the monorepo that generate such reports. Reports are copied to `<root>/.nyc_output/coverage-[pkg-dir-name].json`. Implement scripts to generate a combined html report in `<root>/coverage`. Adjust root `reset` and `clean` scripts to delete `<root>/.nyc_output` and `<root>/coverage`. Implement a script in `<root>/package.json` to generate a `text-lcov` report and upload it to coveralls from CI builds. Remove coveralls from `packages/embark`. Supply `packages/embark` with an nyc configuration in its `package.json` and have its `"test":` script generate both `json` and `html` reports. Use nyc with `embarkjs`'s test suite: supply an nyc configuration in its `package.json` and have its `"test":` script generate both `json` and `html` reports. Adjust `embarkjs`'s tests for more accurate coverage reporting.
78 lines
2.3 KiB
JavaScript
78 lines
2.3 KiB
JavaScript
/* global before describe it require */
|
|
|
|
const {startRPCMockServer, TestProvider} = require('./helpers/blockchain');
|
|
const {assert} = require('chai');
|
|
const {Blockchain} = require('..');
|
|
const {promisify} = require('util');
|
|
|
|
describe('Blockchain', () => {
|
|
describe('#connect', () => {
|
|
before(() => {
|
|
Blockchain.registerProvider('web3', TestProvider);
|
|
Blockchain.setProvider('web3', {});
|
|
});
|
|
|
|
const scenarios = [
|
|
{
|
|
description: 'should not keep trying other connections if connected',
|
|
servers: [true, true],
|
|
visited: [true, false],
|
|
error: false
|
|
},
|
|
{
|
|
description: 'should keep trying other connections if not connected',
|
|
servers: [false, true],
|
|
visited: [true, true],
|
|
error: false
|
|
},
|
|
{
|
|
description: 'should return error if no connections succeed',
|
|
servers: [false, false],
|
|
visited: [true, true],
|
|
error: true
|
|
}
|
|
];
|
|
|
|
scenarios.forEach(({description, ...scenario}) => {
|
|
it(description, async () => {
|
|
const makeServers = async () => {
|
|
const servers = await Promise.all(
|
|
scenario.servers.map(server => (
|
|
promisify(startRPCMockServer)({successful: server})
|
|
))
|
|
);
|
|
const dappConnection = servers.map(server => server.connectionString);
|
|
return {servers, dappConnection};
|
|
};
|
|
|
|
// test Blockchain.connect() using callback
|
|
let {servers, dappConnection} = await makeServers();
|
|
await new Promise((resolve, reject) => {
|
|
Blockchain.connect({dappConnection}, err => {
|
|
try {
|
|
assert(scenario.error ? err : !err);
|
|
servers.forEach((server, idx) => {
|
|
assert.strictEqual(server.visited, scenario.visited[idx]);
|
|
});
|
|
resolve();
|
|
} catch (e) {
|
|
reject(e);
|
|
}
|
|
});
|
|
});
|
|
|
|
// test Blockchain.connect() without callback
|
|
({servers, dappConnection} = await makeServers());
|
|
try {
|
|
await Blockchain.connect({dappConnection});
|
|
} catch (e) {
|
|
if (!scenario.error) throw e;
|
|
}
|
|
servers.forEach((server, idx) => {
|
|
assert.strictEqual(server.visited, scenario.visited[idx]);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|