-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improvement(core): add get tests command
- Loading branch information
Showing
7 changed files
with
298 additions
and
55 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,50 @@ | ||
/* | ||
* Copyright (C) 2018-2021 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { sortBy, uniq } from "lodash" | ||
import { Command, CommandResult, CommandParams } from "../base" | ||
import { printHeader } from "../../logger/util" | ||
import { StringsParameter } from "../../cli/params" | ||
import { makeGetTestOrTaskLog, makeGetTestOrTaskResult } from "../helpers" | ||
|
||
const getTestsArgs = { | ||
tests: new StringsParameter({ | ||
help: "Specify tests(s) to list. Use comma as a separator to specify multiple tests.", | ||
}), | ||
} | ||
|
||
type Args = typeof getTestsArgs | ||
|
||
export class GetTestsCommand extends Command<Args> { | ||
name = "tests" | ||
help = "Lists the tests defined in your project's modules." | ||
|
||
arguments = getTestsArgs | ||
|
||
printHeader({ headerLog }) { | ||
printHeader(headerLog, "Tests", "open_book") | ||
} | ||
|
||
async action({ args, garden, log }: CommandParams<Args>): Promise<CommandResult> { | ||
const graph = await garden.getConfigGraph(log) | ||
const tests = graph.getTests({ names: args.tests }) | ||
const testModuleNames = uniq(tests.map((t) => t.module.name)) | ||
const modules = sortBy(graph.getModules({ names: testModuleNames }), (m) => m.name) | ||
|
||
const testListing = makeGetTestOrTaskResult(modules, tests) | ||
|
||
if (testListing.length > 0) { | ||
const logStr = makeGetTestOrTaskLog(modules, tests, "tests") | ||
log.info(logStr.trim()) | ||
} else { | ||
log.info(`No tests defined for project ${garden.projectName}`) | ||
} | ||
|
||
return { result: testListing } | ||
} | ||
} |
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
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
Oops, something went wrong.