This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3395 from trufflesuite/move-test-files
Internal improvement: Rework test files
- Loading branch information
Showing
43 changed files
with
428 additions
and
884 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
27
packages/core/lib/commands/test/determineTestFilesToRun.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/core/lib/commands/test/prepareConfigAndRunTests.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
Oops, something went wrong.