-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for unsupported field types (#4061)
- Loading branch information
Showing
3 changed files
with
70 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@keystonejs/keystone': patch | ||
--- | ||
|
||
Updated error handling to throw Error objects rather than Strings for invalid field configurations. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const globby = require('globby'); | ||
const path = require('path'); | ||
const { multiAdapterRunners, setupServer } = require('@keystonejs/test-utils'); | ||
|
||
const testModules = globby.sync(`packages/**/src/**/test-fixtures.js`, { | ||
absolute: true, | ||
}); | ||
testModules.push(path.resolve('packages/fields/tests/test-fixtures.js')); | ||
|
||
multiAdapterRunners().map(({ adapterName, after }) => { | ||
const unsupportedModules = testModules | ||
.map(require) | ||
.filter(({ unSupportedAdapterList = [] }) => unSupportedAdapterList.includes(adapterName)); | ||
if (unsupportedModules.length > 0) { | ||
describe(`${adapterName} adapter`, () => { | ||
unsupportedModules.forEach(mod => { | ||
(mod.testMatrix || ['default']).forEach(matrixValue => { | ||
const listKey = 'Test'; | ||
|
||
describe(`${mod.name} - Unsupported field type`, () => { | ||
beforeAll(() => { | ||
if (mod.beforeAll) { | ||
mod.beforeAll(); | ||
} | ||
}); | ||
afterAll(async () => { | ||
if (mod.afterAll) { | ||
await mod.afterAll(); | ||
} | ||
// We expect setup to fail, so disconnect can be a noop | ||
await after({ disconnect: () => {} }); | ||
}); | ||
|
||
test('Delete', async () => { | ||
const createLists = keystone => { | ||
// Create a list with all the fields required for testing | ||
keystone.createList(listKey, { fields: mod.getTestFields(matrixValue) }); | ||
}; | ||
await expect(async () => setupServer({ adapterName, createLists })).rejects.toThrow( | ||
Error | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} else { | ||
// Appease jest, which doesn't like it when you have an empty test file. | ||
test('noop', () => {}); | ||
} | ||
}); |