forked from artsy/force
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dangerfile.ts
44 lines (38 loc) · 1.31 KB
/
dangerfile.ts
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
/* eslint-disable jest/no-jasmine-globals */
import { danger, warn } from "danger"
import * as fs from "fs"
/**
* Helpers
*/
const filesOnly = (file: string) =>
fs.existsSync(file) && fs.lstatSync(file).isFile()
// Modified or Created can be treated the same a lot of the time
const getCreatedFiles = (createdFiles: string[]) =>
createdFiles.filter(filesOnly)
/**
* Rules
*/
function preventDefaultQueryRenderImport() {
const newQueryRendererImports = getCreatedFiles(
danger.git.created_files
).filter(filename => {
const content = fs.readFileSync(filename).toString()
return content.includes("<QueryRenderer")
})
if (newQueryRendererImports.length > 0) {
fail(`Please use \`<SystemQueryRenderer />\` instead of \`<QueryRender />\`. This prevents double fetching during the server-side render pass. See:
> ${newQueryRendererImports.map(filename => `\`${filename}\``).join("\n")}`)
}
}
function warnCreateSmokeTestIfRoutesFileChanged() {
const modified = danger.git.modified_files
if (modified.includes("src/v2/routes.tsx")) {
warn(
"Routes added to `routes.tsx` should have a corresponding cypress.js smoke test. See the `cypress/integration` folder for examples."
)
}
}
;(async function () {
preventDefaultQueryRenderImport()
warnCreateSmokeTestIfRoutesFileChanged()
})()