mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 06:55:50 +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) => {
|
const getStorageItem = (key: string, storageState: any) => {
|
||||||
return storageState.origins
|
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;
|
?.localStorage.find((item) => item.name === key)?.value;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -248,12 +248,10 @@ const createPage = async (page: Page, options?: CreatePageOptions) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const state = await api.storageState();
|
const state = await api.storageState();
|
||||||
const token = getStorageItem('NOCOBASE_TOKEN', state);
|
const headers = getHeaders(state);
|
||||||
|
|
||||||
const systemSettings = await api.get(`/api/systemSettings:get/1`, {
|
const systemSettings = await api.get(`/api/systemSettings:get/1`, {
|
||||||
headers: {
|
headers,
|
||||||
Authorization: `Bearer ${token}`,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const pageUid = uid();
|
const pageUid = uid();
|
||||||
@ -262,9 +260,7 @@ const createPage = async (page: Page, options?: CreatePageOptions) => {
|
|||||||
if (systemSettings.ok()) {
|
if (systemSettings.ok()) {
|
||||||
const { data } = await systemSettings.json();
|
const { data } = await systemSettings.json();
|
||||||
const result = await api.post(`/api/uiSchemas:insertAdjacent/${data.options.adminSchemaUid}?position=beforeEnd`, {
|
const result = await api.post(`/api/uiSchemas:insertAdjacent/${data.options.adminSchemaUid}?position=beforeEnd`, {
|
||||||
headers: {
|
headers,
|
||||||
Authorization: `Bearer ${token}`,
|
|
||||||
},
|
|
||||||
data: {
|
data: {
|
||||||
schema: {
|
schema: {
|
||||||
_isJSONSchemaObject: true,
|
_isJSONSchemaObject: true,
|
||||||
@ -329,12 +325,10 @@ const deletePage = async (pageUid: string) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const state = await api.storageState();
|
const state = await api.storageState();
|
||||||
const token = getStorageItem('NOCOBASE_TOKEN', state);
|
const headers = getHeaders(state);
|
||||||
|
|
||||||
const result = await api.post(`/api/uiSchemas:remove/${pageUid}`, {
|
const result = await api.post(`/api/uiSchemas:remove/${pageUid}`, {
|
||||||
headers: {
|
headers,
|
||||||
Authorization: `Bearer ${token}`,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!result.ok()) {
|
if (!result.ok()) {
|
||||||
@ -348,13 +342,11 @@ const deleteCollections = async (collectionNames: string[]) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const state = await api.storageState();
|
const state = await api.storageState();
|
||||||
const token = getStorageItem('NOCOBASE_TOKEN', state);
|
const headers = getHeaders(state);
|
||||||
const params = collectionNames.map((name) => `filterByTk[]=${name}`).join('&');
|
const params = collectionNames.map((name) => `filterByTk[]=${name}`).join('&');
|
||||||
|
|
||||||
const result = await api.post(`/api/collections:destroy?${params}`, {
|
const result = await api.post(`/api/collections:destroy?${params}`, {
|
||||||
headers: {
|
headers,
|
||||||
Authorization: `Bearer ${token}`,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!result.ok()) {
|
if (!result.ok()) {
|
||||||
@ -388,7 +380,7 @@ const createCollections = async (collectionSettings: CollectionSetting | Collect
|
|||||||
});
|
});
|
||||||
|
|
||||||
const state = await api.storageState();
|
const state = await api.storageState();
|
||||||
const token = getStorageItem('NOCOBASE_TOKEN', state);
|
const headers = getHeaders(state);
|
||||||
// const defaultCollectionSetting: Partial<CollectionSetting> = {
|
// const defaultCollectionSetting: Partial<CollectionSetting> = {
|
||||||
// template: 'general',
|
// template: 'general',
|
||||||
// logging: true,
|
// logging: true,
|
||||||
@ -404,9 +396,7 @@ const createCollections = async (collectionSettings: CollectionSetting | Collect
|
|||||||
collectionSettings = Array.isArray(collectionSettings) ? collectionSettings : [collectionSettings];
|
collectionSettings = Array.isArray(collectionSettings) ? collectionSettings : [collectionSettings];
|
||||||
|
|
||||||
const result = await api.post(`/api/collections:create`, {
|
const result = await api.post(`/api/collections:create`, {
|
||||||
headers: {
|
headers,
|
||||||
Authorization: `Bearer ${token}`,
|
|
||||||
},
|
|
||||||
// data: collectionSettings.map((item) => Object.assign(defaultCollectionSetting, item)),
|
// data: collectionSettings.map((item) => Object.assign(defaultCollectionSetting, item)),
|
||||||
data: collectionSettings.filter((item) => !['users', 'roles'].includes(item.name)),
|
data: collectionSettings.filter((item) => !['users', 'roles'].includes(item.name)),
|
||||||
});
|
});
|
||||||
@ -465,14 +455,12 @@ const createFakerData = async (collectionSettings: CollectionSetting[]) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const state = await api.storageState();
|
const state = await api.storageState();
|
||||||
const token = getStorageItem('NOCOBASE_TOKEN', state);
|
const headers = getHeaders(state);
|
||||||
|
|
||||||
for (const item of collectionSettings) {
|
for (const item of collectionSettings) {
|
||||||
const data = generateFakerData(item);
|
const data = generateFakerData(item);
|
||||||
const result = await api.post(`/api/${item.name}:create`, {
|
const result = await api.post(`/api/${item.name}:create`, {
|
||||||
headers: {
|
headers,
|
||||||
Authorization: `Bearer ${token}`,
|
|
||||||
},
|
|
||||||
form: data,
|
form: data,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -490,3 +478,42 @@ export async function enableToConfig(page: Page) {
|
|||||||
await page.getByRole('button', { name: 'highlight' }).click();
|
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
|
axios
|
||||||
.get(`http://localhost:${process.env.APP_PORT}/api/__health_check`)
|
.get(`${process.env.APP_BASE_URL}/api/__health_check`)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
clearInterval(timer);
|
clearInterval(timer);
|
||||||
@ -86,7 +86,7 @@ const checkUI = async (duration = 1000, max = 60 * 10) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
axios
|
axios
|
||||||
.get(`http://localhost:${process.env.APP_PORT}/__umi/api/bundle-status`)
|
.get(`${process.env.APP_BASE_URL}/__umi/api/bundle-status`)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (response.data.bundleStatus.done) {
|
if (response.data.bundleStatus.done) {
|
||||||
clearInterval(timer);
|
clearInterval(timer);
|
||||||
@ -138,6 +138,12 @@ export const runNocoBase = async (options?: CommonOptions<any>) => {
|
|||||||
return { awaitForNocoBase };
|
return { awaitForNocoBase };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!process.env.APP_BASE_URL.includes('localhost')) {
|
||||||
|
return {
|
||||||
|
awaitForNocoBase: async () => {},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// 加上 -f 会清空数据库
|
// 加上 -f 会清空数据库
|
||||||
console.log('yarn nocobase install -f');
|
console.log('yarn nocobase install -f');
|
||||||
await runCommand('yarn', ['nocobase', 'install', '-f'], options);
|
await runCommand('yarn', ['nocobase', 'install', '-f'], options);
|
||||||
|
Loading…
Reference in New Issue
Block a user