woocommerce/tests/e2e/config/jest.setup.js

45 lines
1.2 KiB
JavaScript
Raw Normal View History

import {
2020-08-05 18:01:43 +00:00
clearLocalStorage,
setBrowserViewport,
2021-05-20 20:55:14 +00:00
withRestApi,
WP_ADMIN_LOGIN
} from '@woocommerce/e2e-utils';
2021-05-20 20:55:14 +00:00
const config = require('config');
const { HTTPClientFactory } = require('@woocommerce/api');
/**
2021-05-20 20:55:14 +00:00
* Uses the WordPress API to delete all existing posts
*/
async function trashExistingPosts() {
2021-05-20 20:55:14 +00:00
const apiUrl = config.get('url');
const wpPostsEndpoint = '/wp/v2/posts';
const adminUsername = config.get('users.admin.username');
const adminPassword = config.get('users.admin.password');
const client = HTTPClientFactory.build(apiUrl)
.withBasicAuth(adminUsername, adminPassword)
.create();
2021-05-20 20:55:14 +00:00
// List all existing posts
const response = await client.get(wpPostsEndpoint);
const posts = response.data;
// Delete each post
for(const post of posts){
await client.delete(`${wpPostsEndpoint}/${post.id}`);
}
2021-05-20 17:18:46 +00:00
}
// Before every test suite run, delete all content created by the test. This ensures
// other posts/comments/etc. aren't dirtying tests and tests don't depend on
// each other's side-effects.
beforeAll( async () => {
await trashExistingPosts();
await withRestApi.deleteAllProducts();
await withRestApi.deleteAllCoupons();
2021-05-20 20:55:14 +00:00
await page.goto(WP_ADMIN_LOGIN);
2020-08-05 18:01:43 +00:00
await clearLocalStorage();
await setBrowserViewport( 'large' );
} );