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

Commit

Permalink
Merge pull request #3395 from trufflesuite/move-test-files
Browse files Browse the repository at this point in the history
Internal improvement: Rework test files
  • Loading branch information
gnidan authored Oct 8, 2020
2 parents ad69387 + 5741159 commit de44ba8
Show file tree
Hide file tree
Showing 43 changed files with 428 additions and 884 deletions.
2 changes: 1 addition & 1 deletion packages/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
// TODO: update this to non-legacy the next breaking change
contracts: require("@truffle/workflow-compile/legacy"),
package: require("./lib/package"),
test: require("./lib/test"),
test: require("./lib/testing/Test"),
version: pkg.version,
ganache: require("ganache-core/public-exports")
};
31 changes: 31 additions & 0 deletions packages/core/lib/commands/test/copyArtifactsToTempDir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const copyArtifactsToTempDir = async config => {
const { promisify } = require("util");
const copy = require("../../copy");
const fs = require("fs");
const OS = require("os");
const tmp = require("tmp");
tmp.setGracefulCleanup();

// 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.
const temporaryDirectory = tmp.dirSync({
unsafeCleanup: true,
prefix: "test-"
}).name;
try {
fs.statSync(config.contracts_build_directory);
} catch (_error) {
return { config, temporaryDirectory };
}

await promisify(copy)(config.contracts_build_directory, temporaryDirectory);
if (config.runnerOutputOnly !== true) {
config.logger.log("Using network '" + config.network + "'." + OS.EOL);
}
return { config, temporaryDirectory };
};

module.exports = {
copyArtifactsToTempDir
};
27 changes: 27 additions & 0 deletions packages/core/lib/commands/test/determineTestFilesToRun.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const determineTestFilesToRun = ({ inputFile, inputArgs = [], config }) => {
const path = require("path");
const fs = require("fs");
const glob = require("glob");
let filesToRun = [];

if (inputFile) {
filesToRun.push(inputFile);
} else if (inputArgs.length > 0) {
inputArgs.forEach(inputArg => filesToRun.push(inputArg));
}

if (filesToRun.length === 0) {
const directoryContents = glob.sync(
`${config.test_directory}${path.sep}**${path.sep}*`
);
filesToRun =
directoryContents.filter(item => fs.statSync(item).isFile()) || [];
}
return filesToRun.filter(file => {
return file.match(config.test_file_extension_regexp) !== null;
});
};

module.exports = {
determineTestFilesToRun
};
71 changes: 0 additions & 71 deletions packages/core/lib/commands/test/helpers.js

This file was deleted.

8 changes: 3 additions & 5 deletions packages/core/lib/commands/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,9 @@ const command = {
run: function (options, done) {
const Config = require("@truffle/config");
const { Environment, Develop } = require("@truffle/environment");
const {
copyArtifactsToTempDir,
determineTestFilesToRun,
prepareConfigAndRunTests
} = require("./helpers");
const { copyArtifactsToTempDir } = require("./copyArtifactsToTempDir");
const { determineTestFilesToRun } = require("./determineTestFilesToRun");
const { prepareConfigAndRunTests } = require("./prepareConfigAndRunTests");

const config = Config.detect(options);

Expand Down
17 changes: 17 additions & 0 deletions packages/core/lib/commands/test/prepareConfigAndRunTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const prepareConfigAndRunTests = ({ config, temporaryDirectory, files }) => {
const Artifactor = require("@truffle/artifactor");
const Test = require("../../testing/Test");
// Set a new artifactor; don't rely on the one created by Environments.
// TODO: Make the test artifactor configurable.
config.artifactor = new Artifactor(temporaryDirectory);

const testConfig = config.with({
test_files: files,
contracts_build_directory: temporaryDirectory
});
return Test.run(testConfig);
};

module.exports = {
prepareConfigAndRunTests
};
Loading

0 comments on commit de44ba8

Please sign in to comment.