Skip to content

Commit 548d7b4

Browse files
chore: moving unit tests (#943)
1 parent 19e076e commit 548d7b4

File tree

76 files changed

+315
-320
lines changed

Some content is hidden

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

76 files changed

+315
-320
lines changed

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ module.exports = {
5858
}
5959
},
6060
{
61-
files: ['src/**/*.test.js', 'src/**/__mocks__/**/*', 'tests/components/**/*'],
61+
files: ['src/**/__mocks__/**/*', 'tests/unit/**/*', 'tests/components/**/*'],
6262
env: {
6363
browser: true,
6464
node: true,

babel.config.js

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ module.exports = function (api, ...args) {
1414
process.env.RRWEB_VERSION = pkg.dependencies.rrweb
1515

1616
const ignore = [
17-
'**/*.test.js',
1817
'**/__mocks__/*.js'
1918
]
2019
const presets = [

jest.config.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ module.exports = {
1515
coverageDirectory: 'coverage',
1616
collectCoverageFrom: [
1717
'src/**/*.js',
18-
'!src/**/*.test.js',
19-
'!src/**/*.component-test.js',
2018
'!src/index.js',
2119
'!src/cdn/**/*.js',
2220
'!src/features/*/index.js',
@@ -27,7 +25,7 @@ module.exports = {
2725
{
2826
...commonConfig,
2927
displayName: 'unit',
30-
testMatch: ['<rootDir>/src/**/?(*.)+(test).[tj]s?(x)']
28+
testMatch: ['<rootDir>/tests/unit/**/?(*.)+(test).[tj]s?(x)']
3129
},
3230
{
3331
...commonConfig,

src/loaders/browser-agent.test.js

-51
This file was deleted.

src/common/aggregate/aggregator.test.js renamed to tests/unit/common/aggregate/aggregator.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Aggregator } from './aggregator.js'
1+
import { Aggregator } from '../../../../src/common/aggregate/aggregator.js'
22

33
let aggregator
44
beforeEach(() => {

src/common/config/state/configurable.test.js renamed to tests/unit/common/config/state/configurable.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getModeledObject } from './configurable'
1+
import { getModeledObject } from '../../../../../src/common/config/state/configurable'
22

33
test('if either params are not objects, function fails', () => {
44
let result = getModeledObject(123, {})

src/common/config/state/info.test.js renamed to tests/unit/common/config/state/info.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
let isValid, getInfo, setInfo
22
beforeEach(async () => {
33
jest.resetModules()
4-
;({ isValid, getInfo, setInfo } = await import('./info.js'))
4+
;({ isValid, getInfo, setInfo } = await import('../../../../../src/common/config/state/info.js'))
55
})
66

77
test('set/getInfo should throw on an invalid agent id', () => {

src/common/config/state/init.test.js renamed to tests/unit/common/config/state/init.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
let getConfiguration, setConfiguration, getConfigurationValue
22
beforeEach(async () => {
33
jest.resetModules()
4-
;({ getConfiguration, setConfiguration, getConfigurationValue } = await import('./init.js'))
4+
;({ getConfiguration, setConfiguration, getConfigurationValue } = await import('../../../../../src/common/config/state/init.js'))
55
})
66

77
test('set/getConfiguration should throw on an invalid agent id', () => {

src/common/config/state/loader-config.test.js renamed to tests/unit/common/config/state/loader-config.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
let getLoaderConfig, setLoaderConfig
22
beforeEach(async () => {
33
jest.resetModules()
4-
;({ getLoaderConfig, setLoaderConfig } = await import('./loader-config.js'))
4+
;({ getLoaderConfig, setLoaderConfig } = await import('../../../../../src/common/config/state/loader-config.js'))
55
})
66

77
test('set/getLoaderConfig should throw on an invalid agent id', () => {

src/common/config/state/runtime.test.js renamed to tests/unit/common/config/state/runtime.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
let getRuntime, setRuntime
22
beforeEach(async () => {
33
jest.resetModules()
4-
;({ getRuntime, setRuntime } = await import('./runtime.js'))
4+
;({ getRuntime, setRuntime } = await import('../../../../../src/common/config/state/runtime.js'))
55
})
66

77
test('set/getRuntime should throw on an invalid agent id', () => {

src/common/constants/env.cdn.test.js renamed to tests/unit/common/constants/env.cdn.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as env from './env.cdn'
1+
import * as env from '../../../../src/common/constants/env.cdn'
22

33
test('should default environment variables to CDN values', async () => {
44
expect(env.VERSION).toMatch(/\d{1,3}\.\d{1,3}\.\d{1,3}/)

src/common/constants/env.npm.test.js renamed to tests/unit/common/constants/env.npm.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as env from './env.npm'
1+
import * as env from '../../../../src/common/constants/env.npm'
22

33
test('should default environment variables to NPM values', () => {
44
expect(env.VERSION).toMatch(/\d{1,3}\.\d{1,3}\.\d{1,3}/)

src/common/constants/env.test.js renamed to tests/unit/common/constants/env.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as env from './env'
1+
import * as env from '../../../../src/common/constants/env'
22

33
test('should default environment variables to NPM values', () => {
44
expect(env.VERSION).toMatch(/\d{1,3}\.\d{1,3}\.\d{1,3}/)

src/common/constants/runtime.test.js renamed to tests/unit/common/constants/runtime.test.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test('should indicate agent is running in a browser scope', async () => {
2828
}
2929
}
3030

31-
const runtime = await import('./runtime')
31+
const runtime = await import('../../../../src/common/constants/runtime')
3232

3333
delete global.window
3434

@@ -43,7 +43,7 @@ test('should indicate agent is running in a worker scope using global self varia
4343
const mockedGlobalSelf = global.self = new global.WorkerGlobalScope()
4444
mockedGlobalSelf.navigator = new global.WorkerNavigator()
4545

46-
const runtime = await import('./runtime')
46+
const runtime = await import('../../../../src/common/constants/runtime')
4747

4848
delete global.WorkerGlobalScope
4949
delete global.WorkerNavigator
@@ -62,7 +62,7 @@ test('should indicate agent is running in a worker scope using global self varia
6262
Object.defineProperties(global.globalThis, Object.getOwnPropertyDescriptors(cachedGlobalThis))
6363
global.globalThis.navigator = new WorkerNavigator()
6464

65-
const runtime = await import('./runtime')
65+
const runtime = await import('../../../../src/common/constants/runtime')
6666

6767
delete global.WorkerGlobalScope
6868
delete global.WorkerNavigator
@@ -88,7 +88,7 @@ test('should store the initial page location', async () => {
8888
}
8989
}
9090

91-
const runtime = await import('./runtime')
91+
const runtime = await import('../../../../src/common/constants/runtime')
9292
mockedWindow.location.href = faker.internet.url()
9393

9494
delete global.window
@@ -108,7 +108,7 @@ test.each([
108108
global.navigator.userAgent = userAgent
109109
global.window = { navigator: global.navigator, document: true }
110110

111-
const runtime = await import('./runtime')
111+
const runtime = await import('../../../../src/common/constants/runtime')
112112

113113
expect(runtime.isiOS).toEqual(expected)
114114
delete global.window
@@ -131,7 +131,7 @@ test.each([
131131
global.navigator.userAgent = userAgent
132132
global.window = { navigator: global.navigator, document: true }
133133

134-
const runtime = await import('./runtime')
134+
const runtime = await import('../../../../src/common/constants/runtime')
135135

136136
delete global.SharedWorker
137137

@@ -150,7 +150,7 @@ test.each([
150150
global.navigator.userAgent = userAgent
151151
global.window = { navigator: global.navigator, document: true }
152152

153-
const runtime = await import('./runtime')
153+
const runtime = await import('../../../../src/common/constants/runtime')
154154

155155
expect(runtime.ffVersion).toEqual(expected)
156156
delete global.window
@@ -160,7 +160,7 @@ test('should set supportsSendBeacon to false', async () => {
160160
// Ensure we don't have a sendBeacon function
161161
delete global.navigator.sendBeacon
162162

163-
const runtime = await import('./runtime')
163+
const runtime = await import('../../../../src/common/constants/runtime')
164164

165165
expect(runtime.supportsSendBeacon).toEqual(false)
166166
})
@@ -169,7 +169,7 @@ test('should set supportsSendBeacon to true', async () => {
169169
global.navigator.sendBeacon = jest.fn()
170170
global.window = { navigator: global.navigator, document: true }
171171

172-
const runtime = await import('./runtime')
172+
const runtime = await import('../../../../src/common/constants/runtime')
173173

174174
expect(runtime.supportsSendBeacon).toEqual(true)
175175
delete global.window

src/common/deny-list/deny-list.test.js renamed to tests/unit/common/deny-list/deny-list.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
jest.enableAutomock()
2-
jest.unmock('./deny-list')
2+
jest.unmock('../../../../src/common/deny-list/deny-list')
33

44
let denyListModule
55

66
beforeEach(async () => {
7-
denyListModule = await import('./deny-list')
7+
denyListModule = await import('../../../../src/common/deny-list/deny-list')
88
})
99

1010
afterEach(() => {

src/common/dispatch/global-event.test.js renamed to tests/unit/common/dispatch/global-event.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { dispatchGlobalEvent } from './global-event'
1+
import { dispatchGlobalEvent } from '../../../../src/common/dispatch/global-event'
22

33
let globalScope, handler
44

55
describe('dispatchGlobalEvent', () => {
66
beforeEach(async () => {
7-
globalScope = (await import('../../common/constants/runtime')).globalScope
7+
globalScope = (await import('../../../../src/common/constants/runtime')).globalScope
88
})
99
afterEach(() => {
1010
jest.resetAllMocks()

src/common/dom/query-selector.test.js renamed to tests/unit/common/dom/query-selector.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isValidSelector } from './query-selector'
1+
import { isValidSelector } from '../../../../src/common/dom/query-selector'
22
describe('query selector tests', () => {
33
test('handles nullish values', () => {
44
expect(isValidSelector(null)).toEqual(false)

src/common/drain/drain.test.js renamed to tests/unit/common/drain/drain.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
let registerDrain, drain, ee
22
beforeEach(async () => {
33
jest.resetModules()
4-
;({ registerDrain, drain } = await import('./drain'))
5-
;({ ee } = await import('../event-emitter/contextual-ee'))
4+
;({ registerDrain, drain } = await import('../../../../src/common/drain/drain'))
5+
;({ ee } = await import('../../../../src/common/event-emitter/contextual-ee'))
66
})
77

88
test('can register a feat and drain it', () => {

src/common/event-emitter/handle.test.js renamed to tests/unit/common/event-emitter/handle.test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { faker } from '@faker-js/faker'
22

3-
jest.mock('./contextual-ee', () => ({
3+
jest.mock('../../../../src/common/event-emitter/contextual-ee', () => ({
44
__esModule: true,
55
ee: {
66
buffer: jest.fn(),
@@ -18,8 +18,8 @@ afterEach(() => {
1818
})
1919

2020
test('it should create and use a default event-emitter', async () => {
21-
const { ee } = await import('./contextual-ee')
22-
const { handle } = await import('./handle')
21+
const { ee } = await import('../../../../src/common/event-emitter/contextual-ee')
22+
const { handle } = await import('../../../../src/common/event-emitter/handle')
2323

2424
const handleEE = jest.mocked(ee.get).mock.results[0].value
2525
const eventType = faker.string.uuid()
@@ -34,8 +34,8 @@ test('it should create and use a default event-emitter', async () => {
3434
})
3535

3636
test('it should use the provided scoped event-emitter', async () => {
37-
const { ee } = await import('./contextual-ee')
38-
const { handle } = await import('./handle')
37+
const { ee } = await import('../../../../src/common/event-emitter/contextual-ee')
38+
const { handle } = await import('../../../../src/common/event-emitter/handle')
3939
const scopedEE = {
4040
buffer: jest.fn(),
4141
emit: jest.fn()

src/common/event-emitter/register-handler.test.js renamed to tests/unit/common/event-emitter/register-handler.test.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { faker } from '@faker-js/faker'
22

3-
jest.mock('./handle', () => ({
3+
jest.mock('../../../../src/common/event-emitter/handle', () => ({
44
__esModule: true,
55
handleEE: {}
66
}))
@@ -11,8 +11,8 @@ afterEach(() => {
1111
})
1212

1313
test('should default group to "feature"', async () => {
14-
const { handleEE } = await import('./handle')
15-
const { registerHandler } = await import('./register-handler')
14+
const { handleEE } = await import('../../../../src/common/event-emitter/handle')
15+
const { registerHandler } = await import('../../../../src/common/event-emitter/register-handler')
1616

1717
const eventType = faker.string.uuid()
1818
const eventHandler = jest.fn()
@@ -27,8 +27,8 @@ test('should default group to "feature"', async () => {
2727
})
2828

2929
test('should use the provided group', async () => {
30-
const { handleEE } = await import('./handle')
31-
const { registerHandler } = await import('./register-handler')
30+
const { handleEE } = await import('../../../../src/common/event-emitter/handle')
31+
const { registerHandler } = await import('../../../../src/common/event-emitter/register-handler')
3232

3333
const eventType = faker.string.uuid()
3434
const eventGroup = faker.string.uuid()
@@ -44,7 +44,7 @@ test('should use the provided group', async () => {
4444
})
4545

4646
test('should use the provided event-emitter', async () => {
47-
const { registerHandler } = await import('./register-handler')
47+
const { registerHandler } = await import('../../../../src/common/event-emitter/register-handler')
4848

4949
const scopedEE = {}
5050
const eventType = faker.string.uuid()

src/common/harvest/harvest-scheduler.test.js renamed to tests/unit/common/harvest/harvest-scheduler.test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { faker } from '@faker-js/faker'
22

3-
import * as submitData from '../util/submit-data'
4-
import { subscribeToEOL } from '../unload/eol'
5-
import { Harvest } from './harvest'
3+
import * as submitData from '../../../../src/common/util/submit-data'
4+
import { subscribeToEOL } from '../../../../src/common/unload/eol'
5+
import { Harvest } from '../../../../src/common/harvest/harvest'
66

7-
import { HarvestScheduler } from './harvest-scheduler'
7+
import { HarvestScheduler } from '../../../../src/common/harvest/harvest-scheduler'
88

99
jest.enableAutomock()
10-
jest.unmock('./harvest-scheduler')
10+
jest.unmock('../../../../src/common/harvest/harvest-scheduler')
1111
jest.useFakeTimers()
1212

1313
let harvestSchedulerInstance

src/common/harvest/harvest.test.js renamed to tests/unit/common/harvest/harvest.test.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { faker } from '@faker-js/faker'
22

3-
import * as encodeModule from '../url/encode'
4-
import * as submitDataModule from '../util/submit-data'
5-
import * as configModule from '../config/config'
6-
import { warn } from '../util/console'
7-
import { applyFnToProps } from '../util/traverse'
3+
import * as encodeModule from '../../../../src/common/url/encode'
4+
import * as submitDataModule from '../../../../src/common/util/submit-data'
5+
import * as configModule from '../../../../src/common/config/config'
6+
import { warn } from '../../../../src/common/util/console'
7+
import { applyFnToProps } from '../../../../src/common/util/traverse'
88

9-
import { Harvest } from './harvest'
9+
import { Harvest } from '../../../../src/common/harvest/harvest'
1010

1111
jest.enableAutomock()
12-
jest.unmock('./harvest')
12+
jest.unmock('../../../../src/common/harvest/harvest')
1313
let harvestInstance
1414

1515
beforeEach(() => {

src/common/ids/id.test.js renamed to tests/unit/common/ids/id.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
let idFn
22

33
beforeEach(async () => {
4-
idFn = (await import('./id')).id
4+
idFn = (await import('../../../../src/common/ids/id')).id
55
})
66

77
afterEach(() => {

0 commit comments

Comments
 (0)