-
Notifications
You must be signed in to change notification settings - Fork 965
/
template.test.js
102 lines (91 loc) · 2.54 KB
/
template.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* eslint-env node, es2022 */
import assert from 'node:assert'
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { test } from 'node:test'
const TEMPLATE_PATH = path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
'../template'
)
// If you add, move, or remove a file from the create-redwood-app template,
// you'll have to update this test.
test("the file structure hasn't unintentionally changed", () => {
assert.deepStrictEqual(walk(TEMPLATE_PATH), [
'/.editorconfig',
'/.env',
'/.env.defaults',
'/.env.example',
'/.nvmrc',
'/.vscode/extensions.json',
'/.vscode/launch.json',
'/.vscode/settings.json',
'/.yarn/releases/yarn-3.5.0.cjs',
'/.yarnrc.yml',
'/README.md',
'/api/db/schema.prisma',
'/api/jest.config.js',
'/api/package.json',
'/api/server.config.js',
'/api/src/directives/requireAuth/requireAuth.test.ts',
'/api/src/directives/requireAuth/requireAuth.ts',
'/api/src/directives/skipAuth/skipAuth.test.ts',
'/api/src/directives/skipAuth/skipAuth.ts',
'/api/src/functions/graphql.ts',
'/api/src/graphql/.keep',
'/api/src/lib/auth.ts',
'/api/src/lib/db.ts',
'/api/src/lib/logger.ts',
'/api/src/services/.keep',
'/api/tsconfig.json',
'/gitignore.template',
'/graphql.config.js',
'/jest.config.js',
'/package.json',
'/prettier.config.js',
'/redwood.toml',
'/scripts/.keep',
'/scripts/seed.ts',
'/scripts/tsconfig.json',
'/web/jest.config.js',
'/web/package.json',
'/web/public/README.md',
'/web/public/favicon.png',
'/web/public/robots.txt',
'/web/src/App.tsx',
'/web/src/Routes.tsx',
'/web/src/components/.keep',
'/web/src/index.css',
'/web/src/index.html',
'/web/src/layouts/.keep',
'/web/src/pages/FatalErrorPage/FatalErrorPage.tsx',
'/web/src/pages/NotFoundPage/NotFoundPage.tsx',
'/web/tsconfig.json',
])
})
/**
* Get all the files in a directory.
*
* @param {string} dir
* @returns string[]
*/
function walk(dir) {
/** @type {string[]} */
let files = []
const fileList = fs.readdirSync(dir)
fileList.forEach((file) => {
file = path.join(dir, file)
const stat = fs.statSync(file)
if (!stat) {
throw new Error(`Failed to get stats for ${file}`)
}
if (stat.isDirectory()) {
// Recurse into directory
files = files.concat(walk(file))
} else {
// It's a file
files.push(file)
}
})
return files.map((file) => file.replace(TEMPLATE_PATH, ''))
}