Skip to content

Commit 3cc2372

Browse files
committed
refactor: move tests to specificly related folders
1 parent a82d5ef commit 3cc2372

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+67
-56
lines changed

.gitignore

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1+
# node
12
node_modules
2-
coverage
3+
4+
# build generated
35
lib
46
dom
57
native
68
server
79
pure
810
.docz
911
site
12+
13+
# tests (need the !files because of the build generated above)
14+
coverage
15+
!src/dom
16+
!src/native
17+
!src/server
18+
19+
# settings from IDE
1020
.vscode

jest.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
const { jest: jestConfig } = require('kcd-scripts/config')
33

44
module.exports = Object.assign(jestConfig, {
5-
roots: ['<rootDir>/src', '<rootDir>/test'],
6-
testMatch: ['<rootDir>/test/**/*.(ts|tsx|js)']
5+
roots: ['<rootDir>/src'],
6+
testMatch: ['<rootDir>/**/__tests__/*.(ts|tsx|js)']
77
})
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"extends": "../tsconfig",
2+
"extends": "../../tsconfig",
33
"compilerOptions": {
44
"declaration": false
55
},
66
"exclude": [],
7-
"include": ["./**/*.ts"]
7+
"include": ["**/*.test.(ts|tsx)"]
88
}

test/dom/asyncHook.ts renamed to src/dom/__tests__/asyncHook.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState, useRef, useEffect } from 'react'
2-
import { renderHook } from '../../src/dom'
2+
import { renderHook } from '../index'
33

44
describe('async hook tests', () => {
55
const useSequence = (...values: string[]) => {

test/native/autoCleanup.disabled.ts renamed to src/dom/__tests__/autoCleanup.disabled.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect } from 'react'
22

3-
import { ReactHooksRenderer } from 'types'
3+
import { ReactHooksRenderer } from '../../types/react'
44

55
// This verifies that if RHTL_SKIP_AUTO_CLEANUP is set
66
// then we DON'T auto-wire up the afterEach for folks
@@ -11,7 +11,7 @@ describe('skip auto cleanup (disabled) tests', () => {
1111
beforeAll(() => {
1212
process.env.RHTL_SKIP_AUTO_CLEANUP = 'true'
1313
// eslint-disable-next-line @typescript-eslint/no-var-requires
14-
renderHook = (require('../../src/native') as ReactHooksRenderer).renderHook
14+
renderHook = (require('../index') as ReactHooksRenderer).renderHook
1515
})
1616

1717
test('first', () => {

test/server/autoCleanup.noAfterEach.ts renamed to src/dom/__tests__/autoCleanup.noAfterEach.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect } from 'react'
22

3-
import { ReactHooksRenderer } from 'types'
3+
import { ReactHooksRenderer } from '../../types/react'
44

55
// This verifies that if RHTL_SKIP_AUTO_CLEANUP is set
66
// then we DON'T auto-wire up the afterEach for folks
@@ -13,7 +13,7 @@ describe('skip auto cleanup (no afterEach) tests', () => {
1313
// eslint-disable-next-line no-global-assign
1414
afterEach = false
1515
// eslint-disable-next-line @typescript-eslint/no-var-requires
16-
renderHook = (require('../../src/server') as ReactHooksRenderer).renderHook
16+
renderHook = (require('../index') as ReactHooksRenderer).renderHook
1717
})
1818

1919
test('first', () => {

test/dom/autoCleanup.ts renamed to src/dom/__tests__/autoCleanup.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect } from 'react'
2-
import { renderHook } from '../../src/dom'
2+
import { renderHook } from '../index'
33

44
// This verifies that by importing RHTL in an
55
// environment which supports afterEach (like Jest)

test/dom/cleanup.ts renamed to src/dom/__tests__/cleanup.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect } from 'react'
2-
import { renderHook, cleanup, addCleanup, removeCleanup } from '../../src/dom/pure'
2+
import { renderHook, cleanup, addCleanup, removeCleanup } from '../pure'
33

44
describe('cleanup tests', () => {
55
test('should flush effects on cleanup', async () => {

test/dom/customHook.ts renamed to src/dom/__tests__/customHook.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState, useCallback } from 'react'
2-
import { renderHook, act } from '../../src/dom'
2+
import { renderHook, act } from '../index'
33

44
describe('custom hook tests', () => {
55
function useCounter() {

test/dom/errorHook.ts renamed to src/dom/__tests__/errorHook.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState, useEffect } from 'react'
2-
import { renderHook } from '../../src/dom'
2+
import { renderHook } from '../index'
33

44
describe('error hook tests', () => {
55
function useError(throwError?: boolean) {

test/dom/resultHistory.ts renamed to src/dom/__tests__/resultHistory.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { renderHook } from '../../src/dom'
1+
import { renderHook } from '../index'
22

33
describe('result history tests', () => {
44
let count = 0

test/dom/suspenseHook.ts renamed to src/dom/__tests__/suspenseHook.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { renderHook } from '../../src/dom'
1+
import { renderHook } from '../index'
22

33
describe('suspense hook tests', () => {
44
const cache: { value?: Promise<string | Error> | string | Error } = {}

test/dom/useContext.tsx renamed to src/dom/__tests__/useContext.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { createContext, useContext } from 'react'
2-
import { renderHook } from '../../src/dom'
2+
import { renderHook } from '../index'
33

44
describe('useContext tests', () => {
55
test('should get default value from context', () => {

test/dom/useEffect.ts renamed to src/dom/__tests__/useEffect.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect, useLayoutEffect } from 'react'
2-
import { renderHook } from '../../src/dom'
2+
import { renderHook } from '../index'
33

44
describe('useEffect tests', () => {
55
test('should handle useEffect hook', () => {

test/dom/useMemo.ts renamed to src/dom/__tests__/useMemo.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useMemo, useCallback } from 'react'
2-
import { renderHook } from '../../src/dom'
2+
import { renderHook } from '../index'
33

44
describe('useCallback tests', () => {
55
test('should handle useMemo hook', () => {

test/dom/useReducer.ts renamed to src/dom/__tests__/useReducer.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useReducer } from 'react'
2-
import { renderHook, act } from '../../src/dom'
2+
import { renderHook, act } from '../index'
33

44
describe('useReducer tests', () => {
55
test('should handle useReducer hook', () => {

test/dom/useRef.ts renamed to src/dom/__tests__/useRef.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useRef, useImperativeHandle } from 'react'
2-
import { renderHook } from '../../src/dom'
2+
import { renderHook } from '../index'
33

44
describe('useHook tests', () => {
55
test('should handle useRef hook', () => {

test/dom/useState.ts renamed to src/dom/__tests__/useState.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState } from 'react'
2-
import { renderHook, act } from '../../src/dom'
2+
import { renderHook, act } from '../index'
33

44
describe('useState tests', () => {
55
test('should use setState value', () => {

test/native/asyncHook.ts renamed to src/native/__tests__/asyncHook.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState, useRef, useEffect } from 'react'
2-
import { renderHook } from '../../src/native'
2+
import { renderHook } from '../index'
33

44
describe('async hook tests', () => {
55
const useSequence = (...values: string[]) => {

test/dom/autoCleanup.disabled.ts renamed to src/native/__tests__/autoCleanup.disabled.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect } from 'react'
22

3-
import { ReactHooksRenderer } from 'types/react'
3+
import { ReactHooksRenderer } from '../../types/react'
44

55
// This verifies that if RHTL_SKIP_AUTO_CLEANUP is set
66
// then we DON'T auto-wire up the afterEach for folks
@@ -11,7 +11,7 @@ describe('skip auto cleanup (disabled) tests', () => {
1111
beforeAll(() => {
1212
process.env.RHTL_SKIP_AUTO_CLEANUP = 'true'
1313
// eslint-disable-next-line @typescript-eslint/no-var-requires
14-
renderHook = (require('../../src/dom') as ReactHooksRenderer).renderHook
14+
renderHook = (require('../index') as ReactHooksRenderer).renderHook
1515
})
1616

1717
test('first', () => {

test/dom/autoCleanup.noAfterEach.ts renamed to src/native/__tests__/autoCleanup.noAfterEach.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect } from 'react'
22

3-
import { ReactHooksRenderer } from 'types/react'
3+
import { ReactHooksRenderer } from '../../types/react'
44

55
// This verifies that if RHTL_SKIP_AUTO_CLEANUP is set
66
// then we DON'T auto-wire up the afterEach for folks
@@ -13,7 +13,7 @@ describe('skip auto cleanup (no afterEach) tests', () => {
1313
// eslint-disable-next-line no-global-assign
1414
afterEach = false
1515
// eslint-disable-next-line @typescript-eslint/no-var-requires
16-
renderHook = (require('../../src/dom') as ReactHooksRenderer).renderHook
16+
renderHook = (require('../index') as ReactHooksRenderer).renderHook
1717
})
1818

1919
test('first', () => {

test/native/autoCleanup.ts renamed to src/native/__tests__/autoCleanup.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect } from 'react'
2-
import { renderHook } from '../../src/native'
2+
import { renderHook } from '../index'
33

44
// This verifies that by importing RHTL in an
55
// environment which supports afterEach (like Jest)

test/native/cleanup.ts renamed to src/native/__tests__/cleanup.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect } from 'react'
2-
import { renderHook, cleanup, addCleanup, removeCleanup } from '../../src/native/pure'
2+
import { renderHook, cleanup, addCleanup, removeCleanup } from '../pure'
33

44
describe('cleanup tests', () => {
55
test('should flush effects on cleanup', async () => {

test/native/customHook.ts renamed to src/native/__tests__/customHook.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState, useCallback } from 'react'
2-
import { renderHook, act } from '../../src/native'
2+
import { renderHook, act } from '../index'
33

44
describe('custom hook tests', () => {
55
function useCounter() {

test/native/errorHook.ts renamed to src/native/__tests__/errorHook.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState, useEffect } from 'react'
2-
import { renderHook } from '../../src/native'
2+
import { renderHook } from '../index'
33

44
describe('error hook tests', () => {
55
function useError(throwError?: boolean) {

test/native/resultHistory.ts renamed to src/native/__tests__/resultHistory.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { renderHook } from '../../src/native'
1+
import { renderHook } from '../index'
22

33
describe('result history tests', () => {
44
let count = 0

test/native/suspenseHook.ts renamed to src/native/__tests__/suspenseHook.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { renderHook } from '../../src/native'
1+
import { renderHook } from '../index'
22

33
describe('suspense hook tests', () => {
44
const cache: { value?: Promise<string | Error> | string | Error } = {}

test/native/useContext.tsx renamed to src/native/__tests__/useContext.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { createContext, useContext } from 'react'
2-
import { renderHook } from '../../src/native'
2+
import { renderHook } from '../index'
33

44
describe('useContext tests', () => {
55
test('should get default value from context', () => {

test/native/useEffect.ts renamed to src/native/__tests__/useEffect.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect, useLayoutEffect } from 'react'
2-
import { renderHook } from '../../src/native'
2+
import { renderHook } from '../index'
33

44
describe('useEffect tests', () => {
55
test('should handle useEffect hook', () => {

test/native/useMemo.ts renamed to src/native/__tests__/useMemo.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useMemo, useCallback } from 'react'
2-
import { renderHook } from '../../src/native'
2+
import { renderHook } from '../index'
33

44
describe('useCallback tests', () => {
55
test('should handle useMemo hook', () => {

test/native/useReducer.ts renamed to src/native/__tests__/useReducer.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useReducer } from 'react'
2-
import { renderHook, act } from '../../src/native'
2+
import { renderHook, act } from '../index'
33

44
describe('useReducer tests', () => {
55
test('should handle useReducer hook', () => {

test/native/useRef.ts renamed to src/native/__tests__/useRef.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useRef, useImperativeHandle } from 'react'
2-
import { renderHook } from '../../src/native'
2+
import { renderHook } from '../index'
33

44
describe('useHook tests', () => {
55
test('should handle useRef hook', () => {

test/native/useState.ts renamed to src/native/__tests__/useState.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState } from 'react'
2-
import { renderHook, act } from '../../src/native'
2+
import { renderHook, act } from '../index'
33

44
describe('useState tests', () => {
55
test('should use setState value', () => {

test/server/asyncHook.ts renamed to src/server/__tests__/asyncHook.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useState, useRef, useEffect } from 'react'
22

3-
import { renderHook } from '../../src/server'
3+
import { renderHook } from '../index'
44

55
describe('async hook tests', () => {
66
const useSequence = (...values: string[]) => {

test/server/autoCleanup.disabled.ts renamed to src/server/__tests__/autoCleanup.disabled.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect } from 'react'
22

3-
import { ReactHooksRenderer } from 'types'
3+
import { ReactHooksRenderer } from '../../types/react'
44

55
// This verifies that if RHTL_SKIP_AUTO_CLEANUP is set
66
// then we DON'T auto-wire up the afterEach for folks
@@ -11,7 +11,7 @@ describe('skip auto cleanup (disabled) tests', () => {
1111
beforeAll(() => {
1212
process.env.RHTL_SKIP_AUTO_CLEANUP = 'true'
1313
// eslint-disable-next-line @typescript-eslint/no-var-requires
14-
renderHook = (require('../../src/server') as ReactHooksRenderer).renderHook
14+
renderHook = (require('../index') as ReactHooksRenderer).renderHook
1515
})
1616

1717
test('first', () => {

test/native/autoCleanup.noAfterEach.ts renamed to src/server/__tests__/autoCleanup.noAfterEach.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect } from 'react'
22

3-
import { ReactHooksRenderer } from 'types'
3+
import { ReactHooksRenderer } from '../../types/react'
44

55
// This verifies that if RHTL_SKIP_AUTO_CLEANUP is set
66
// then we DON'T auto-wire up the afterEach for folks
@@ -13,7 +13,7 @@ describe('skip auto cleanup (no afterEach) tests', () => {
1313
// eslint-disable-next-line no-global-assign
1414
afterEach = false
1515
// eslint-disable-next-line @typescript-eslint/no-var-requires
16-
renderHook = (require('../../src/native') as ReactHooksRenderer).renderHook
16+
renderHook = (require('../index') as ReactHooksRenderer).renderHook
1717
})
1818

1919
test('first', () => {

test/server/autoCleanup.ts renamed to src/server/__tests__/autoCleanup.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect } from 'react'
2-
import { renderHook } from '../../src/server'
2+
import { renderHook } from '../index'
33

44
// This verifies that by importing RHTL in an
55
// environment which supports afterEach (like Jest)

test/server/cleanup.ts renamed to src/server/__tests__/cleanup.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect } from 'react'
2-
import { renderHook, cleanup } from '../../src/server'
2+
import { renderHook, cleanup } from '../index'
33

44
describe('cleanup tests', () => {
55
test('should flush effects on cleanup', async () => {

test/server/customHook.ts renamed to src/server/__tests__/customHook.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState, useCallback } from 'react'
2-
import { renderHook, act } from '../../src/server'
2+
import { renderHook, act } from '../index'
33

44
describe('custom hook tests', () => {
55
function useCounter() {

test/server/errorHook.ts renamed to src/server/__tests__/errorHook.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useState, useEffect } from 'react'
22

3-
import { renderHook } from '../../src/server'
3+
import { renderHook } from '../index'
44

55
describe('error hook tests', () => {
66
function useError(throwError?: boolean) {

test/server/hydrationErrors.ts renamed to src/server/__tests__/hydrationErrors.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState, useCallback } from 'react'
2-
import { renderHook } from '../../src/server'
2+
import { renderHook } from '../index'
33

44
describe('hydration errors tests', () => {
55
function useCounter() {

test/server/useContext.tsx renamed to src/server/__tests__/useContext.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { createContext, useContext } from 'react'
2-
import { renderHook } from '../../src/server'
2+
import { renderHook } from '../index'
33

44
describe('useContext tests', () => {
55
test('should get default value from context', () => {

test/server/useEffect.ts renamed to src/server/__tests__/useEffect.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect } from 'react'
2-
import { renderHook } from '../../src/server'
2+
import { renderHook } from '../index'
33

44
describe('useEffect tests', () => {
55
test('should handle useEffect hook', () => {

test/server/useMemo.ts renamed to src/server/__tests__/useMemo.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useMemo, useCallback } from 'react'
2-
import { renderHook } from '../../src/server'
2+
import { renderHook } from '../index'
33

44
describe('useCallback tests', () => {
55
test('should handle useMemo hook', () => {

test/server/useReducer.ts renamed to src/server/__tests__/useReducer.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useReducer } from 'react'
2-
import { renderHook, act } from '../../src/server'
2+
import { renderHook, act } from '../index'
33

44
describe('useReducer tests', () => {
55
test('should handle useReducer hook', () => {

0 commit comments

Comments
 (0)