Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ast/src/lang/queries/react_ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ impl Stack for TypeScriptReact {
)
) @{VARIABLE_DECLARATION}

)
(program
(expression_statement
(assignment_expression
left: (member_expression) @{VARIABLE_NAME}
right: [{types}(call_expression)]+ @{VARIABLE_VALUE}
)
) @{VARIABLE_DECLARATION}
)"#,
))
}
Expand Down
18 changes: 9 additions & 9 deletions ast/src/testing/coverage/nextjs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ async fn test_nextjs_graph_upload() -> Result<()> {
let graph_ops = setup_nextjs_graph().await?;
let (nodes, edges) = graph_ops.get_graph_size().await?;

assert_eq!(nodes, 536);
assert_eq!(edges, 888);
assert_eq!(nodes, 558);
assert_eq!(edges, 925);

Ok(())
}
Expand Down Expand Up @@ -388,8 +388,8 @@ async fn test_nodes_function_type() -> Result<()> {
)
.await?;

assert_eq!(count, 55);
assert_eq!(results.len(), 55);
assert_eq!(count, 62);
assert_eq!(results.len(), 62);

for (node_type, _, _, _, _, _, _, _, _) in &results {
assert_eq!(*node_type, NodeType::Function);
Expand Down Expand Up @@ -473,8 +473,8 @@ async fn test_nodes_unit_test_type() -> Result<()> {
)
.await?;

assert_eq!(count, 30);
assert_eq!(results.len(), 30);
assert_eq!(count, 33);
assert_eq!(results.len(), 33);

Ok(())
}
Expand Down Expand Up @@ -527,7 +527,7 @@ async fn test_nodes_multi_type() -> Result<()> {
)
.await?;

assert_eq!(count, 76);
assert_eq!(count, 83);

let has_function = results
.iter()
Expand Down Expand Up @@ -567,8 +567,8 @@ async fn test_nodes_all_test_types() -> Result<()> {
)
.await?;

assert_eq!(count, 54);
assert_eq!(results.len(), 54);
assert_eq!(count, 57);
assert_eq!(results.len(), 57);

Ok(())
}
Expand Down
41 changes: 41 additions & 0 deletions ast/src/testing/nextjs/app/test/unit.noisy-patterns.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// @ts-nocheck
import { createApiHandlers, deepConfig, apiService } from "../../lib/noisy-patterns";

describe("unit: noisy patterns - category 3 (returned from function)", () => {
it("calls onSuccess handler", () => {
const handlers = createApiHandlers();
const result = handlers.onSuccess({ amount: 42 });
expect(result).toBeDefined();
});

it("calls onError handler", () => {
const handlers = createApiHandlers();
handlers.onError(new Error("fail"));
});
});

describe("unit: noisy patterns - category 4 (deep config)", () => {
it("accesses deeply nested handler", async () => {
const result = await deepConfig.level1.level2.handler();
expect(result.ready).toBe(true);
});

it("accesses deeply nested transform", () => {
const result = deepConfig.level1.level2.transform("hello");
expect(result).toBe("HELLO");
});
});

describe("unit: noisy patterns - category 5 (class method return)", () => {
it("uses parse from getHandlers", () => {
const handlers = apiService.getHandlers();
const data = handlers.parse('{"a":1}');
expect(data.a).toBe(1);
});

it("uses serialize from getHandlers", () => {
const handlers = apiService.getHandlers();
const json = handlers.serialize({ b: 2 });
expect(json).toBe('{"b":2}');
});
});
42 changes: 42 additions & 0 deletions ast/src/testing/nextjs/lib/noisy-patterns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// @ts-nocheck
import { formatNumber } from "./helpers";

global.fetch = jest.fn().mockResolvedValue({
json: async () => ({ id: 1, name: "mock" }),
text: async () => "raw body",
});


jest.mock("./helpers", () => ({
fetchUser: async (id: string) => ({ id, name: "mocked-user" }),
deleteUser: async (id: string) => true,
}));

export function createApiHandlers() {
return {
onSuccess: (data: any) => formatNumber(data.amount),
onError: (err: any) => console.error(err),
};
}

export const deepConfig = {
level1: {
level2: {
handler: async () => {
return { ready: true };
},
transform: (input: string) => input.toUpperCase(),
},
},
};

class ApiService {
getHandlers() {
return {
parse: (raw: string) => JSON.parse(raw),
serialize: (obj: any) => JSON.stringify(obj),
};
}
}

export const apiService = new ApiService();
Loading
Loading