Skip to content

Commit 7a9dc8a

Browse files
committed
added tests
1 parent 9d406f6 commit 7a9dc8a

File tree

4 files changed

+39
-23
lines changed

4 files changed

+39
-23
lines changed

src/cli/support/describeMove.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as path from "path";
2+
3+
export function describeMove(fromDir: string, toDir: string): string {
4+
const relativeForward = path.relative(fromDir, toDir);
5+
const relativeBackward = path.relative(toDir, fromDir);
6+
const upSteps = relativeBackward.split("node_modules").length - 1;
7+
const downSteps = relativeForward.split("node_modules").length - 1;
8+
if (upSteps > 0) {
9+
return `up ${upSteps} stairs and down ${downSteps}.`
10+
} else if (downSteps > 0) {
11+
return `down ${downSteps} stair.` // should always be 1.
12+
} else {
13+
return `right through.`;
14+
}
15+
}

src/cli/support/youAreIn.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { outputCurrentState, output, outputDoom, outputDebug } from "./output";
99
import { promisify } from "util";
1010
import { Crawl as LocalCrawl, NodeModuleResolutionExposed, isModuleResolutionError } from "./SecretDungeonCrawl";
1111
import { injectSecretDungeonCrawl } from "./injectSecretDungeonCrawl";
12+
import { describeMove } from "./describeMove";
1213

1314
// want to:
1415
// - make it find roots of packages, because it fails when it goes into a lib
@@ -70,6 +71,7 @@ function tryToTeleport(room: Room, past: Room[], destination: string) {
7071
const otherSide = findLibraryRoot(destination, room.crawl);
7172
if (itsaTrap(otherSide)) {
7273
outputDoom(chalk.yellow("Your teleport fails."));
74+
outputDebug(otherSide.details || otherSide.error.message);
7375
return youAreIn(room.appDir, past);
7476
}
7577
output("Magic! " + describeMove(room.appDir, otherSide));
@@ -89,20 +91,6 @@ function goThroughDoor(room: Room, past: Room[], destination: string) {
8991
return youAreIn(otherSide, past);
9092
}
9193

92-
export function describeMove(fromDir: string, toDir: string): string {
93-
const relativeForward = path.relative(fromDir, toDir);
94-
const relativeBackward = path.relative(toDir, fromDir);
95-
const upSteps = relativeBackward.split("node_modules").length - 1;
96-
const downSteps = relativeForward.split("node_modules").length - 1;
97-
if (upSteps > 0) {
98-
return `up ${upSteps} stairs and down ${downSteps}.`
99-
} else if (downSteps > 0) {
100-
return `down ${downSteps} stair.` // should always be 1.
101-
} else {
102-
return `right through.`;
103-
}
104-
}
105-
10694
type Trap = {
10795
error: Error,
10896
details?: string
Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
1+
import { describeMove } from "../../../src/cli/support/describeMove";
2+
import * as assert from "assert";
3+
14
describe("color text for moving to another directory", () => {
25

36
it("move into an adjacent lib", () => {
7+
const result = describeMove("/Users/jessitron/code/other/yargs/node_modules/chai",
8+
"/Users/jessitron/code/other/yargs/node_modules/ucui");
9+
assert.strictEqual(result, "You step across into ucui.")
10+
});
411

5-
})
612

713
it("move down one", () => {
8-
14+
const result = describeMove("/Users/jessitron/code/other/yargs",
15+
"/Users/jessitron/code/other/yargs/node_modules/ucui");
16+
assert.strictEqual(result, "You descend into ucui.")
917
})
1018

11-
it("move into a global lib", () => {
19+
it("move into a global lib") // how does this work? it doesn't look in the places that my libs go
1220

21+
it("move up some random directories", () => {
22+
const result = describeMove("/Users/jessitron/code/other/yargs",
23+
"/Users/jessitron/code/node_modules/@atomist/automation-client");
24+
assert.strictEqual(result, "You climb two flights of stairs, then descend into @atomist/automation-client")
1325
})
1426

15-
it("move up some distance"), () => {
16-
17-
}
18-
19-
})
27+
it("move up some node_module directories", () => {
28+
const result = describeMove("/Users/jessitron/code/other/yargs/node_modules/chai/node_modules/subchai",
29+
"/Users/jessitron/code/other/yargs/node_modules/ucui");
30+
assert.strictEqual(result, "You climb one flight of stairs, then step into ucui")
31+
});
32+
});

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// "checkJs": true, /* Report errors in .js files. */
1515
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
1616
"declaration": true, /* Generates corresponding '.d.ts' file. */
17-
"declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
17+
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
1818
"sourceMap": true, /* Generates corresponding '.map' file. */
1919
// "outFile": "./", /* Concatenate and emit output to single file. */
2020
"outDir": "build", /* Redirect output structure to the directory. */

0 commit comments

Comments
 (0)