Skip to content

Commit

Permalink
Address performance error
Browse files Browse the repository at this point in the history
  • Loading branch information
rendall committed Oct 4, 2023
1 parent 98e4fcd commit 0e8458c
Show file tree
Hide file tree
Showing 2 changed files with 7,382 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/tests/frontend/frontend-utilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
* @jest-environment jsdom
*/
import { longFormatDate, threadComments } from "../../frontend-utilities"
import { Comment } from "../../lib/simple-comment-types"
import { Comment, Discussion } from "../../lib/simple-comment-types"
import { mockCommentTree, mockTopic } from "../mockData"
import { performance } from "perf_hooks"
import { debounceFunc } from "../../frontend-utilities"
import mockDiscussion from "../mockDiscussion.json";

Check failure on line 9 in src/tests/frontend/frontend-utilities.test.ts

View workflow job for this annotation

GitHub Actions / test-netlify-functions

Extra semicolon

describe("threadComments", () => {
it("should thread comments correctly", () => {
Expand Down Expand Up @@ -42,11 +43,25 @@ describe("threadComments", () => {
expect(result).toEqual(expected)
})

it("should thread mockDiscussion.json in under 0.1s", () => {
const topic = mockDiscussion as unknown as Discussion;

Check failure on line 47 in src/tests/frontend/frontend-utilities.test.ts

View workflow job for this annotation

GitHub Actions / test-netlify-functions

Extra semicolon

const topicReplies = topic.replies as Comment[]

const t0 = performance.now()

threadComments(topic, topicReplies)

const t1 = performance.now()

expect(t1 - t0).toBeLessThan(100)
})

it("should thread flat array of 2000 comments in under 1s", () => {
const topic = mockTopic()
const largeCommentsArray = mockCommentTree(2000, undefined, [
topic,
]) as Comment[] // replace this with your function to generate a large array of comments
]) as Comment[]

const t0 = performance.now()

Expand Down
Loading

0 comments on commit 0e8458c

Please sign in to comment.