Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(testing): improve local registry script… #29050

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions packages/js/src/plugins/jest/start-local-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ import { execSync, fork } from 'child_process';
* @param storage the storage location for the local registry
* @param verbose whether to log verbose output
* @param clearStorage whether to clear the verdaccio storage before running the registry
* @param listenAddress the address that verdaccio should listen to (default to `localhost`)
*/
export function startLocalRegistry({
localRegistryTarget,
storage,
verbose,
clearStorage,
listenAddress = 'localhost',
}: {
localRegistryTarget: string;
storage?: string;
verbose?: boolean;
clearStorage?: boolean;
listenAddress?: string;
}) {
if (!localRegistryTarget) {
throw new Error(`localRegistryTarget is required`);
Expand All @@ -36,17 +39,21 @@ export function startLocalRegistry({
const listener = (data) => {
if (verbose) {
process.stdout.write(data);
console.log('Waiting for local registry to start...');
}
if (data.toString().includes('http://localhost:')) {
if (data.toString().includes(`http://${listenAddress}:`)) {
const port = parseInt(
data.toString().match(/localhost:(?<port>\d+)/)?.groups?.port
data.toString().match(new RegExp(`${listenAddress}:(?<port>\\d+)`))
?.groups?.port
);
console.log('Local registry started on port ' + port);

const registry = `http://localhost:${port}`;
const registry = `http://${listenAddress}:${port}`;

console.log(`Local registry started on ${registry}`);

process.env.npm_config_registry = registry;
execSync(
`npm config set //localhost:${port}/:_authToken "secretVerdaccioToken"`,
`npm config set //${listenAddress}:${port}/:_authToken "secretVerdaccioToken"`,
{
windowsHide: false,
}
Expand All @@ -56,13 +63,13 @@ export function startLocalRegistry({
process.env.YARN_REGISTRY = registry;
// yarnv2
process.env.YARN_NPM_REGISTRY_SERVER = registry;
process.env.YARN_UNSAFE_HTTP_WHITELIST = 'localhost';
process.env.YARN_UNSAFE_HTTP_WHITELIST = listenAddress;

console.log('Set npm and yarn config registry to ' + registry);

resolve(() => {
childProcess.kill();
execSync(`npm config delete //localhost:${port}/:_authToken`, {
execSync(`npm config delete //${listenAddress}:${port}/:_authToken`, {
windowsHide: false,
});
});
Expand Down