-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathCommandLineArgumentsTest.res
More file actions
126 lines (112 loc) · 4.54 KB
/
Copy pathCommandLineArgumentsTest.res
File metadata and controls
126 lines (112 loc) · 4.54 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
open Node
let assertCommandLineArguments = (actual: CommandLineArguments.t, ~projectName, ~templateName) => {
Assert.strictEqual(actual.projectName, projectName)
Assert.strictEqual(actual.templateName, templateName)
}
let assertParseError = (~remainingArguments, ~message) =>
switch CommandLineArguments.parse(remainingArguments) {
| Ok(_) => Assert.fail(`Expected parse error: ${message}`)
| Error(actualMessage) => Assert.strictEqual(actualMessage, message)
}
Test.describe("CommandLineArguments", () => {
Test.test("returns empty values when no arguments are provided", () => {
switch CommandLineArguments.parse(list{}) {
| Ok(commandLineArguments) =>
commandLineArguments->assertCommandLineArguments(~projectName=None, ~templateName=None)
| Error(message) => Assert.fail(message)
}
})
Test.test("parses the project name from the first positional argument", () => {
switch CommandLineArguments.parse(list{"my-app"}) {
| Ok(commandLineArguments) =>
commandLineArguments->assertCommandLineArguments(
~projectName=Some("my-app"),
~templateName=None,
)
| Error(message) => Assert.fail(message)
}
})
Test.test("parses the current directory as a project name", () => {
switch CommandLineArguments.parse(list{"."}) {
| Ok(commandLineArguments) =>
commandLineArguments->assertCommandLineArguments(~projectName=Some("."), ~templateName=None)
| Error(message) => Assert.fail(message)
}
})
Test.test("parses the template name from the -t flag", () => {
switch CommandLineArguments.parse(list{"my-app", "-t", "vite"}) {
| Ok(commandLineArguments) =>
commandLineArguments->assertCommandLineArguments(
~projectName=Some("my-app"),
~templateName=Some(Templates.viteTemplateName),
)
| Error(message) => Assert.fail(message)
}
})
Test.test("parses the template name from the --template flag", () => {
switch CommandLineArguments.parse(list{"my-app", "--template", "nextjs"}) {
| Ok(commandLineArguments) =>
commandLineArguments->assertCommandLineArguments(
~projectName=Some("my-app"),
~templateName=Some(Templates.nextjsTemplateName),
)
| Error(message) => Assert.fail(message)
}
})
Test.test("parses the template name from the --template=... flag", () => {
switch CommandLineArguments.parse(list{"my-app", "--template=basic"}) {
| Ok(commandLineArguments) =>
commandLineArguments->assertCommandLineArguments(
~projectName=Some("my-app"),
~templateName=Some(Templates.basicTemplateName),
)
| Error(message) => Assert.fail(message)
}
})
Test.test("ignores the node executable and script path in process argv", () => {
switch CommandLineArguments.fromProcessArgv([
"/usr/local/bin/node",
"/tmp/create-rescript-app",
"my-app",
"-t",
"vite",
]) {
| Ok(commandLineArguments) =>
commandLineArguments->assertCommandLineArguments(
~projectName=Some("my-app"),
~templateName=Some(Templates.viteTemplateName),
)
| Error(message) => Assert.fail(message)
}
})
Test.test("rejects a missing template value", () => {
assertParseError(
~remainingArguments=list{"my-app", "--template"},
~message="Missing value for --template. Supported options: --template <vite|nextjs|xote|xote-ssr|basic> or -t <vite|nextjs|xote|xote-ssr|basic>.",
)
})
Test.test("rejects unknown options", () => {
assertParseError(
~remainingArguments=list{"my-app", "--yes"},
~message="Unknown option \"--yes\". Supported options: --template <vite|nextjs|xote|xote-ssr|basic> or -t <vite|nextjs|xote|xote-ssr|basic>.",
)
})
Test.test("rejects unknown templates", () => {
assertParseError(
~remainingArguments=list{"my-app", "--template", "unknown"},
~message="Unknown template \"unknown\". Available templates: vite, nextjs, xote, xote-ssr, basic.",
)
})
Test.test("rejects positional templates", () => {
assertParseError(
~remainingArguments=list{"my-app", "vite"},
~message="Unexpected argument \"vite\". Supported options: --template <vite|nextjs|xote|xote-ssr|basic> or -t <vite|nextjs|xote|xote-ssr|basic>.",
)
})
Test.test("rejects additional positional arguments after the template", () => {
assertParseError(
~remainingArguments=list{"my-app", "-t", "vite", "extra"},
~message="Unexpected argument \"extra\". Supported options: --template <vite|nextjs|xote|xote-ssr|basic> or -t <vite|nextjs|xote|xote-ssr|basic>.",
)
})
})