diff --git a/docs/man_pages/project/testing/test-init.md b/docs/man_pages/project/testing/test-init.md index 2d0a8763bd..5cd1eb408d 100644 --- a/docs/man_pages/project/testing/test-init.md +++ b/docs/man_pages/project/testing/test-init.md @@ -17,7 +17,7 @@ General | `$ tns test init [--framework ]` ### Options -* `--framework ` - Sets the unit testing framework to install. The following frameworks are available: <%= formatListOfNames(constants.TESTING_FRAMEWORKS, 'and') %>. +* `--framework ` - Sets the unit testing framework to install. The following frameworks are available: <%= formatListOfNames(getUnitTestingFrameworkNames(), 'and') %>. <% if(isHtml) { %> diff --git a/lib/common/services/micro-templating-service.ts b/lib/common/services/micro-templating-service.ts index fa534c93fc..50e7c33b06 100644 --- a/lib/common/services/micro-templating-service.ts +++ b/lib/common/services/micro-templating-service.ts @@ -6,7 +6,8 @@ import { formatListOfNames } from '../helpers'; export class MicroTemplateService implements IMicroTemplateService { private dynamicCallRegex: RegExp; - constructor(private $injector: IInjector) { + constructor(private $injector: IInjector, + private $testInitializationService: ITestInitializationService) { // Injector's dynamicCallRegex doesn't have 'g' option, which we need here. // Use ( ) in order to use $1 to get whole expression later this.dynamicCallRegex = new RegExp(util.format("(%s)", this.$injector.dynamicCallRegex.source), "g"); @@ -37,6 +38,7 @@ export class MicroTemplateService implements IMicroTemplateService { localVariables["isConsole"] = !isHtml; localVariables["isHtml"] = isHtml; localVariables["formatListOfNames"] = formatListOfNames; + localVariables["getUnitTestingFrameworkNames"] = this.$testInitializationService.getFrameworkNames; localVariables["isJekyll"] = false; return localVariables; diff --git a/lib/common/test/unit-tests/services/help-service.ts b/lib/common/test/unit-tests/services/help-service.ts index 4430b92294..fe03eaa6e1 100644 --- a/lib/common/test/unit-tests/services/help-service.ts +++ b/lib/common/test/unit-tests/services/help-service.ts @@ -34,6 +34,8 @@ const createTestInjector = (opts?: { isProjectTypeResult: boolean; isPlatformRes getInstalledExtensionsData: (): IExtensionData[] => [] }); + injector.register("testInitializationService", {}); + injector.registerCommand("foo", {}); const microTemplateService: any = injector.resolve("microTemplateService"); diff --git a/lib/definitions/project.d.ts b/lib/definitions/project.d.ts index 51eb52fc99..c02d342aab 100644 --- a/lib/definitions/project.d.ts +++ b/lib/definitions/project.d.ts @@ -376,6 +376,7 @@ interface ITestExecutionService { interface ITestInitializationService { getDependencies(framework: string): IDependencyInformation[]; + getFrameworkNames(): string[]; } /** diff --git a/lib/services/test-initialization-service.ts b/lib/services/test-initialization-service.ts index c2d7f6220c..60995ae0e9 100644 --- a/lib/services/test-initialization-service.ts +++ b/lib/services/test-initialization-service.ts @@ -1,4 +1,5 @@ import * as path from "path"; +import * as fs from "fs"; import { cache } from "../common/decorators"; export class TestInitializationService implements ITestInitializationService { @@ -27,6 +28,21 @@ export class TestInitializationService implements ITestInitializationService { return targetFrameworkDependencies; } + + /** + * This method is used from test-init.md file so it is not allowed to use "this" inside the method's body. + */ + @cache() + public getFrameworkNames(): string[] { + const configsPath = path.join(__dirname, "..", "..", "config"); + const dependenciesPath = path.join(configsPath, "test-dependencies.json"); + const allDependencies: { name: string, framework?: string }[] = JSON.parse(fs.readFileSync(dependenciesPath, { encoding: 'utf-8'})); + const frameworks = _.uniqBy(allDependencies, "framework") + .map(item => item && item.framework) + .filter(item => item); + + return frameworks; + } } $injector.register("testInitializationService", TestInitializationService);