Skip to content

Commit

Permalink
Merge pull request #39 from mykelp/master
Browse files Browse the repository at this point in the history
Update to run testRPC on an open port
  • Loading branch information
pfletcherhill authored Feb 21, 2018
2 parents 8584658 + a00afb7 commit 81e74ad
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"mocha": "^5.0.1",
"mocha-better-spec-reporter": "^3.1.0",
"mocha-parallel-tests": "^1.2.10",
"portfinder": "^1.0.13",
"truffle": "^4.0.5",
"truffle-artifactor": "^3.0.3",
"truffle-compile": "^3.0.5",
Expand Down
6 changes: 4 additions & 2 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ program
.option("-w, --watch", "Watch tests")
.option("-v, --verbose", "Verbose tests")
.option("-f, --fun", "Fun tests")
.option("-p, --port [port]", "Port number to launch test RPC on")
.action(function(path) {
testPath = path;
})
Expand All @@ -29,8 +30,9 @@ if (program.watch) {

const instance = new Espresso({
testPath,
watch: program.watch,
reporter
reporter,
port: program.port,
watch: program.watch
});

global = Object.assign(global, instance.globalScope);
Expand Down
4 changes: 3 additions & 1 deletion src/espresso.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export default class Espresso {
this.testPath = options.testPath || ".";
this.watch = options.watch;
this.reporter = options.reporter;
this.server = new Server();
this.server = new Server({
port: options.port
});
this.mocha = new MochaParallel();
//this.mocha = new Mocha();
}
Expand Down
17 changes: 11 additions & 6 deletions src/server.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import Ganache from "ganache-core";
import Web3 from "web3";
import { Profiler, Contracts, Migrate } from "./truffle/external";
import portfinder from "portfinder";

export default class Server {
constructor() {
constructor(options = {}) {
this.ganache = Ganache.server({
default_balance_ether: 1000
});
this.web3 = new Web3();
this.accounts = [];
portfinder.basePort = options.port || 8545;
}

async start() {
await this.ganache.listen(8545, (err, chain) => {
if (err) {
console.log("Error: ", err);
}
});
this.port = await portfinder.getPortPromise();

try {
await this.ganache.listen(this.port);
console.log("Launched test RPC on port: ", this.port);
} catch (err) {
console.log("Error: ", err);
}
this.web3.setProvider(this.ganache.provider);
this.accounts = await this.getAccounts();
}
Expand Down
10 changes: 9 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3396,7 +3396,7 @@ mississippi@^2.0.0:
stream-each "^1.1.0"
through2 "^2.0.0"

[email protected], "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1:
[email protected], [email protected], "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
dependencies:
Expand Down Expand Up @@ -4093,6 +4093,14 @@ pinkie@^2.0.0:
version "2.0.4"
resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870"

portfinder@^1.0.13:
version "1.0.13"
resolved "https://registry.yarnpkg.com/portfinder/-/portfinder-1.0.13.tgz#bb32ecd87c27104ae6ee44b5a3ccbf0ebb1aede9"
dependencies:
async "^1.5.2"
debug "^2.2.0"
mkdirp "0.5.x"

prepend-file@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/prepend-file/-/prepend-file-1.3.1.tgz#83b16e0b4ac1901fce88dbd945a22f4cc81df579"
Expand Down

0 comments on commit 81e74ad

Please sign in to comment.