mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-03-19 15:01:06 +08:00
fix(build): Move page not an object error to addDefaultPages.
This commit is contained in:
parent
20f02bdef9
commit
b3c980d2bf
@ -29,7 +29,12 @@ async function addDefaultPages({ components }) {
|
||||
throw new Error('lowdefy.pages is not an array.');
|
||||
}
|
||||
|
||||
const pageIds = components.pages.map((page) => page.id);
|
||||
const pageIds = components.pages.map((page, index) => {
|
||||
if (!type.isObject(page)) {
|
||||
throw new Error(`pages[${index}] is not an object. Received ${JSON.stringify(page)}`);
|
||||
}
|
||||
return page.id;
|
||||
});
|
||||
// deep copy to avoid mutating defaultConfig
|
||||
const filteredDefaultPages = defaultPages.filter(
|
||||
(defaultPage) => !pageIds.includes(defaultPage.id)
|
||||
|
@ -204,6 +204,15 @@ test('addDefaultPages, pages not an array', async () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('addDefaultPages, with a page not an object', async () => {
|
||||
const components = {
|
||||
pages: [null],
|
||||
};
|
||||
await expect(addDefaultPages({ components, context })).rejects.toThrow(
|
||||
'pages[0] is not an object. Received null'
|
||||
);
|
||||
});
|
||||
|
||||
test('addDefaultPages, pages are copied', async () => {
|
||||
const components1 = {};
|
||||
const res1 = await addDefaultPages({ components: components1, context });
|
||||
|
@ -14,12 +14,7 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { type } from '@lowdefy/helpers';
|
||||
|
||||
async function writePage({ page, context }) {
|
||||
if (!type.isObject(page)) {
|
||||
throw new Error(`Page is not an object. Received ${JSON.stringify(page)}`);
|
||||
}
|
||||
await context.writeBuildArtifact(
|
||||
`pages/${page.pageId}/${page.pageId}.json`,
|
||||
JSON.stringify(page, null, 2)
|
||||
@ -27,10 +22,6 @@ async function writePage({ page, context }) {
|
||||
}
|
||||
|
||||
async function writePages({ components, context }) {
|
||||
if (type.isNone(components.pages)) return;
|
||||
if (!type.isArray(components.pages)) {
|
||||
throw new Error(`Pages is not an array.`);
|
||||
}
|
||||
const writePromises = components.pages.map((page) => writePage({ page, context }));
|
||||
return Promise.all(writePromises);
|
||||
}
|
||||
|
@ -99,25 +99,3 @@ test('writePages no pages', async () => {
|
||||
await writePages({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([]);
|
||||
});
|
||||
|
||||
test('writePages pages undefined', async () => {
|
||||
const components = {};
|
||||
await writePages({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([]);
|
||||
});
|
||||
|
||||
test('writePages pages not an array', async () => {
|
||||
const components = {
|
||||
pages: 'pages',
|
||||
};
|
||||
await expect(writePages({ components, context })).rejects.toThrow('Pages is not an array.');
|
||||
});
|
||||
|
||||
test('writePages page is not an object', async () => {
|
||||
const components = {
|
||||
pages: ['page'],
|
||||
};
|
||||
await expect(writePages({ components, context })).rejects.toThrow(
|
||||
'Page is not an object. Received "page"'
|
||||
);
|
||||
});
|
||||
|
@ -14,8 +14,6 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { type } from '@lowdefy/helpers';
|
||||
|
||||
async function writeRequestsOnPage({ page, context }) {
|
||||
return Promise.all(
|
||||
page.requests.map(async (request) => {
|
||||
@ -32,7 +30,6 @@ async function writeRequestsOnPage({ page, context }) {
|
||||
}
|
||||
|
||||
async function writeRequests({ components, context }) {
|
||||
if (type.isNone(components.pages)) return;
|
||||
const writePromises = components.pages.map((page) => writeRequestsOnPage({ page, context }));
|
||||
return Promise.all(writePromises);
|
||||
}
|
||||
|
@ -224,12 +224,6 @@ test('writeRequests empty pages array', async () => {
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([]);
|
||||
});
|
||||
|
||||
test('writeRequests no pages array', async () => {
|
||||
const components = {};
|
||||
await writeRequests({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([]);
|
||||
});
|
||||
|
||||
test('writeRequests deletes request properties', async () => {
|
||||
const components = {
|
||||
pages: [
|
||||
|
Loading…
x
Reference in New Issue
Block a user