@wordpress/e2e-test-utils
Version:
End-To-End (E2E) test utils for WordPress.
36 lines (35 loc) • 854 B
JavaScript
import { rest } from "./rest-api";
const PATH_MAPPING = {
wp_template: "/wp/v2/templates",
wp_template_part: "/wp/v2/template-parts"
};
async function deleteAllTemplates(type) {
const path = PATH_MAPPING[type];
if (!path) {
throw new Error(`Unsupported template type: ${type}.`);
}
const templates = await rest({ path });
if (!templates?.length) {
return;
}
for (const template of templates) {
if (!template?.wp_id) {
continue;
}
try {
await rest({
path: `${path}/${template.id}?force=true`,
method: "DELETE"
});
} catch (responseError) {
console.warn(
`deleteAllTemplates failed to delete template (id: ${template.wp_id}) with the following error`,
responseError
);
}
}
}
export {
deleteAllTemplates
};
//# sourceMappingURL=templates.js.map