-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathNewProjectValidationTest.res
More file actions
65 lines (53 loc) · 2.14 KB
/
Copy pathNewProjectValidationTest.res
File metadata and controls
65 lines (53 loc) · 2.14 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
open Node
let testRoot = Path.join2(Process.cwd(), ".tmp-new-project-validation-test")
let existingProjectMessage = "The folder my-app already exist in the current directory."
let cleanupTestRoot = async () =>
await Fs.Promises.rm(testRoot, ~options={recursive: true, force: true})
let resetTestRoot = async () => {
await cleanupTestRoot()
await Fs.Promises.mkdir(testRoot, ~options={recursive: true})
}
let assertValidationOk = result =>
switch result {
| Ok() => ()
| Error(message) => Assert.fail(`Expected project name to be valid, got: ${message}`)
}
let assertValidationError = (result, expectedMessage) =>
switch result {
| Error(message) => Assert.strictEqual(message, expectedMessage)
| Ok() => Assert.fail(`Expected validation error: ${expectedMessage}`)
}
let validateProjectName = projectName =>
NewProjectValidation.validateProjectName(~cwd=testRoot, projectName)
Test.describe("NewProjectValidation", () => {
Test.testAsync("allows an existing project directory with only .devcontainer", async () => {
await resetTestRoot()
await Fs.Promises.mkdir(
Path.join([testRoot, "my-app", ".devcontainer"]),
~options={
recursive: true,
},
)
validateProjectName("my-app")->assertValidationOk
await cleanupTestRoot()
})
Test.testAsync("rejects an existing project directory with additional files", async () => {
await resetTestRoot()
await Fs.Promises.mkdir(
Path.join([testRoot, "my-app", ".devcontainer"]),
~options={
recursive: true,
},
)
await Fs.Promises.writeFile(Path.join([testRoot, "my-app", "package.json"]), "{}")
validateProjectName("my-app")->assertValidationError(existingProjectMessage)
await cleanupTestRoot()
})
Test.testAsync("rejects an existing project directory with a .devcontainer file", async () => {
await resetTestRoot()
await Fs.Promises.mkdir(Path.join2(testRoot, "my-app"), ~options={recursive: true})
await Fs.Promises.writeFile(Path.join([testRoot, "my-app", ".devcontainer"]), "")
validateProjectName("my-app")->assertValidationError(existingProjectMessage)
await cleanupTestRoot()
})
})