Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Internal improvement: Update truffle test code #2081

Merged
merged 19 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b695264
Use synchronous form of node-dir method and pull out a callback
eggplantzzz Jun 6, 2019
3beb4ad
Use synchronous version of temp.mkdir method to remove another callback
eggplantzzz Jun 6, 2019
afb523e
Make a few minor stylistic edits to test
eggplantzzz Jun 6, 2019
24c2153
Make some stylistic changes to lib/test
eggplantzzz Jun 6, 2019
f8ea2e6
Call done directly instead of relying on the callback to catch the error
eggplantzzz Jun 6, 2019
b9a41e4
Make the interface for Test.run promise based rather than callback-based
eggplantzzz Jun 6, 2019
543e4a6
Change the huge Promise chain thingy to a series of await statements
eggplantzzz Jun 6, 2019
07d3100
Remove the dreaded self=this
eggplantzzz Jun 6, 2019
e73541f
Edit variable declarations
eggplantzzz Jun 6, 2019
e048a42
Switch Test to use truffle-workflow-compile's Promise-based interface…
eggplantzzz Jun 6, 2019
fb46129
Remove unnecessary promise
eggplantzzz Jun 6, 2019
f793e43
Make a minor edit in the interest of readability
eggplantzzz Jun 6, 2019
dfb0b3a
Use synchronous fs method instead of async one
eggplantzzz Jun 7, 2019
1a8b2d1
Update some syntax in testsource
eggplantzzz Jun 7, 2019
8682493
Update some more syntax and edit some variable names
eggplantzzz Jun 7, 2019
a317164
Edit variable name and update some function syntax
eggplantzzz Jun 7, 2019
abea6e7
Update some more syntax
eggplantzzz Jun 7, 2019
0fcad75
Drop in fs-extra to replace fs library
eggplantzzz Jun 12, 2019
faef71c
Make some minor variable name edits
eggplantzzz Jun 12, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
161 changes: 77 additions & 84 deletions packages/truffle-core/lib/commands/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const command = {
const promisifiedCopy = promisify(require("../copy"));
const Environment = require("../environment");

var config = Config.detect(options);
const config = Config.detect(options);

// if "development" exists, default to using that for testing
if (!config.network && config.networks.development) {
Expand All @@ -67,108 +67,101 @@ const command = {
Environment.detect(config).catch(done);
}

var ipcDisconnect;

var files = [];
let ipcDisconnect;
let files = [];

if (options.file) {
files = [options.file];
} else if (options._.length > 0) {
Array.prototype.push.apply(files, options._);
}

function getFiles(callback) {
if (files.length !== 0) {
return callback(null, files);
try {
if (files.length === 0) {
files = dir.files(config.test_directory, { sync: true });
}
} catch (error) {
return done(error);
}

dir.files(config.test_directory, callback);
files = files.filter(function(file) {
return file.match(config.test_file_extension_regexp) != null;
});

let temporaryDirectory;
try {
temporaryDirectory = temp.mkdirSync("test-");
} catch (error) {
return done(error);
}

getFiles(function(err, files) {
if (err) return done(err);
function runCallback() {
var args = arguments;
// Ensure directory cleanup.
done.apply(null, args);
if (ipcDisconnect) ipcDisconnect();
}

files = files.filter(function(file) {
return file.match(config.test_file_extension_regexp) != null;
});
function run() {
// Set a new artifactor; don't rely on the one created by Environments.
// TODO: Make the test artifactor configurable.
config.artifactor = new Artifactor(temporaryDirectory);

temp.mkdir("test-", function(err, temporaryDirectory) {
if (err) return done(err);
const testConfig = config.with({
test_files: files,
contracts_build_directory: temporaryDirectory
});
Test.run(testConfig)
.then(runCallback)
.catch(runCallback);
}

function runCallback() {
var args = arguments;
// Ensure directory cleanup.
done.apply(null, args);
if (ipcDisconnect) {
ipcDisconnect();
}
}
const environmentCallback = function() {
// Copy all the built files over to a temporary directory, because we
// don't want to save any tests artifacts. Only do this if the build directory
// exists.
try {
fs.statSync(config.contracts_build_directory);
} catch (_error) {
return run();
}

function run() {
// Set a new artifactor; don't rely on the one created by Environments.
// TODO: Make the test artifactor configurable.
config.artifactor = new Artifactor(temporaryDirectory);

Test.run(
config.with({
test_files: files,
contracts_build_directory: temporaryDirectory
}),
runCallback
);
}
promisifiedCopy(config.contracts_build_directory, temporaryDirectory)
.then(() => {
config.logger.log("Using network '" + config.network + "'." + OS.EOL);

const environmentCallback = function(err) {
if (err) return done(err);
// Copy all the built files over to a temporary directory, because we
// don't want to save any tests artifacts. Only do this if the build directory
// exists.
try {
fs.statSync(config.contracts_build_directory);
} catch (_error) {
return run();
}

promisifiedCopy(config.contracts_build_directory, temporaryDirectory)
.then(() => {
config.logger.log(
"Using network '" + config.network + "'." + OS.EOL
);

run();
})
.catch(done);
};
run();
})
.catch(done);
};

if (config.networks[config.network]) {
Environment.detect(config)
if (config.networks[config.network]) {
Environment.detect(config)
.then(() => environmentCallback())
.catch(done);
} else {
const ipcOptions = { network: "test" };

const ganacheOptions = {
host: "127.0.0.1",
port: 7545,
network_id: 4447,
mnemonic:
"candy maple cake sugar pudding cream honey rich smooth crumble sweet treat",
gasLimit: config.gas,
noVMErrorsOnRPCResponse: true
};
Develop.connectOrStart(
ipcOptions,
ganacheOptions,
(started, disconnect) => {
ipcDisconnect = disconnect;
Environment.develop(config, ganacheOptions)
.then(() => environmentCallback())
.catch(environmentCallback);
} else {
const ipcOptions = { network: "test" };

const ganacheOptions = {
host: "127.0.0.1",
port: 7545,
network_id: 4447,
mnemonic:
"candy maple cake sugar pudding cream honey rich smooth crumble sweet treat",
gasLimit: config.gas,
noVMErrorsOnRPCResponse: true
};
Develop.connectOrStart(
ipcOptions,
ganacheOptions,
(started, disconnect) => {
ipcDisconnect = disconnect;
Environment.develop(config, ganacheOptions)
.then(() => environmentCallback())
.catch(environmentCallback);
}
);
.catch(done);
}
});
});
);
}
}
};

Expand Down