Skip to content
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

Add doc in test_all.js #531

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions test_all.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const semver = require("semver");

const examplesFolder = path.join(__dirname, "src");

/**
* Recursively get all folders with package.json
*/
function getAllExamples(pathToCheck) {
const directoriesToTest = [];
for (const fd of fs.readdirSync(pathToCheck)) {
Expand All @@ -28,6 +31,8 @@ const failedTests = [];
for (directoryToTest of getAllExamples(examplesFolder)) {
console.log(chalk.green(`testing: ${directoryToTest}`));
const pkgJson = require(path.join(directoryToTest, "package.json"));

// Check if a node version exists, then skip the project if the current node version does not satisfy the range
if (pkgJson.engines && pkgJson.engines.node) {
const currentNodeVersion = process.versions.node;
const range = pkgJson.engines.node;
Expand All @@ -42,6 +47,7 @@ for (directoryToTest of getAllExamples(examplesFolder)) {
}
}

// install dependencies
try {
const stdout = execSync("npm install", { cwd: directoryToTest });
console.log(stdout.toString());
Expand All @@ -51,6 +57,7 @@ for (directoryToTest of getAllExamples(examplesFolder)) {
continue;
}

// choose a project entry point scripts.start or scripts.test or main file
let testCommand;
if ("scripts" in pkgJson && "start" in pkgJson.scripts) {
testCommand = "npm start";
Expand All @@ -63,6 +70,7 @@ for (directoryToTest of getAllExamples(examplesFolder)) {
continue;
}

// call the test command
try {
const stdout = execSync(testCommand, { cwd: directoryToTest });
console.log(stdout.toString());
Expand Down