Skip to content

Commit

Permalink
Simplify test-utils (#5459)
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie committed Apr 14, 2021
1 parent c7aecec commit 5106e4b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 32 deletions.
5 changes: 5 additions & 0 deletions .changeset/shy-turkeys-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/test-utils-legacy': patch
---

Simplified internal implementation now that Prisma is the only database adapter supported.
45 changes: 13 additions & 32 deletions packages/test-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,6 @@ const hashPrismaSchema = memoizeOne(prismaSchema =>
crypto.createHash('md5').update(prismaSchema).digest('hex')
);

const argGenerator = {
postgresql: () => ({
url: process.env.DATABASE_URL!,
provider: 'postgresql' as const,
getDbSchemaName: () => null as any,
// Turn this on if you need verbose debug info
enableLogging: false,
}),
sqlite: () => ({
url: process.env.DATABASE_URL!,
provider: 'sqlite' as const,
// Turn this on if you need verbose debug info
enableLogging: false,
}),
};

// Users should use testConfig({ ... }) in place of config({ ... }) when setting up
// their system for test. We explicitly don't allow them to control the 'db' or 'ui'
// properties as we're going to set that up as part of setupFromConfig.
Expand All @@ -55,10 +39,13 @@ async function setupFromConfig({
provider: ProviderName;
config: TestKeystoneConfig;
}) {
const adapterArgs = await argGenerator[provider]();
const config = initConfig({
..._config,
db: adapterArgs,
db: {
url: process.env.DATABASE_URL!,
provider,
enableLogging: false, // Turn this on if you need verbose debug info
},
ui: { isDisabled: true },
});

Expand All @@ -80,7 +67,7 @@ async function setupFromConfig({
config.db.url,
artifacts.prisma,
path.join(cwd, 'schema.prisma'),
true
true // shouldDropDatabase
);
return requirePrismaClient(cwd);
})();
Expand Down Expand Up @@ -175,20 +162,14 @@ function _after(tearDownFunction: () => Promise<void> | void) {
}

function multiAdapterRunners(only = process.env.TEST_ADAPTER) {
return [
{
runner: _keystoneRunner('postgresql', () => {}),
provider: 'postgresql' as const,
before: _before('postgresql'),
after: _after(() => {}),
},
{
runner: _keystoneRunner('sqlite', () => {}),
provider: 'sqlite' as const,
before: _before('sqlite'),
return (['postgresql', 'sqlite'] as const)
.filter(provider => typeof only === 'undefined' || provider === only)
.map(provider => ({
provider,
runner: _keystoneRunner(provider, () => {}),
before: _before(provider),
after: _after(() => {}),
},
].filter(a => typeof only === 'undefined' || a.provider === only);
}));
}

export { setupFromConfig, multiAdapterRunners, networkedGraphqlRequest };

1 comment on commit 5106e4b

@vercel
Copy link

@vercel vercel bot commented on 5106e4b Apr 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.