diff --git a/package-lock.json b/package-lock.json index 7f48f63d..1671167a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3558,7 +3558,7 @@ }, "is-obj": { "version": "1.0.1", - "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz", + "resolved": "http://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz", "integrity": "sha1-PkcprB9f3gJc19g6iW2rn09n2w8=", "dev": true }, @@ -5787,7 +5787,7 @@ }, "through": { "version": "2.3.8", - "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", + "resolved": "http://registry.npmjs.org/through/-/through-2.3.8.tgz", "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", "dev": true }, diff --git a/packages/alsatian/cli/alsatian-cli-options.ts b/packages/alsatian/cli/alsatian-cli-options.ts index c6933e61..2cc93b38 100644 --- a/packages/alsatian/cli/alsatian-cli-options.ts +++ b/packages/alsatian/cli/alsatian-cli-options.ts @@ -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; @@ -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); } } @@ -129,10 +131,31 @@ 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, argumentName: string, - argumentShorthand?: string + argumentShorthand?: string, + hasValue: boolean = false ) { const argumentIndex = this.getArgumentIndexFromArgumentList( args, @@ -140,14 +163,20 @@ export class AlsatianCliOptions { 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 }; } diff --git a/packages/alsatian/cli/alsatian-cli.ts b/packages/alsatian/cli/alsatian-cli.ts index 1878320b..44a646d9 100644 --- a/packages/alsatian/cli/alsatian-cli.ts +++ b/packages/alsatian/cli/alsatian-cli.ts @@ -1,5 +1,4 @@ #! /usr/bin/env node -import "ts-node/register/transpile-only"; import { AlsatianCliOptions } from "./alsatian-cli-options"; import { CliTestRunner } from "./cli-test-runner"; @@ -7,6 +6,9 @@ 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); diff --git a/packages/alsatian/test/integration-tests/cli/runner.ts b/packages/alsatian/test/integration-tests/cli/runner.ts index 9b937df5..8b0c35cc 100644 --- a/packages/alsatian/test/integration-tests/cli/runner.ts +++ b/packages/alsatian/test/integration-tests/cli/runner.ts @@ -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((resolve, reject) => { + result.on("close", (code: number) => { + Expect(consoleOutput).toBe(expectedOutput.replace(/\r/g, "")); + resolve(); + }); + }); + } } diff --git a/packages/tap-bark/src/tap-bark.tsx b/packages/tap-bark/src/tap-bark.tsx index bfae8006..334c212a 100644 --- a/packages/tap-bark/src/tap-bark.tsx +++ b/packages/tap-bark/src/tap-bark.tsx @@ -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 = ; - render(tapBarkOutput); - - return { - getPipeable: () => duplexer(TapBark.tapParser, through()) - }; - } + public static create(showProgress: boolean = true) { + const tapBarkOutput = ; + render(tapBarkOutput); + + return { + getPipeable: () => duplexer(TapBark.tapParser, through()) + }; + } } diff --git a/packages/tap-bark/test/unit-tests/index.test.ts b/packages/tap-bark/test/unit-tests/index.test.ts index e51684f5..ba8ac7df 100644 --- a/packages/tap-bark/test/unit-tests/index.test.ts +++ b/packages/tap-bark/test/unit-tests/index.test.ts @@ -57,4 +57,9 @@ export default class IndexTests { Expect(chainedPipe.pipe).toHaveBeenCalledWith(process.stdout); } + + @Teardown + private _restoreTapBarkCreate() { + (TapBark.create as any).restore(); + } }