Skip to content

Commit d5c3074

Browse files
fortmarekOlimpiaZurek
authored andcommitted
Use verdaccio for the template e2e test (facebook#34577)
Summary: This PR adds [verdaccio](https://github.com/verdaccio/verdaccio) to release packages in the `packages` directory during the E2E test on CI. The rationale behind this is the following: - Firstly, we wanted to push the [monorepo RFC](react-native-community/discussions-and-proposals#480). We hit an issue when renaming the packages to follow the same convention caused by the e2e test using the template to fail. This is because the template installs packages from the live version of npm – and if you just rename a package in a given PR without releasing it, the package understandably can't be installed since it's not published, yet – as you can see [here](https://app.circleci.com/pipelines/github/facebook/react-native/15286/workflows/149df51f-f59b-4eb3-b92c-20c513111f04/jobs/282135?invite=true#step-108-283). - Secondly, the current e2e test on `main` does not actually test the latest code of the packages in the `packages` directory as it simply downloads the latest versions from npm. This creates a divide between what's tested and what users should expect when using nightlies or when a new minor is released. ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [Internal] [Changed] - Use verdaccio for template e2e test Pull Request resolved: facebook#34577 Test Plan: `test_js` CI check should pass. Additionally, I have temporarily updated the [PR](facebook#34572) renaming `assets` to `assets-registry` to include the verdaccio changes – the `test_js` passes there, additionally proving merging this PR will unblock us with the rename PRs. Reviewed By: cipolleschi Differential Revision: D39723048 Pulled By: cortinico fbshipit-source-id: aeff3811967360740df3b3dbf1df50e506fb72d8
1 parent 48c9d82 commit d5c3074

File tree

4 files changed

+95
-4
lines changed

4 files changed

+95
-4
lines changed

.circleci/verdaccio.yml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
storage: ./storage
2+
auth:
3+
htpasswd:
4+
file: ./htpasswd
5+
uplinks:
6+
npmjs:
7+
url: https://registry.npmjs.org/
8+
max_fails: 40
9+
maxage: 30m
10+
timeout: 60s
11+
fail_timeout: 10m
12+
cache: false
13+
agent_options:
14+
keepAlive: true
15+
maxSockets: 40
16+
maxFreeSockets: 10
17+
packages:
18+
# Group and isolate all local packages, avoid being proxy from outside
19+
'@react-native/*':
20+
access: $all
21+
publish: $all
22+
# The below specific entries can be removed once they are renamed and have the @react-native prefix
23+
'@react-native-community/eslint-config':
24+
access: $all
25+
publish: $all
26+
'@react-native-community/eslint-plugin':
27+
access: $all
28+
publish: $all
29+
'react-native-codegen':
30+
access: $all
31+
publish: $all
32+
'react-native-gradle-plugin':
33+
access: $all
34+
publish: $all
35+
'@*/*':
36+
access: $all
37+
publish: $authenticated
38+
proxy: npmjs
39+
'**':
40+
access: $all
41+
publish: $all
42+
proxy: npmjs
43+
logs:
44+
- {type: file, path: verdaccio.log, format: json, level: warn}

scripts/run-ci-e2e-tests.js

+20-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const {cd, cp, echo, exec, exit, mv, rm} = require('shelljs');
2323
const spawn = require('child_process').spawn;
2424
const argv = require('yargs').argv;
2525
const path = require('path');
26+
const {setupVerdaccio} = require('./setup-verdaccio');
2627

2728
const SCRIPTS = __dirname;
2829
const ROOT = path.normalize(path.join(__dirname, '..'));
@@ -35,6 +36,7 @@ const REACT_NATIVE_APP_DIR = `${REACT_NATIVE_TEMP_DIR}/template`;
3536
const numberOfRetries = argv.retries || 1;
3637
let SERVER_PID;
3738
let APPIUM_PID;
39+
let VERDACCIO_PID;
3840
let exitCode;
3941

4042
function describe(message) {
@@ -70,6 +72,19 @@ try {
7072

7173
const REACT_NATIVE_PACKAGE = path.join(ROOT, 'react-native-*.tgz');
7274

75+
describe('Set up Verdaccio');
76+
VERDACCIO_PID = setupVerdaccio();
77+
78+
describe('Publish packages');
79+
const packages = JSON.parse(
80+
JSON.parse(exec('yarn --json workspaces info').stdout).data,
81+
);
82+
Object.keys(packages).forEach(packageName => {
83+
exec(
84+
`cd ${packages[packageName].location} && npm publish --registry http://localhost:4873 --yes --access public`,
85+
);
86+
});
87+
7388
describe('Scaffold a basic React Native app from template');
7489
exec(`rsync -a ${ROOT}/template ${REACT_NATIVE_TEMP_DIR}`);
7590
cd(REACT_NATIVE_APP_DIR);
@@ -156,9 +171,7 @@ try {
156171

157172
describe(`Start Metro, ${SERVER_PID}`);
158173
// shelljs exec('', {async: true}) does not emit stdout events, so we rely on good old spawn
159-
const packagerProcess = spawn('yarn', ['start', '--max-workers 1'], {
160-
env: process.env,
161-
});
174+
const packagerProcess = spawn('yarn', ['start', '--max-workers 1']);
162175
SERVER_PID = packagerProcess.pid;
163176
// wait a bit to allow packager to startup
164177
exec('sleep 15s');
@@ -288,5 +301,9 @@ try {
288301
echo(`Killing appium ${APPIUM_PID}`);
289302
exec(`kill -9 ${APPIUM_PID}`);
290303
}
304+
if (VERDACCIO_PID) {
305+
echo(`Killing verdaccio ${VERDACCIO_PID}`);
306+
exec(`kill -9 ${VERDACCIO_PID}`);
307+
}
291308
}
292309
exit(exitCode);

scripts/setup-verdaccio.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
*/
9+
10+
'use strict';
11+
12+
const {exec} = require('shelljs');
13+
const spawn = require('child_process').spawn;
14+
15+
function setupVerdaccio() {
16+
const verdaccioProcess = spawn('npx', [
17+
18+
'--config',
19+
'.circleci/verdaccio.yml',
20+
]);
21+
const VERDACCIO_PID = verdaccioProcess.pid;
22+
exec('npx [email protected] http://localhost:4873');
23+
exec('npm set registry http://localhost:4873');
24+
exec('echo "//localhost:4873/:_authToken=secretToken" > .npmrc');
25+
return VERDACCIO_PID;
26+
}
27+
28+
module.exports = {
29+
setupVerdaccio: setupVerdaccio,
30+
};

template/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"devDependencies": {
1717
"@babel/core": "^7.12.9",
1818
"@babel/runtime": "^7.12.5",
19-
"@react-native-community/eslint-config": "^2.0.0",
19+
"@react-native-community/eslint-config": "^3.0.0",
2020
"babel-jest": "^26.6.3",
2121
"eslint": "^8.19.0",
2222
"jest": "^26.6.3",

0 commit comments

Comments
 (0)