Skip to content

(PC-5740) feat: clear react-query cache after each test file #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 15, 2020
Merged
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
47 changes: 47 additions & 0 deletions scripts/detect_ko_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import os
import sys
import json
import subprocess
from time import time


def verify_arguments():
if (len(sys.argv) == 2):
return True
else:
print("Compatible with yarn packager and jest")
print("Usage: detetect_ko_test <path_to_repo>")
return False

def get_test_array():
process = subprocess.Popen('cd ' + sys.argv[1] + ' && yarn jest --listTests --json', shell=True, stdout=subprocess.PIPE)
process.wait()
return json.loads(process.stdout.readlines()[2])

def get_test_name(test_path):
test_path_array = test_path.split('/')
return test_path_array[-1]

def main():
if(not(verify_arguments())):
return
test_list = get_test_array()
total_time = 0
max_duration = 0
longest_test = ''
for test in test_list:
timestmp = time()
print(get_test_name(test))
process = subprocess.Popen('cd ' + sys.argv[1] + ' && yarn jest ' + test + ' --detectOpenHandles --runTestsByPath', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
process.wait()
test_time = time() - timestmp
total_time += test_time
if(test_time > max_duration):
max_duration = test_time
longest_test = get_test_name(test)
print('\033[31m' + '---- Time it took to do this test: ', str(test_time) + 's')
print('\033[39m')
print('Total time:', str(total_time) + 's')
print('Max duration is:', str(max_duration) + 's', 'For the test:', longest_test)

main()
4 changes: 3 additions & 1 deletion src/tests/reactQueryProviderHOC.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React from 'react'
import { QueryCache, QueryClient, QueryClientProvider } from 'react-query'

export const queryCache = new QueryCache()

export const reactQueryProviderHOC = (component: React.ReactNode) => {
const queryClient = new QueryClient({ cache: new QueryCache() })
const queryClient = new QueryClient({ cache: queryCache })
return <QueryClientProvider client={queryClient}>{component}</QueryClientProvider>
}
3 changes: 3 additions & 0 deletions src/tests/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import { toMatchDiffSnapshot } from 'snapshot-diff'

import { server } from 'tests/server'

import { queryCache } from './reactQueryProviderHOC'

global.expect.extend({ toMatchDiffSnapshot })

global.beforeAll(() => server.listen())

global.afterAll(() => {
server.resetHandlers()
server.close()
queryCache.clear()
})