Skip to content

Commit

Permalink
Merge pull request #7370 from uktrade/fix/manage-randomness-in-tests
Browse files Browse the repository at this point in the history
Fix/manage randomness in tests
  • Loading branch information
peterhudec authored Dec 5, 2024
2 parents 589e5fc + 7739532 commit c83fe65
Show file tree
Hide file tree
Showing 63 changed files with 251 additions and 77 deletions.
12 changes: 11 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,17 @@
],
"no-duplicate-imports": "error",
"import/no-named-as-default": "off",
"import/no-named-as-default-member": "off"
"import/no-named-as-default-member": "off",
"no-restricted-imports": [
"error",
{
"name": "@faker-js/faker",
"message": "Use the pseudo-random `faker` from `test/sandbox/utils/random.js`"
},
{
"name": "json-schema-faker",
"message": "Use the pseudo-random `jsf` from `test/sandbox/utils/random.js`"
}]
},
"overrides": [
{
Expand Down
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
"proxyquire": "^2.1.3",
"reqres": "^3.0.1",
"rewire": "^6.0.0",
"seedrandom": "^3.0.5",
"sharp": "^0.33.5",
"sinon": "^18.0.0",
"sinon-chai": "^3.7.0",
Expand Down
2 changes: 1 addition & 1 deletion src/client/components/CompanyLists/tasks/dummy/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../../../../test/sandbox/utils/random'

const randomLists = ({ length, max = 10 }) =>
Array(length || faker.number.int(max))
Expand Down
2 changes: 1 addition & 1 deletion src/client/components/ReferralList/tasks/dummy/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../../../../test/sandbox/utils/random'

const randomAdviser = () => ({
...faker.helpers.createCard(),
Expand Down
3 changes: 2 additions & 1 deletion src/client/components/Task/__stories__/tasks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import _ from 'lodash'
import { faker } from '@faker-js/faker'

import { faker } from '../../../../../test/sandbox/utils/random'

const OPTIONS = Array(1000)
.fill()
Expand Down
1 change: 1 addition & 0 deletions test/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
},
"rules": {
"no-unused-expressions": 0

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import { faker } from '@faker-js/faker'

import { faker } from '../../../../../../sandbox/utils/random.js'

import ObjectiveForm from '../../../../../../../src/client/modules/Companies/AccountManagement/Objective/ObjectiveForm'
import { companyFaker } from '../../../../../../functional/cypress/fakers/companies'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import { faker } from '@faker-js/faker'

import { faker } from '../../../../../../sandbox/utils/random.js'

import { largeInvestorProfileFaker } from '../../../../../../functional/cypress/fakers/large-investor-profile'
import { ProfileDetailsForm } from '../../../../../../../src/client/modules/Companies/CompanyInvestments/LargeCapitalProfile/EditProfileDetailsForm'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '../../../../functional/cypress/support/assertions'
import CustomerFeedback from '../../../../../src/client/modules/ExportWins/CustomerFeedback'
import urls from '../../../../../src/lib/urls'
import { resolve } from '../../../../utils'
import { resolve } from '../../support/utils'

const toYesNo = (x) => (x ? 'Yes' : 'No')

Expand Down
2 changes: 1 addition & 1 deletion test/component/cypress/specs/Resource/Paginated.cy.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react'

import PaginatedResource from '../../../../../src/client/components/Resource/Paginated'
import TabNav from '../../../../../src/client/components/TabNav'
import { resolve } from '../../../../utils'
import { resolve } from '../../support/utils'

const PAGE_SIZE = 10
const COUNT = 35
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import { capitalize } from 'lodash'
import { faker } from '@faker-js/faker'

import { faker } from '../../../../../sandbox/utils/random.js'

import {
assertFieldDate,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/functional/cypress/fakers/addresses.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../sandbox/utils/random'

const addressFaker = (overrides = {}) => ({
line_1: faker.location.streetAddress(),
Expand Down
2 changes: 1 addition & 1 deletion test/functional/cypress/fakers/administrative-areas.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../sandbox/utils/random'

import { listFaker } from './utils'

Expand Down
3 changes: 1 addition & 2 deletions test/functional/cypress/fakers/advisers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import jsf from 'json-schema-faker'

import { jsf } from '../../../sandbox/utils/random'
import apiSchema from '../../../api-schema.json'
import { listFaker } from './utils'
import { ditTeamFaker } from './dit-team'
Expand Down
3 changes: 1 addition & 2 deletions test/functional/cypress/fakers/companies.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { faker } from '@faker-js/faker'
import jsf from 'json-schema-faker'
import { jsf, faker } from '../../../sandbox/utils/random'

import apiSchema from '../../../api-schema.json'

Expand Down
3 changes: 1 addition & 2 deletions test/functional/cypress/fakers/company-activity.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { faker } from '@faker-js/faker'
import jsf from 'json-schema-faker'
import { faker, jsf } from '../../../sandbox/utils/random'

import apiSchema from '../../../api-schema.json'
import { relativeDateFaker } from './dates'
Expand Down
2 changes: 1 addition & 1 deletion test/functional/cypress/fakers/company-export-win.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../sandbox/utils/random'

import { listFaker } from './utils'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../sandbox/utils/random'

import { listFaker } from './utils'

Expand Down
3 changes: 1 addition & 2 deletions test/functional/cypress/fakers/contacts.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { faker } from '@faker-js/faker'
import jsf from 'json-schema-faker'
import { faker, jsf } from '../../../sandbox/utils/random'

import apiSchema from '../../../api-schema.json'
import { listFaker } from './utils'
Expand Down
2 changes: 1 addition & 1 deletion test/functional/cypress/fakers/countries.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../sandbox/utils/random'

import { listFaker } from './utils'

Expand Down
2 changes: 1 addition & 1 deletion test/functional/cypress/fakers/dates.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../sandbox/utils/random'

import { addDays } from '../../../../src/client/utils/date'

Expand Down
2 changes: 1 addition & 1 deletion test/functional/cypress/fakers/dit-team.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../sandbox/utils/random'

import { listFaker } from './utils'

Expand Down
2 changes: 1 addition & 1 deletion test/functional/cypress/fakers/dnb-hierarchy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../sandbox/utils/random'

import { listFaker } from './utils'
import { addressFaker } from './addresses'
Expand Down
3 changes: 1 addition & 2 deletions test/functional/cypress/fakers/event-types.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { faker } from '@faker-js/faker'

import { faker } from '../../../sandbox/utils/random'
import { listFaker } from './utils'

/**
Expand Down
4 changes: 1 addition & 3 deletions test/functional/cypress/fakers/events.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { faker } from '@faker-js/faker'
import jsf from 'json-schema-faker'

import { faker, jsf } from '../../../sandbox/utils/random'
import apiSchema from '../../../api-schema.json'

import { listFaker } from './utils'
Expand Down
2 changes: 1 addition & 1 deletion test/functional/cypress/fakers/export-wins.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../sandbox/utils/random'

import { contactFaker } from './contacts'
import { sectorFaker } from './sectors'
Expand Down
2 changes: 1 addition & 1 deletion test/functional/cypress/fakers/export.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../sandbox/utils/random'

import { listFaker } from './utils'
import { sectorFaker } from './sectors'
Expand Down
5 changes: 2 additions & 3 deletions test/functional/cypress/fakers/eyb-leads.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { faker } from '@faker-js/faker'
import { JSONSchemaFaker } from 'json-schema-faker'
import { faker, jsf } from '../../../sandbox/utils/random'

import apiSchema from '../../../api-schema.json'

Expand Down Expand Up @@ -63,7 +62,7 @@ const LANDING_TIMEFRAME_CHOICES = [
* merges in overrides.
*/
const eybLeadFaker = (overrides = {}) => ({
...JSONSchemaFaker.generate(apiSchema.components.schemas.RetrieveEYBLead),
...jsf.generate(apiSchema.components.schemas.RetrieveEYBLead),
archived: false,
archived_on: null,
archived_reason: null,
Expand Down
2 changes: 1 addition & 1 deletion test/functional/cypress/fakers/hq-team.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../sandbox/utils/random'

import { listFaker } from './utils'

Expand Down
3 changes: 1 addition & 2 deletions test/functional/cypress/fakers/interactions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { faker } from '@faker-js/faker'
import jsf from 'json-schema-faker'
import { faker, jsf } from '../../../sandbox/utils/random'

import apiSchema from '../../../api-schema.json'
import { listFaker } from './utils'
Expand Down
3 changes: 2 additions & 1 deletion test/functional/cypress/fakers/investment-project-summary.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { faker } from '@faker-js/faker'
import { snakeCase } from 'lodash'

import { faker } from '../../../sandbox/utils/random'

import { INVESTMENT_PROJECT_STAGES_LIST } from './constants'

/**
Expand Down
3 changes: 1 addition & 2 deletions test/functional/cypress/fakers/investment-projects.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { faker } from '@faker-js/faker'
import jsf from 'json-schema-faker'
import { faker, jsf } from '../../../sandbox/utils/random'

import apiSchema from '../../../api-schema.json'

Expand Down
2 changes: 1 addition & 1 deletion test/functional/cypress/fakers/investor-type.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../sandbox/utils/random'

const investorTypes = [
'Angel syndicate',
Expand Down
2 changes: 1 addition & 1 deletion test/functional/cypress/fakers/large-investor-profile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../sandbox/utils/random'

import { listFaker } from './utils'
import { investorTypeFaker } from './investor-type'
Expand Down
2 changes: 1 addition & 1 deletion test/functional/cypress/fakers/numbers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../sandbox/utils/random'

/**
* Pad a number with leading zeroes to ensure it has the given length
Expand Down
2 changes: 1 addition & 1 deletion test/functional/cypress/fakers/objective.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../sandbox/utils/random'

import { listFaker } from './utils'
import { formatWithoutParsing } from '../../../../src/client/utils/date'
Expand Down
3 changes: 1 addition & 2 deletions test/functional/cypress/fakers/orders.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { faker } from '@faker-js/faker'
import jsf from 'json-schema-faker'
import { jsf, faker } from '../../../sandbox/utils/random'

import apiSchema from '../../../api-schema.json'
import { listFaker } from './utils'
Expand Down
2 changes: 1 addition & 1 deletion test/functional/cypress/fakers/policy-area.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../sandbox/utils/random'

import { listFaker } from './utils'

Expand Down
2 changes: 1 addition & 1 deletion test/functional/cypress/fakers/policy-issue-type.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../sandbox/utils/random'

import { listFaker } from './utils'

Expand Down
4 changes: 2 additions & 2 deletions test/functional/cypress/fakers/propositions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { faker } from '@faker-js/faker'
import jsf from 'json-schema-faker'
import { startCase } from 'lodash'

import { faker, jsf } from '../../../sandbox/utils/random'

import apiSchema from '../../../api-schema.json'

import { relativeDateFaker } from './dates'
Expand Down
2 changes: 1 addition & 1 deletion test/functional/cypress/fakers/regions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../sandbox/utils/random'

import { listFaker } from './utils'

Expand Down
2 changes: 1 addition & 1 deletion test/functional/cypress/fakers/reminders.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../sandbox/utils/random'

import { relativeDateFaker } from './dates'
import { investmentProjectCodeFaker } from './investment-projects'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../sandbox/utils/random'

const names = [
'Cleared',
Expand Down
2 changes: 1 addition & 1 deletion test/functional/cypress/fakers/sectors.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../sandbox/utils/random'

import { listFaker } from './utils'

Expand Down
2 changes: 1 addition & 1 deletion test/functional/cypress/fakers/services.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../sandbox/utils/random'

import { listFaker } from './utils'

Expand Down
3 changes: 2 additions & 1 deletion test/functional/cypress/fakers/task.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { faker } from '@faker-js/faker'
import { pick } from 'lodash'

import { faker } from '../../../sandbox/utils/random'

import { listFaker } from './utils'
import { companyFaker } from './companies'
import { interactionFaker } from './interactions'
Expand Down
2 changes: 1 addition & 1 deletion test/functional/cypress/fakers/team-type.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../sandbox/utils/random'

import { listFaker } from './utils'

Expand Down
2 changes: 1 addition & 1 deletion test/functional/cypress/fakers/team.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../sandbox/utils/random'

import { listFaker } from './utils'

Expand Down
2 changes: 1 addition & 1 deletion test/functional/cypress/fakers/users.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../sandbox/utils/random'

const userFaker = (overrides) => {
const first_name = faker.person.firstName()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { faker } from '@faker-js/faker'
import { format } from 'date-fns'

import { faker } from '../../../../sandbox/utils/random'

import { companyFaker } from '../../fakers/companies'
import { userFaker } from '../../fakers/users'
import objectiveListFaker, { objectiveFaker } from '../../fakers/objective'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import { faker } from '../../../../sandbox/utils/random'

import { formatWithoutParsing } from '../../../../../src/client/utils/date'
import { investmentProjectFaker } from '../../fakers/investment-projects'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { faker } from '@faker-js/faker'

import { faker } from '../../../../sandbox/utils/random'
import { contactFaker, contactsListFaker } from '../../fakers/contacts'
import { exportFaker } from '../../fakers/export'
import { companyFaker } from '../../fakers/companies'
Expand Down
Loading

0 comments on commit c83fe65

Please sign in to comment.