Fix test-e2e-local when building artifacts locally (#43043)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43043

Restores behaviour of `yarn test-e2e-local` when we are not using `--circleciToken`. The `npm pack` logic (necessary for the subsequent `updateTemplatePackage` call before initing `RNTestProject`) was deleted in https://github.com/facebook/react-native/pull/41172 / D50651448.

https://github.com/facebook/react-native/commit/4eed12b7df5d9731e556b77d701c87dcf91d3a1f#diff-56f57bf0eac99b0fda1b2938aceb8d9b663db82c07cb405bd53a01c8689710ffL224-L240

Changelog: [Internal]

Reviewed By: cipolleschi

Differential Revision: D53806191

fbshipit-source-id: 918306d5dea90266292728cda9c0e243e5c37eba
This commit is contained in:
Alex Hunt
2024-02-15 09:06:44 -08:00
committed by Facebook GitHub Bot
parent ca980447f0
commit afc61ab643
+22
View File
@@ -25,6 +25,7 @@ const {
prepareArtifacts,
setupCircleCIArtifacts,
} = require('./utils/testing-utils');
const fs = require('fs');
const path = require('path');
const {cd, exec, popd, pushd, pwd, sed} = require('shelljs');
const yargs = require('yargs');
@@ -229,6 +230,27 @@ async function testRNTestProject(
reactNativePackagePath,
);
// If artifacts were built locally, we need to pack the react-native package
if (circleCIArtifacts == null) {
exec('npm pack --pack-destination ', {cwd: reactNativePackagePath});
// node pack does not creates a version of React Native with the right name on main.
// Let's add some defensive programming checks:
if (!fs.existsSync(localNodeTGZPath)) {
const tarfile = fs
.readdirSync(reactNativePackagePath)
.find(
name => name.startsWith('react-native-') && name.endsWith('.tgz'),
);
if (tarfile == null) {
throw new Error("Couldn't find a zipped version of react-native");
}
exec(
`cp ${path.join(reactNativePackagePath, tarfile)} ${localNodeTGZPath}`,
);
}
}
updateTemplatePackage({
'react-native': `file://${localNodeTGZPath}`,
});