e2e-test: add test for backwards compatibility with React 17

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-02-08 18:37:07 +01:00
parent 52941b2639
commit 7ca20761e9
+43
View File
@@ -71,6 +71,20 @@ export async function run() {
env: { ...process.env, CI: undefined },
});
await switchToReact17(appDir);
print(`Running 'yarn install' to install React 17`);
await runPlain(['yarn', 'install'], { cwd: appDir });
print(`Running 'yarn tsc' with React 17`);
await runPlain(['yarn', 'tsc'], { cwd: appDir });
print(`Running 'yarn test:e2e' with React 17`);
await runPlain(['yarn', 'test:e2e'], {
cwd: appDir,
env: { ...process.env, CI: undefined },
});
if (
Boolean(process.env.POSTGRES_USER) ||
Boolean(process.env.MYSQL_CONNECTION)
@@ -393,6 +407,35 @@ async function createPlugin(options: {
}
}
/**
* Switch the entire project to use React 17
*/
async function switchToReact17(appDir: string) {
const rootPkg = await fs.readJson(resolvePath(appDir, 'package.json'));
rootPkg.resolutions = {
...(rootPkg.resolutions || {}),
react: '^17.0.0',
'react-dom': '^17.0.0',
'@types/react': '^17.0.0',
'@types/react-dom': '^17.0.0',
};
await fs.writeJson(resolvePath(appDir, 'package.json'), rootPkg, {
spaces: 2,
});
await fs.writeFile(
resolvePath(appDir, 'packages/app/src/index.tsx'),
`import '@backstage/cli/asset-types';
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
ReactDOM.render(<App />, document.getElementById('root'));
`,
'utf8',
);
}
/** Drops PG databases */
async function dropDB(database: string, client: string) {
try {