mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.8 KiB
64 lines
1.8 KiB
2 years ago
|
import { Page } from '@playwright/test';
|
||
2 years ago
|
import axios from 'axios';
|
||
|
|
||
2 years ago
|
export interface NcContext {
|
||
|
project: any;
|
||
|
token: string;
|
||
|
dbType?: string;
|
||
|
}
|
||
|
|
||
2 years ago
|
const setup = async ({ page, isEmptyProject }: { page: Page; isEmptyProject?: boolean }): Promise<NcContext> => {
|
||
2 years ago
|
let dbType = process.env.CI ? process.env.E2E_DB_TYPE : process.env.E2E_DEV_DB_TYPE;
|
||
2 years ago
|
dbType = dbType || 'mysql';
|
||
2 years ago
|
|
||
2 years ago
|
if (!process.env.CI) console.time(`setup ${process.env.TEST_PARALLEL_INDEX}`);
|
||
|
let response;
|
||
|
try {
|
||
|
response = await axios.post(`http://localhost:8080/api/v1/meta/test/reset`, {
|
||
|
parallelId: process.env.TEST_PARALLEL_INDEX,
|
||
|
dbType,
|
||
|
isEmptyProject,
|
||
|
});
|
||
|
} catch (e) {
|
||
|
console.error(`Error resetting project: ${process.env.TEST_PARALLEL_INDEX}`, e);
|
||
|
}
|
||
|
if (!process.env.CI) console.timeEnd(`setup ${process.env.TEST_PARALLEL_INDEX}`);
|
||
|
|
||
|
if (response.status !== 200 || !response.data?.token || !response.data?.project) {
|
||
|
console.error('Failed to reset test data', response.data, response.status);
|
||
2 years ago
|
throw new Error('Failed to reset test data');
|
||
|
}
|
||
2 years ago
|
const token = response.data.token;
|
||
|
|
||
2 years ago
|
await page.addInitScript(
|
||
|
async ({ token }) => {
|
||
2 years ago
|
try {
|
||
2 years ago
|
let initialLocalStorage = {};
|
||
|
try {
|
||
|
initialLocalStorage = JSON.parse(localStorage.getItem('nocodb-gui-v2') || '{}');
|
||
|
} catch (e) {
|
||
|
console.error('Failed to parse local storage', e);
|
||
|
}
|
||
|
window.localStorage.setItem(
|
||
|
'nocodb-gui-v2',
|
||
|
JSON.stringify({
|
||
|
...initialLocalStorage,
|
||
|
token: token,
|
||
|
})
|
||
|
);
|
||
|
} catch (e) {
|
||
|
window.console.log(e);
|
||
2 years ago
|
}
|
||
2 years ago
|
},
|
||
|
{ token: token }
|
||
|
);
|
||
2 years ago
|
|
||
2 years ago
|
const project = response.data.project;
|
||
2 years ago
|
|
||
|
await page.goto(`/#/nc/${project.id}/auth`);
|
||
|
|
||
2 years ago
|
return { project, token, dbType } as NcContext;
|
||
2 years ago
|
};
|
||
2 years ago
|
|
||
2 years ago
|
export default setup;
|