|
| 1 | +name: "JavaScript: simple ES module imports and cross-file resolution" |
| 2 | +pipeline: js |
| 3 | +fixtures: |
| 4 | + - path: utils.js |
| 5 | + content: | |
| 6 | + export function helper() { |
| 7 | + return "help"; |
| 8 | + } |
| 9 | +
|
| 10 | + export function unused() { |
| 11 | + return "unused"; |
| 12 | + } |
| 13 | +
|
| 14 | + - path: main.js |
| 15 | + content: | |
| 16 | + import { helper } from './utils'; |
| 17 | +
|
| 18 | + function run() { |
| 19 | + helper(); |
| 20 | + } |
| 21 | +
|
| 22 | +tests: |
| 23 | + - name: Exactly 1 import extracted |
| 24 | + query: | |
| 25 | + MATCH (i:ImportedSymbol) |
| 26 | + WHERE i.file_path = 'main.js' |
| 27 | + RETURN i.name AS name, i.path AS path |
| 28 | + assert: |
| 29 | + - { row_count: 1 } |
| 30 | + - { row: { name: "helper", path: "./utils" } } |
| 31 | + |
| 32 | + - name: No imports from utils.js |
| 33 | + query: | |
| 34 | + MATCH (i:ImportedSymbol) |
| 35 | + WHERE i.file_path = 'utils.js' |
| 36 | + RETURN count(i) AS n |
| 37 | + assert: |
| 38 | + - { row_count: 1 } |
| 39 | + - { row: { n: 0 } } |
| 40 | + |
| 41 | + - name: Cross-file call from run to helper |
| 42 | + query: | |
| 43 | + MATCH (caller:Definition)-[e:DefinitionToDefinition]->(callee:Definition) |
| 44 | + WHERE caller.name = 'run' AND callee.name = 'helper' |
| 45 | + AND caller.file_path <> callee.file_path |
| 46 | + AND e.edge_kind = 'Calls' |
| 47 | + RETURN caller.fqn AS caller, callee.fqn AS callee |
| 48 | + assert: |
| 49 | + - { row_count: 1 } |
| 50 | + - { row: { caller: "run", callee: "helper" } } |
| 51 | + |
| 52 | + - name: unused has no incoming cross-file calls |
| 53 | + query: | |
| 54 | + MATCH (caller:Definition)-[e:DefinitionToDefinition]->(callee:Definition) |
| 55 | + WHERE callee.name = 'unused' AND e.edge_kind = 'Calls' |
| 56 | + RETURN caller.fqn AS caller |
| 57 | + assert: |
| 58 | + - { empty: true } |
| 59 | + |
| 60 | + - name: Exactly 3 definitions across both files |
| 61 | + query: | |
| 62 | + MATCH (d:Definition) |
| 63 | + WHERE d.definition_type = 'Function' |
| 64 | + RETURN d.name AS name, d.file_path AS file |
| 65 | + ORDER BY name |
| 66 | + assert: |
| 67 | + - { row_count: 3 } |
| 68 | + - { unique: name } |
| 69 | + - { row: { name: "helper", file: "utils.js" } } |
| 70 | + - { row: { name: "run", file: "main.js" } } |
| 71 | + - { row: { name: "unused", file: "utils.js" } } |
| 72 | + |
| 73 | + - name: Exactly 2 JavaScript files |
| 74 | + query: | |
| 75 | + MATCH (f:File) |
| 76 | + RETURN f.path AS path |
| 77 | + ORDER BY path |
| 78 | + assert: |
| 79 | + - { row_count: 2 } |
| 80 | + - { column_values: { field: path, values: ["main.js", "utils.js"] } } |
0 commit comments