Skip to content

tns test init --help doesn't show the available unit testing frameworks #5151

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

Merged
merged 2 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion docs/man_pages/project/testing/test-init.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ General | `$ tns test init [--framework <Framework>]`

### Options

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

<% if(isHtml) { %>

Expand Down
4 changes: 3 additions & 1 deletion lib/common/services/micro-templating-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions lib/common/test/unit-tests/services/help-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const createTestInjector = (opts?: { isProjectTypeResult: boolean; isPlatformRes
getInstalledExtensionsData: (): IExtensionData[] => []
});

injector.register("testInitializationService", {});

injector.registerCommand("foo", {});

const microTemplateService: any = injector.resolve("microTemplateService");
Expand Down
1 change: 1 addition & 0 deletions lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ interface ITestExecutionService {

interface ITestInitializationService {
getDependencies(framework: string): IDependencyInformation[];
getFrameworkNames(): string[];
}

/**
Expand Down
16 changes: 16 additions & 0 deletions lib/services/test-initialization-service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as path from "path";
import * as fs from "fs";
import { cache } from "../common/decorators";

export class TestInitializationService implements ITestInitializationService {
Expand Down Expand Up @@ -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);