forked from jamesshore/testing-without-mocks-complex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_command_line_test.js
More file actions
67 lines (53 loc) · 2.05 KB
/
_command_line_test.js
File metadata and controls
67 lines (53 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright Titanium I.T. LLC.
import assert from "util/assert.js";
import { CommandLine } from "infrastructure/command_line.js";
import { runModuleAsync } from "util/test_helper.js";
import { pathToFile } from "util/module_paths.js";
// dependency_analysis: ./_command_line_test_args_runner
// dependency_analysis: ./_command_line_test_null_output_runner
// dependency_analysis: ./_command_line_test_output_runner
describe("CommandLine", () => {
it("provides command-line arguments", async () => {
const args = [ "my arg 1", "my arg 2" ];
const { stdout } = await runModuleAsync(
pathToFile(import.meta.url, "_command_line_test_args_runner.js"),
{ args },
);
assert.equal(stdout, '["my arg 1","my arg 2"]');
});
it("writes to stdout and stderr", async () => {
const { stdout, stderr } = await runModuleAsync(
pathToFile(import.meta.url, "_command_line_test_output_runner.js"),
{ failOnStderr: false },
);
assert.equal(stdout, "my stdout", "stdout");
assert.equal(stderr, "my stderr", "stderr");
});
it("tracks writes to stdout and stderr", () => {
const commandLine = CommandLine.createNull();
const stdout = commandLine.trackStdout();
const stderr = commandLine.trackStderr();
commandLine.writeStdout("my stdout");
commandLine.writeStderr("my stderr");
assert.deepEqual(stdout.data, [ "my stdout" ]);
assert.deepEqual(stderr.data, [ "my stderr" ]);
});
describe("nulled instances", () => {
it("defaults to no arguments", () => {
const commandLine = CommandLine.createNull();
assert.deepEqual(commandLine.args(), []);
});
it("allows arguments to be configured", () => {
const commandLine = CommandLine.createNull({ args: [ "one", "two" ] });
assert.deepEqual(commandLine.args(), [ "one", "two" ]);
});
it("doesn't write output to command line", async () => {
const { stdout, stderr } = await runModuleAsync(
pathToFile(import.meta.url, "_command_line_test_null_output_runner.js"),
{ failOnStderr: false },
);
assert.equal(stdout, "", "stdout");
assert.equal(stderr, "", "stderr");
});
});
});