-
Notifications
You must be signed in to change notification settings - Fork 9
/
cli.test.js
85 lines (76 loc) · 2.31 KB
/
cli.test.js
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
#!/usr/bin/env node
const fs = require("fs");
const mkpath = require("mkpath");
const { execSync } = require("child_process");
// base is defined as a location outside a git repo. Assumes I have write
// access to .. :)
const base = "../.kebab-ify-test";
const widgetContents = `
//#
//# Test file
//#
import Avatar from '../../Components/Avatar'
import SomeThing from '../../Components/SomeThing'
import SomeThingElse from '../../components/SomeThingElse'
//
// The rest of the file isn't important
//
`;
const avatarContents = `
//#
//# Avatar component test file
//#
import SomeThing from '../../components/SomeThing'
//
// The rest of the file isn't important
//
`;
afterAll(() => {
execSync(`rm -rf ${base}`);
});
//
// Defensive cleanup of old test folder
//
if (fs.existsSync(base)) {
execSync(`rm -rf ${base}/*`);
}
mkpath.sync(`${base}/src/Components/MyWidget`);
const widgetsrc = `${base}/src/Components/MyWidget/MyWidget.js`;
fs.writeFileSync(widgetsrc, widgetContents, {
encoding: "utf8"
});
const avatarsrc = `${base}/src/Components/Avatar.js`;
fs.writeFileSync(avatarsrc, avatarContents, {
encoding: "utf8"
});
const setupTestsFile = `${base}/src/setupTests.ts`;
fs.writeFileSync(setupTestsFile, "Contents not important", {
encoding: "utf8"
});
test("Files are set up", async () => {
await expect(fs.existsSync(base)).toBeTruthy();
await expect(fs.existsSync(widgetsrc)).toBeTruthy();
});
test("Kebab-ify!!!", () => {
expect(execSync("kebab-ify src", { cwd: base })).toBeTruthy();
});
test("PascalCase files are not there any more", () => {
expect(fs.existsSync(base)).toBeTruthy();
// Because MacOS isn't case sensitive, this folder appears to be there, even though it
// has been renamed, so we can't do this test
// expect(fs.existsSync(`${base}/src/Components`)).toBeFalsy()
expect(fs.existsSync(`${base}/src/Components/MyWidget`)).toBeFalsy();
expect(
fs.existsSync(`${base}/src/Components/MyWidget/MyWidget.js`)
).toBeFalsy();
});
test("kebab-case files are there", () => {
expect(fs.existsSync(base)).toBeTruthy();
expect(fs.existsSync(`${base}/src/components`)).toBeTruthy();
expect(
fs.existsSync(`${base}/src/components/my-widget/my-widget.js`)
).toBeTruthy();
});
test("setupTests file is preserved", async () => {
await expect(fs.existsSync(setupTestsFile)).toBeTruthy();
});