MCPcopy Create free account
hub / github.com/Effect-TS/effect / createTestContext

Function createTestContext

packages/tools/oxc/test/utils.ts:15–46  ·  view source on GitHub ↗
(options: TestContextOptions = {})

Source from the content-addressed store, hash-verified

13}
14
15export const createTestContext = (options: TestContextOptions = {}) => {
16 const {
17 sourceCode = "",
18 filename = "/test/file.ts",
19 cwd = "/test",
20 ruleOptions = []
21 } = options
22
23 const errors: Array<ReportedError> = []
24 const context = {
25 id: "test/rule",
26 filename,
27 physicalFilename: filename,
28 cwd,
29 options: ruleOptions,
30 getFilename: () => filename,
31 getCwd: () => cwd,
32 report(reportOptions: ReportedError) {
33 errors.push(reportOptions)
34 },
35 sourceCode: {
36 text: sourceCode,
37 getText(node?: { range?: [number, number] } | null) {
38 if (node?.range) {
39 return sourceCode.slice(node.range[0], node.range[1])
40 }
41 return sourceCode
42 }
43 }
44 }
45 return { errors, context }
46}
47
48export const runRule = (
49 rule: CreateRule,

Callers 3

runRuleWithNodesFunction · 0.90
runFunction · 0.90
runRuleFunction · 0.85

Calls

no outgoing calls

Tested by 2

runRuleWithNodesFunction · 0.72
runFunction · 0.72