-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
69 lines (65 loc) · 2.06 KB
/
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
import test from "ava"
import { readFile } from "fs/promises"
import { execSync } from "child_process"
import recursiveReadir from "recursive-readdir"
import rmfr from "rmfr"
async function dirToTree(dir) {
const filePaths = await recursiveReadir(dir)
const obj = {}
for (const filePath of filePaths) {
if (filePath.includes("node_modules/")) continue
const fileContent = (await readFile(filePath, "utf8")).toString()
obj[filePath] = fileContent
}
return obj
}
const commands = [
`ava-config`,
`gitignore`,
`prettierrc yes`,
"node-pg-migrate no",
"github-ci-test no",
"github-ci-test yes",
"github-ci-vercel-deploy yes",
"github-ci-release no no",
"github-ci-release yes no",
"tsconfig",
]
test("snapshot for a bunch of commands", async (t) => {
for (const cmd of commands) {
try {
await rmfr("./test-output")
execSync(
`mkdir -p ./test-output && cd ./test-output && echo '{ "name": "some-package" }' > package.json && npx plop --plopfile ../plopfile.js --cwd $(pwd) --dest $(pwd) ${cmd}`,
{
shell: true,
}
)
const fileTree = await dirToTree("./test-output")
t.snapshot(
`${Object.entries(fileTree)
.map(([fp, fc]) => [fp.replace("test-output/", ""), fc])
.filter(([fp]) => fp !== "yarn.lock")
.filter(([fp, content]) => {
// Filter out package.json unless it's been modified
if (fp !== "package.json") return true
const packageJSON = JSON.parse(content)
// If it has more than just the "name", it's been modified
if (Object.keys(packageJSON).length > 1) return true
return false
})
.map(
([filePath, fileContent]) =>
`\n\n\n// ${filePath}\n\n${fileContent}`
)
.join("")}`.trim(),
`seam-plop ${cmd}`
)
await rmfr("./test-output")
} catch (e) {
t.fail(
`Command failed "${cmd}"\n${e.toString()}\nstdout:${e.stdout?.toString()}\nstderr:${e.stderr?.toString()}`
)
}
}
})