-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathNewProjectLocationTest.res
More file actions
65 lines (52 loc) · 2.47 KB
/
Copy pathNewProjectLocationTest.res
File metadata and controls
65 lines (52 loc) · 2.47 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-location-test")
let currentDirectoryConflictMessage = "The current directory contains files that could conflict with project creation."
let cleanupTestRoot = async () =>
await Fs.Promises.rm(testRoot, ~options={recursive: true, force: true})
let resetTestRoot = async projectDirectoryName => {
await cleanupTestRoot()
let projectPath = Path.join2(testRoot, projectDirectoryName)
await Fs.Promises.mkdir(projectPath, ~options={recursive: true})
projectPath
}
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}`)
}
Test.describe("NewProjectLocation", () => {
Test.test("uses the current directory basename as the package name", () => {
NewProjectLocation.getPackageName(~cwd="/tmp/my-app", ".")->Assert.strictEqual("my-app")
})
Test.test("uses the current directory as the project path", () => {
NewProjectLocation.getProjectPath(~cwd="/tmp/my-app", ".")->Assert.strictEqual("/tmp/my-app")
})
Test.testAsync("allows creating in a repository with README and license files", async () => {
let projectPath = await resetTestRoot("my-app")
await Fs.Promises.mkdir(Path.join2(projectPath, ".git"))
await Fs.Promises.writeFile(Path.join2(projectPath, "README.md"), "")
await Fs.Promises.writeFile(Path.join2(projectPath, "LICENSE"), "")
NewProjectLocation.validateProjectName(~cwd=projectPath, ".")->assertValidationOk
await cleanupTestRoot()
})
Test.testAsync("rejects creating in a current directory with project files", async () => {
let projectPath = await resetTestRoot("my-app")
await Fs.Promises.writeFile(Path.join2(projectPath, "src"), "")
NewProjectLocation.validateProjectName(~cwd=projectPath, ".")->assertValidationError(
currentDirectoryConflictMessage,
)
await cleanupTestRoot()
})
Test.testAsync("rejects creating a nested project that already exists", async () => {
let _ = await resetTestRoot("existing-app")
NewProjectLocation.validateProjectName(~cwd=testRoot, "existing-app")->assertValidationError(
"The folder existing-app already exist in the current directory.",
)
await cleanupTestRoot()
})
})