Skip to content
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

Implement specifying ts-config to alsatian-cli #600

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 36 additions & 7 deletions packages/alsatian/cli/alsatian-cli-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { InvalidArgumentNamesError } from "./errors/invalid-argument-names-error
import { InvalidTimeoutValueError } from "./errors/invalid-timeout-value-error";
import { MissingArgumentValueError } from "./errors/missing-argument-value-error";
import { Unused } from "../core/unused";
import { removeItemByIndex } from "../core/utils/remove-item-by-index";

export class AlsatianCliOptions {
public readonly fileGlobs: Array<string>;
Expand Down Expand Up @@ -32,8 +31,11 @@ export class AlsatianCliOptions {
const f = this.extractHideProgress(e.args);
this.hideProgress = f.value;

if (f.args.length > 0) {
throw new InvalidArgumentNamesError(f.args);
const t = this.extractTranspileOnly(f.args);
const p = this.extractProject(t.args);

if (p.args.length > 0) {
throw new InvalidArgumentNamesError(p.args);
}
}

Expand Down Expand Up @@ -129,25 +131,52 @@ export class AlsatianCliOptions {
);
}

private extractTranspileOnly(args) {
const transpileOnly = this.extractArgumentFromList(args, "transpile-only", "t");

if (transpileOnly.value) {
process.env.TS_NODE_TRANSPILE_ONLY = "true";
}

return transpileOnly;
}

private extractProject(args) {
const project = this.extractArgumentFromList(args, "project", "p", true);

if (project.value) {
process.env.TS_NODE_PROJECT = project.value;
}

return project;
}

private extractArgumentFromList(
args: Array<string>,
argumentName: string,
argumentShorthand?: string
argumentShorthand?: string,
hasValue: boolean = false
) {
const argumentIndex = this.getArgumentIndexFromArgumentList(
args,
argumentName,
argumentShorthand
);

let value: any = argumentIndex !== -1;

if (hasValue && value) {
value = args[argumentIndex + 1];
}

// filter out the tap argument and return the other args
args = args.filter((value, index) => {
Unused(value);
args = args.filter((_, index) => {
Unused(_);
return index !== argumentIndex;
});

return {
value: argumentIndex !== -1,
value,
args
};
}
Expand Down
4 changes: 3 additions & 1 deletion packages/alsatian/cli/alsatian-cli.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#! /usr/bin/env node
import "ts-node/register/transpile-only";

import { AlsatianCliOptions } from "./alsatian-cli-options";
import { CliTestRunner } from "./cli-test-runner";

// get all arguments from the user
const userArguments = new AlsatianCliOptions(process.argv.slice(2));

// import ts-node/register after retrieving arguments in case --project specified
import "ts-node/register";

// run the test set
const cliTestRunner = CliTestRunner.create();
cliTestRunner.run(userArguments);
26 changes: 26 additions & 0 deletions packages/alsatian/test/integration-tests/cli/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,30 @@ export class CliIntegrationTests {
});
});
}

public shouldWorkWithSpecifiedTsConfig() {
const result = child.exec(
`alsatian` +
`./dist/test/integration-tests/test-sets/expectations/to-be.spec.js` +
` --tap` +
` --project ./dist/test/tsconfig.json`
);

let consoleOutput = "";

result.stdout.on("data", (data: string) => (consoleOutput += data));
result.stderr.on("data", (data: string) => (consoleOutput += data));

const expectedOutput = FileSystem.readFileSync(
`./test/integration-tests/expected-output/` +
`expectations/to-be.txt`
).toString();

return new Promise<void>((resolve, reject) => {
result.on("close", (code: number) => {
Expect(consoleOutput).toBe(expectedOutput.replace(/\r/g, ""));
resolve();
});
});
}
}
19 changes: 9 additions & 10 deletions packages/tap-bark/src/tap-bark.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import { render } from "ink";
import { TapBarkRoot } from "./components/tap-bark-root";

export class TapBark {

public static readonly tapParser = new Parser();
public static readonly tapParser = new Parser();

public static create(showProgress: boolean = true) {
const tapBarkOutput = <TapBarkRoot showProgress={showProgress} />;
render(tapBarkOutput);
return {
getPipeable: () => duplexer(TapBark.tapParser, through())
};
}
public static create(showProgress: boolean = true) {
const tapBarkOutput = <TapBarkRoot showProgress={showProgress} />;
render(tapBarkOutput);

return {
getPipeable: () => duplexer(TapBark.tapParser, through())
};
}
}
5 changes: 5 additions & 0 deletions packages/tap-bark/test/unit-tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@ export default class IndexTests {

Expect(chainedPipe.pipe).toHaveBeenCalledWith(process.stdout);
}

@Teardown
private _restoreTapBarkCreate() {
(TapBark.create as any).restore();
}
}