mirror of https://github.com/nocodb/nocodb
66 lines
1.9 KiB
66 lines
1.9 KiB
2 years ago
|
import { Page, selectors } 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
|
selectors.setTestIdAttribute('data-testid');
|
||
|
|
||
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 || 'sqlite';
|
||
2 years ago
|
|
||
2 years ago
|
// if (!process.env.CI) console.time(`setup ${process.env.TEST_PARALLEL_INDEX}`);
|
||
2 years ago
|
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);
|
||
|
}
|
||
2 years ago
|
// if (!process.env.CI) console.timeEnd(`setup ${process.env.TEST_PARALLEL_INDEX}`);
|
||
2 years ago
|
|
||
|
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;
|