Skip to content

Commit 6aed995

Browse files
committed
feat: add test command
1 parent d724f46 commit 6aed995

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

.suite-cli/cli/cli.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ program
5151
.command('release [package]')
5252
.description('make a package release and publish simultaneously to npm.If no package is passed then generate:release for changelog is run')
5353
.action(async (package) => await actionHandlers.releasePackage({ package }));
54+
program
55+
.command('test [package]')
56+
.description('run tests')
57+
.action(async (package) => await actionHandlers.test({ package }));
5458
program
5559
.command('start [components...]')
5660
.description('Starts specified components (services or apps), or all services in dev mode if -m is not specified')
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
const { test } = require('../scripts.module')
3+
4+
module.exports = async ({ package }) => {
5+
test({ package });
6+
};

.suite-cli/cli/scripts/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ module.exports.scaffoldNewRepo = require('./commands/scaffoldNewRepo.cmd');
2222
module.exports.releasePackage = require('./commands/releasePackage.cmd');
2323
module.exports.scaffoldNewService = require('./commands/scaffoldNewService.cmd');
2424
module.exports.scaffoldNewLibrary = require('./commands/scaffoldNewLibrary.cmd');
25+
module.exports.test = require('./commands/test.cmd');

.suite-cli/cli/scripts/scripts.module.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,35 @@ const registerServiceWithSuiteJson = ({ root_dir, name, port }) => {
14131413
config.services.push({ name, port });
14141414
writeFile(configPath, JSON.stringify(config, null, 2), 'utf8');
14151415
}
1416+
1417+
/**
1418+
* Releases a package or generates a release for the workspace.
1419+
* @async
1420+
* @param {Object} options - Options for releasing the package.
1421+
* @param {string} options.package - The name of the package to release (optional).
1422+
* @returns {Promise<void>} A Promise that resolves when the release process is completed.
1423+
*/
1424+
const test = async ({ package }) => {
1425+
let rootDir = cwd();
1426+
if (!package) {
1427+
rootDir = generatRootPath({ currentDir: cwd() });
1428+
}
1429+
try {
1430+
const package_json_path = join(rootDir, 'package.json');
1431+
1432+
// Read the package.json file
1433+
const { workspace_name } = retrieveWorkSpaceName({ package_json_path });
1434+
if (package) {
1435+
logInfo({ message: `Looking for package: ${workspace_name}/${package}` });
1436+
await executeCommand('yarn', ['workspace', `${workspace_name}/${package}`, 'test'], { stdio: 'inherit', shell: true });
1437+
} else {
1438+
await executeCommand('yarn', ['test'], { cwd: rootDir, stdio: 'inherit', shell: true });
1439+
}
1440+
} catch (error) {
1441+
ora().fail('Command failed to run');
1442+
}
1443+
}
1444+
14161445
const readFileContent = ({ path }) => { }
14171446
module.exports = {
14181447
generateDirectoryPath,
@@ -1441,5 +1470,6 @@ module.exports = {
14411470
scaffoldNewService,
14421471
scaffoldNewLibrary,
14431472
getNextAvailablePort,
1444-
getExistingServices
1473+
getExistingServices,
1474+
test
14451475
}

0 commit comments

Comments
 (0)