Skip to content

Commit dc5f27a

Browse files
committed
tns test init --help doesn't show the available unit testing frameworks as the constant constants.TESTING_FRAMEWORKS that is used from the test-init.md file was deleted. On the other side, test-dependencies.json file was introduced in order to list all supported frameworks. So, this PR gets the supported unit testing framework names from test-dependencies.json file and prints them from test-init.md file.
Rel to: #5113
1 parent 3f65dc2 commit dc5f27a

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

docs/man_pages/project/testing/test-init.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ General | `$ tns test init [--framework <Framework>]`
1717

1818
### Options
1919

20-
* `--framework <Framework>` - Sets the unit testing framework to install. The following frameworks are available: <%= formatListOfNames(constants.TESTING_FRAMEWORKS, 'and') %>.
20+
* `--framework <Framework>` - Sets the unit testing framework to install. The following frameworks are available: <%= formatListOfNames(getUnitTestingFrameworkNames(), 'and') %>.
2121

2222
<% if(isHtml) { %>
2323

lib/common/services/micro-templating-service.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { formatListOfNames } from '../helpers';
66
export class MicroTemplateService implements IMicroTemplateService {
77
private dynamicCallRegex: RegExp;
88

9-
constructor(private $injector: IInjector) {
9+
constructor(private $injector: IInjector,
10+
private $testInitializationService: ITestInitializationService) {
1011
// Injector's dynamicCallRegex doesn't have 'g' option, which we need here.
1112
// Use ( ) in order to use $1 to get whole expression later
1213
this.dynamicCallRegex = new RegExp(util.format("(%s)", this.$injector.dynamicCallRegex.source), "g");
@@ -37,6 +38,7 @@ export class MicroTemplateService implements IMicroTemplateService {
3738
localVariables["isConsole"] = !isHtml;
3839
localVariables["isHtml"] = isHtml;
3940
localVariables["formatListOfNames"] = formatListOfNames;
41+
localVariables["getUnitTestingFrameworkNames"] = this.$testInitializationService.getFrameworkNames;
4042
localVariables["isJekyll"] = false;
4143

4244
return localVariables;

lib/definitions/project.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ interface ITestExecutionService {
376376

377377
interface ITestInitializationService {
378378
getDependencies(framework: string): IDependencyInformation[];
379+
getFrameworkNames(): string[];
379380
}
380381

381382
/**

lib/services/test-initialization-service.ts

+16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as path from "path";
2+
import * as fs from "fs";
23
import { cache } from "../common/decorators";
34

45
export class TestInitializationService implements ITestInitializationService {
@@ -27,6 +28,21 @@ export class TestInitializationService implements ITestInitializationService {
2728

2829
return targetFrameworkDependencies;
2930
}
31+
32+
/**
33+
* This method is used from test-init.md file so it is not allowed to use "this" inside the method's body.
34+
*/
35+
@cache()
36+
public getFrameworkNames(): string[] {
37+
const configsPath = path.join(__dirname, "..", "..", "config");
38+
const dependenciesPath = path.join(configsPath, "test-dependencies.json");
39+
const allDependencies: { name: string, framework?: string }[] = JSON.parse(fs.readFileSync(dependenciesPath, { encoding: 'utf-8'}));
40+
const frameworks = _.uniqBy(allDependencies, "framework")
41+
.map(item => item && item.framework)
42+
.filter(item => item);
43+
44+
return frameworks;
45+
}
3046
}
3147

3248
$injector.register("testInitializationService", TestInitializationService);

0 commit comments

Comments
 (0)