Skip to content

Commit

Permalink
chore(test): make global setup safe for running in shards
Browse files Browse the repository at this point in the history
  • Loading branch information
binoy14 committed Oct 24, 2023
1 parent 596fd8f commit 3281d2b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/@sanity/cli/test/shared/globalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,18 @@ async function prepareDatasets() {
token: cliUserToken,
})

const existingDatasets = await client.datasets.list()
const datasetSet = new Set(existingDatasets.map((ds) => ds.name))

for (const version of studioVersions) {
const args = getTestRunArgs(version)
const datasets = [args.documentsDataset, args.graphqlDataset, args.aclDataset]

await Promise.all(
datasets.map((ds) => {
if (datasetSet.has(ds)) {
return Promise.resolve()
}
// eslint-disable-next-line no-console
console.log(`Creating dataset ${ds}...`)
return client.datasets.create(ds, {aclMode: 'public'}).catch((err) => {
Expand Down
10 changes: 9 additions & 1 deletion packages/@sanity/cli/test/shared/globalTeardown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,15 @@ async function deleteDatasets(args: ReturnType<typeof getTestRunArgs>) {
args.aclDataset,
]

const existingDatasets = await testClient.datasets.list()
const datasetSet = new Set(existingDatasets.map((ds) => ds.name))

await Promise.all(
datasets.map((ds) => testClient.datasets.delete(ds).catch(getErrorWarner('dataset', ds))),
datasets.map((ds) => {
if (!datasetSet.has(ds)) {
return Promise.resolve()
}
return testClient.datasets.delete(ds).catch(getErrorWarner('dataset', ds))
}),
)
}

0 comments on commit 3281d2b

Please sign in to comment.