mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 03:46:08 +00:00
fix(e2e): APP_BASE_URL (#2938)
* fix: should use APP_BASE_URL * chore: should not start local service when setting APP_BASE_URL * fix: should use process.env.APP_BASE_URL
This commit is contained in:
parent
fdf4c2d96c
commit
f374c2f9b5
@ -213,7 +213,7 @@ export const test = Object.assign(_test, {
|
||||
|
||||
const getStorageItem = (key: string, storageState: any) => {
|
||||
return storageState.origins
|
||||
.find((item) => item.origin === `http://localhost:${process.env.APP_PORT}`)
|
||||
.find((item) => item.origin === process.env.APP_BASE_URL)
|
||||
?.localStorage.find((item) => item.name === key)?.value;
|
||||
};
|
||||
|
||||
@ -248,12 +248,10 @@ const createPage = async (page: Page, options?: CreatePageOptions) => {
|
||||
});
|
||||
|
||||
const state = await api.storageState();
|
||||
const token = getStorageItem('NOCOBASE_TOKEN', state);
|
||||
const headers = getHeaders(state);
|
||||
|
||||
const systemSettings = await api.get(`/api/systemSettings:get/1`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
headers,
|
||||
});
|
||||
|
||||
const pageUid = uid();
|
||||
@ -262,9 +260,7 @@ const createPage = async (page: Page, options?: CreatePageOptions) => {
|
||||
if (systemSettings.ok()) {
|
||||
const { data } = await systemSettings.json();
|
||||
const result = await api.post(`/api/uiSchemas:insertAdjacent/${data.options.adminSchemaUid}?position=beforeEnd`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
headers,
|
||||
data: {
|
||||
schema: {
|
||||
_isJSONSchemaObject: true,
|
||||
@ -329,12 +325,10 @@ const deletePage = async (pageUid: string) => {
|
||||
});
|
||||
|
||||
const state = await api.storageState();
|
||||
const token = getStorageItem('NOCOBASE_TOKEN', state);
|
||||
const headers = getHeaders(state);
|
||||
|
||||
const result = await api.post(`/api/uiSchemas:remove/${pageUid}`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
headers,
|
||||
});
|
||||
|
||||
if (!result.ok()) {
|
||||
@ -348,13 +342,11 @@ const deleteCollections = async (collectionNames: string[]) => {
|
||||
});
|
||||
|
||||
const state = await api.storageState();
|
||||
const token = getStorageItem('NOCOBASE_TOKEN', state);
|
||||
const headers = getHeaders(state);
|
||||
const params = collectionNames.map((name) => `filterByTk[]=${name}`).join('&');
|
||||
|
||||
const result = await api.post(`/api/collections:destroy?${params}`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
headers,
|
||||
});
|
||||
|
||||
if (!result.ok()) {
|
||||
@ -388,7 +380,7 @@ const createCollections = async (collectionSettings: CollectionSetting | Collect
|
||||
});
|
||||
|
||||
const state = await api.storageState();
|
||||
const token = getStorageItem('NOCOBASE_TOKEN', state);
|
||||
const headers = getHeaders(state);
|
||||
// const defaultCollectionSetting: Partial<CollectionSetting> = {
|
||||
// template: 'general',
|
||||
// logging: true,
|
||||
@ -404,9 +396,7 @@ const createCollections = async (collectionSettings: CollectionSetting | Collect
|
||||
collectionSettings = Array.isArray(collectionSettings) ? collectionSettings : [collectionSettings];
|
||||
|
||||
const result = await api.post(`/api/collections:create`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
headers,
|
||||
// data: collectionSettings.map((item) => Object.assign(defaultCollectionSetting, item)),
|
||||
data: collectionSettings.filter((item) => !['users', 'roles'].includes(item.name)),
|
||||
});
|
||||
@ -465,14 +455,12 @@ const createFakerData = async (collectionSettings: CollectionSetting[]) => {
|
||||
});
|
||||
|
||||
const state = await api.storageState();
|
||||
const token = getStorageItem('NOCOBASE_TOKEN', state);
|
||||
const headers = getHeaders(state);
|
||||
|
||||
for (const item of collectionSettings) {
|
||||
const data = generateFakerData(item);
|
||||
const result = await api.post(`/api/${item.name}:create`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
headers,
|
||||
form: data,
|
||||
});
|
||||
|
||||
@ -490,3 +478,42 @@ export async function enableToConfig(page: Page) {
|
||||
await page.getByRole('button', { name: 'highlight' }).click();
|
||||
}
|
||||
}
|
||||
|
||||
function getHeaders(storageState: any) {
|
||||
const headers: any = {};
|
||||
const token = getStorageItem('NOCOBASE_TOKEN', storageState);
|
||||
const auth = getStorageItem('NOCOBASE_AUTH', storageState);
|
||||
const subAppName = new URL(process.env.APP_BASE_URL).pathname.match(/^\/apps\/([^/]*)\/*/)?.[1];
|
||||
const hostName = new URL(process.env.APP_BASE_URL).host;
|
||||
const locale = getStorageItem('NOCOBASE_LOCALE', storageState);
|
||||
const timezone = '+08:00';
|
||||
const withAclMeta = 'true';
|
||||
const role = getStorageItem('NOCOBASE_ROLE', storageState);
|
||||
|
||||
if (token) {
|
||||
headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
if (auth) {
|
||||
headers['X-Authenticator'] = auth;
|
||||
}
|
||||
if (subAppName) {
|
||||
headers['X-App'] = subAppName;
|
||||
}
|
||||
if (hostName) {
|
||||
headers['X-Hostname'] = hostName;
|
||||
}
|
||||
if (locale) {
|
||||
headers['X-Locale'] = locale;
|
||||
}
|
||||
if (timezone) {
|
||||
headers['X-Timezone'] = timezone;
|
||||
}
|
||||
if (withAclMeta) {
|
||||
headers['X-With-Acl-Meta'] = withAclMeta;
|
||||
}
|
||||
if (role) {
|
||||
headers['X-Role'] = role;
|
||||
}
|
||||
|
||||
return headers;
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ const checkServer = async (duration = 1000, max = 60 * 10) => {
|
||||
}
|
||||
|
||||
axios
|
||||
.get(`http://localhost:${process.env.APP_PORT}/api/__health_check`)
|
||||
.get(`${process.env.APP_BASE_URL}/api/__health_check`)
|
||||
.then((response) => {
|
||||
if (response.status === 200) {
|
||||
clearInterval(timer);
|
||||
@ -86,7 +86,7 @@ const checkUI = async (duration = 1000, max = 60 * 10) => {
|
||||
}
|
||||
|
||||
axios
|
||||
.get(`http://localhost:${process.env.APP_PORT}/__umi/api/bundle-status`)
|
||||
.get(`${process.env.APP_BASE_URL}/__umi/api/bundle-status`)
|
||||
.then((response) => {
|
||||
if (response.data.bundleStatus.done) {
|
||||
clearInterval(timer);
|
||||
@ -138,6 +138,12 @@ export const runNocoBase = async (options?: CommonOptions<any>) => {
|
||||
return { awaitForNocoBase };
|
||||
}
|
||||
|
||||
if (!process.env.APP_BASE_URL.includes('localhost')) {
|
||||
return {
|
||||
awaitForNocoBase: async () => {},
|
||||
};
|
||||
}
|
||||
|
||||
// 加上 -f 会清空数据库
|
||||
console.log('yarn nocobase install -f');
|
||||
await runCommand('yarn', ['nocobase', 'install', '-f'], options);
|
||||
|
Loading…
Reference in New Issue
Block a user