-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
various fixes & improvements #46
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,22 +8,91 @@ import { | |
} from "../internal/utils/source-files"; | ||
import { MochaOptions } from "mocha"; | ||
import { isTSProject } from "../internal/utils/typescript-support"; | ||
import * as os from 'os'; | ||
import { exec } from "child_process"; | ||
import semver from "semver"; | ||
|
||
export type TestOptionsArguments = { | ||
timeout: string; | ||
grep: string; | ||
jobs: number; | ||
}; | ||
|
||
function max_num_jobs(): number { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. running
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For now I'll probably just add another check that tries to run the |
||
const cpuCores = os.cpus().length; | ||
const totalMemoryGB = os.totalmem() / (1024 ** 3); | ||
|
||
return Math.max(1, Math.min(Math.floor(cpuCores / 4), Math.floor(totalMemoryGB / 4))); | ||
} | ||
|
||
async function checkAptosVersion(): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
exec("npx aptos --version", (error, stdout, stderr) => { | ||
if (error) { | ||
return reject( | ||
new Error( | ||
"Failed to run npx aptos, have you installed it properly?\n" + | ||
"If your project uses `yarn`, you need to run `yarn add --dev @aptos-labs/ts-sdk`.\n" + | ||
"If your project uses `pnpm`, you need to run `pnpm add -D @aptos-labs/aptos-cli`." | ||
) | ||
); | ||
} | ||
|
||
const versionMatch = stdout.match(/aptos (\d+\.\d+\.\d+)/); | ||
|
||
if (!versionMatch) { | ||
return reject(new Error("Could not determine the Aptos CLI version.")); | ||
} | ||
|
||
const version = versionMatch[1]; | ||
const minimumVersion = "6.0.2"; | ||
|
||
if (semver.lt(version, minimumVersion)) { | ||
return reject( | ||
new Error( | ||
`Aptos CLI version needs to be at least ${minimumVersion}, please run "npx aptos --update" to update.\n` + | ||
"You might need to restart your shell in a new window for the update to take effect." | ||
) | ||
); | ||
} | ||
|
||
console.log(`Aptos CLI version ${version} detected.`); | ||
resolve(); // Successfully completed the check | ||
}); | ||
}); | ||
} | ||
|
||
async function checkDockerVersion(): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
exec("docker -v", (error, stdout, stderr) => { | ||
if (error) { | ||
reject(new Error( | ||
"An error occurred while checking the Docker version. Ensure Docker is installed and properly set up.\n\n" + | ||
"If Docker is not installed, you can download and install it by following the instructions here: https://www.docker.com/get-started/")); | ||
} else { | ||
const match = stdout.trim().match(/Docker version (\d+\.\d+\.\d+)/); | ||
if (match) { | ||
console.log(`Docker version ${match[1]} detected.`); | ||
resolve(); | ||
} else { | ||
reject(new Error(`Failed to parse Docker version. Docker output: ${stdout}`)); | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
export const test = async (options: TestOptionsArguments) => { | ||
const userProjectPath = process.cwd(); | ||
|
||
isUserProjectTestsFolderExists(userProjectPath); | ||
await checkAptosVersion(); | ||
await checkDockerVersion(); | ||
|
||
const { default: Mocha } = await import("mocha"); | ||
|
||
const mochaConfig: MochaOptions = { | ||
timeout: options.timeout ?? 20000, // to support local testnet run, TODO improve performance | ||
timeout: options.timeout ?? 60000, // to support local testnet run, TODO improve performance | ||
require: [path.join(__dirname, "internal/rootHook.js")], | ||
parallel: true, | ||
grep: "", | ||
|
@@ -43,6 +112,9 @@ export const test = async (options: TestOptionsArguments) => { | |
if (options.jobs !== undefined) { | ||
mochaConfig.jobs = options.jobs; | ||
} | ||
else { | ||
mochaConfig.jobs = max_num_jobs(); | ||
} | ||
|
||
const mocha = new Mocha(mochaConfig); | ||
|
||
|
@@ -75,7 +147,7 @@ export const test = async (options: TestOptionsArguments) => { | |
await mocha.loadFilesAsync(); | ||
} | ||
|
||
console.log("Spinning up the server to run tests, hold on..."); | ||
console.log("\nSpinning up local networks to run tests, this may take a while..."); | ||
// run mocha | ||
await new Promise<number>((resolve) => { | ||
mocha.run(resolve); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be great to clean up a bit the output when running
npx aptos workspace run
on cli whendocker
is not available