Skip to content

Commit bfbd4a1

Browse files
chore: improve tests for reliability [] (#2847)
* chore: remove concurrent async calls to better help rate limiting * chore: add waitForEnvironmentToBeReady to tests where it wasn't already there * fix: fix lint --------- Co-authored-by: Ely Lucas <ely.lucas@contentful.com>
1 parent 3a1e5b1 commit bfbd4a1

10 files changed

+128
-154
lines changed

test/integration/comment-integration.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
createTestSpace,
66
initPlainClient,
77
timeoutToCalmRateLimiting,
8+
waitForEnvironmentToBeReady,
89
} from '../helpers'
910
import type { ContentType, Entry, Environment, PlainClientAPI, Space } from '../../lib/export-types'
1011

@@ -19,11 +20,9 @@ describe('Comment Api', () => {
1920

2021
beforeAll(async () => {
2122
plainClient = initPlainClient()
22-
space = (await createTestSpace(defaultClient, 'Comment')) as Space
23-
environment = (await createTestEnvironment(
24-
space,
25-
'Comment Testing Environment',
26-
)) as unknown as Environment
23+
space = await createTestSpace(defaultClient, 'Comment')
24+
environment = await createTestEnvironment(space, 'Comment Testing Environment')
25+
await waitForEnvironmentToBeReady(space, environment)
2726
contentType = await environment.createContentType({
2827
name: 'Content Type',
2928
fields: [

test/integration/content-type-integration.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
generateRandomId,
77
getDefaultSpace,
88
timeoutToCalmRateLimiting,
9+
waitForEnvironmentToBeReady,
910
} from '../helpers'
1011
import type { Environment, ContentType, Space } from '../../lib/export-types'
1112

@@ -23,6 +24,7 @@ describe('ContentType Api', () => {
2324

2425
writeSpace = await createTestSpace(defaultClient, 'ContentType')
2526
writeEnvironment = await createTestEnvironment(writeSpace, 'Testing Environment')
27+
await waitForEnvironmentToBeReady(writeSpace, writeEnvironment)
2628
})
2729

2830
afterAll(async () => {

test/integration/locale-integration.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
createTestEnvironment,
55
createTestSpace,
66
timeoutToCalmRateLimiting,
7+
waitForEnvironmentToBeReady,
78
} from '../helpers'
89
import type { Space, Environment } from '../../lib/export-types'
910

@@ -14,6 +15,7 @@ describe('Locale API', () => {
1415
beforeAll(async () => {
1516
space = await createTestSpace(defaultClient, 'Locale')
1617
environment = await createTestEnvironment(space, 'Test')
18+
await waitForEnvironmentToBeReady(space, environment)
1719
})
1820

1921
afterAll(async () => {

test/integration/plain-client.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
generateRandomId,
77
getDefaultSpace,
88
timeoutToCalmRateLimiting,
9+
waitForEnvironmentToBeReady,
910
} from '../helpers'
1011
import type { Environment, ContentType, Space } from '../../lib/export-types'
1112

@@ -26,6 +27,7 @@ describe('ContentType Api', () => {
2627
writeSpace,
2728
'Testing Environment',
2829
)) as unknown as Environment
30+
await waitForEnvironmentToBeReady(writeSpace, writeEnvironment)
2931
})
3032

3133
afterAll(async () => {

test/integration/release-action-integration.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,8 @@ describe('ReleaseAction Api', () => {
5656
},
5757
}
5858

59-
;[testRelease, testRelease2] = await Promise.all([
60-
testEnvironment.createRelease(releasePayload),
61-
testEnvironment.createRelease(releasePayload),
62-
])
59+
testRelease = await testEnvironment.createRelease(releasePayload)
60+
testRelease2 = await testEnvironment.createRelease(releasePayload)
6361

6462
testReleaseAction = await testRelease.validate()
6563
testReleaseAction2 = await testRelease2.validate()

test/integration/release-integration.test.ts

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,20 @@ describe('Release Api', () => {
8787
})
8888

8989
it('Get Releases', async () => {
90-
const [release1, release2] = await Promise.all([
91-
testEnvironment.createRelease({
92-
title: 'First release',
93-
entities: {
94-
sys: { type: 'Array' },
95-
items: [makeLink('Entry', TestDefaults.entry.testEntryReleasesId)],
96-
},
97-
}),
98-
testEnvironment.createRelease({
99-
title: 'Second release',
100-
entities: {
101-
sys: { type: 'Array' },
102-
items: [makeLink('Entry', TestDefaults.entry.testEntryReleasesId)],
103-
},
104-
}),
105-
])
90+
const release1 = await testEnvironment.createRelease({
91+
title: 'First release',
92+
entities: {
93+
sys: { type: 'Array' },
94+
items: [makeLink('Entry', TestDefaults.entry.testEntryReleasesId)],
95+
},
96+
})
97+
const release2 = await testEnvironment.createRelease({
98+
title: 'Second release',
99+
entities: {
100+
sys: { type: 'Array' },
101+
items: [makeLink('Entry', TestDefaults.entry.testEntryReleasesId)],
102+
},
103+
})
106104

107105
const queryLimit = 1
108106
const queryResult = await testEnvironment.getReleases({
@@ -116,29 +114,25 @@ describe('Release Api', () => {
116114
expect(typeof queryResult.pages?.next).toBe('string')
117115

118116
// cleanup
119-
await Promise.all([
120-
testEnvironment.deleteRelease(release1.sys.id),
121-
testEnvironment.deleteRelease(release2.sys.id),
122-
])
117+
await testEnvironment.deleteRelease(release1.sys.id)
118+
await testEnvironment.deleteRelease(release2.sys.id)
123119
})
124120

125121
it('Get Releases with query filters', async () => {
126-
const [release1, release2] = await Promise.all([
127-
testEnvironment.createRelease({
128-
title: 'First release',
129-
entities: {
130-
sys: { type: 'Array' },
131-
items: [makeLink('Entry', TestDefaults.entry.testEntryReleasesId)],
132-
},
133-
}),
134-
testEnvironment.createRelease({
135-
title: 'Second release',
136-
entities: {
137-
sys: { type: 'Array' },
138-
items: [],
139-
},
140-
}),
141-
])
122+
const release1 = await testEnvironment.createRelease({
123+
title: 'First release',
124+
entities: {
125+
sys: { type: 'Array' },
126+
items: [makeLink('Entry', TestDefaults.entry.testEntryReleasesId)],
127+
},
128+
})
129+
const release2 = await testEnvironment.createRelease({
130+
title: 'Second release',
131+
entities: {
132+
sys: { type: 'Array' },
133+
items: [],
134+
},
135+
})
142136

143137
const queryResult = await testEnvironment.getReleases({
144138
'entities[exists]': true,
@@ -151,10 +145,8 @@ describe('Release Api', () => {
151145
expect(queryResult.items[0].title).toBe('First release')
152146

153147
// cleanup
154-
await Promise.all([
155-
testEnvironment.deleteRelease(release1.sys.id),
156-
testEnvironment.deleteRelease(release2.sys.id),
157-
])
148+
await testEnvironment.deleteRelease(release1.sys.id)
149+
await testEnvironment.deleteRelease(release2.sys.id)
158150
})
159151
})
160152

test/integration/scheduled-action-integration.test.ts

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ const cleanup = async (testSpace: Space, environmentId: string) => {
1919
'sys.status': 'scheduled',
2020
})
2121

22-
await Promise.all(scheduledActions.items.map((action) => action.delete()))
22+
for (const action of scheduledActions.items) {
23+
await action.delete()
24+
}
2325
}
2426

2527
describe('Scheduled Actions API', () => {
@@ -78,30 +80,22 @@ describe('Scheduled Actions API', () => {
7880
})
7981

8082
it.skip('Query Scheduled Actions', async () => {
81-
const [action1, action2] = await Promise.all([
82-
testSpace.createScheduledAction({
83-
entity: makeLink('Entry', TestDefaults.entry.testEntryId),
84-
action: 'publish',
85-
environment: makeLink('Environment', environment.sys.id),
86-
scheduledFor: {
87-
datetime,
88-
},
89-
}),
90-
testSpace.createScheduledAction({
91-
entity: makeLink('Asset', asset.sys.id),
92-
action: 'unpublish',
93-
environment: {
94-
sys: {
95-
type: 'Link',
96-
linkType: 'Environment',
97-
id: environment.sys.id,
98-
},
99-
},
100-
scheduledFor: {
101-
datetime,
102-
},
103-
}),
104-
])
83+
const action1 = await testSpace.createScheduledAction({
84+
entity: makeLink('Entry', TestDefaults.entry.testEntryId),
85+
action: 'publish',
86+
environment: makeLink('Environment', environment.sys.id),
87+
scheduledFor: {
88+
datetime,
89+
},
90+
})
91+
const action2 = await testSpace.createScheduledAction({
92+
entity: makeLink('Entry', TestDefaults.entry.testEntryId),
93+
action: 'publish',
94+
environment: makeLink('Environment', environment.sys.id),
95+
scheduledFor: {
96+
datetime,
97+
},
98+
})
10599

106100
try {
107101
const queryLimit = 1

test/integration/tag-integration.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ describe('Tags API', () => {
2929

3030
afterEach(async () => {
3131
const tags = await environment.getTags({ limit: 1000 })
32-
const deleting = tags.items.map((tag) => tag.delete())
33-
await Promise.allSettled(deleting)
32+
for (const tag of tags.items) {
33+
await tag.delete().catch(() => {})
34+
}
3435
})
3536

3637
afterAll(async () => {

0 commit comments

Comments
 (0)