Skip to content

feat: handle configuration file not exposing a config object #22

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

Merged
merged 5 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions plugins/plugin-tools/src/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@ describe('config', () => {
JunoPluginError
);
});

it('throws if config is undefined in satelliteId', async () => {
vi.spyOn(configLoader, 'junoConfigExist').mockResolvedValue(true);
vi.spyOn(configLoader, 'readJunoConfig').mockResolvedValue(
undefined as unknown as JunoConfig
);

await expect(() => satelliteId({params: {}, mode: 'production'})).rejects.toThrow(
/No configuration exported/
);
});
});
});

Expand Down
14 changes: 13 additions & 1 deletion plugins/plugin-tools/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ export const satelliteId = async (args: ConfigArgs): Promise<string> => {
const junoConfigSatelliteId = async ({mode}: ConfigArgs): Promise<string> => {
await assertJunoConfig();

const config = await readJunoConfig({mode});

if (config === undefined || !('satellite' in config)) {
throw new JunoPluginError(`No configuration exported for ${mode}.`);
}

const {
satellite: {ids, satelliteId: deprecatedSatelliteId, id}
} = await readJunoConfig({mode});
Expand Down Expand Up @@ -62,9 +68,15 @@ const containerSatelliteId = async ({mode}: ConfigArgs): Promise<string> => {
return DOCKER_SATELLITE_ID;
}

const config = await readJunoConfig({mode});

if (config == undefined || !('satellite' in config)) {
return DOCKER_SATELLITE_ID;
}

const {
satellite: {ids}
} = await readJunoConfig({mode});
} = config;

return ids?.[MODE_DEVELOPMENT] ?? DOCKER_SATELLITE_ID;
};
Expand Down
13 changes: 10 additions & 3 deletions plugins/plugin-tools/src/init.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,19 @@ describe('init', () => {
});

it('throws if satelliteId is missing in config in production', async () => {
vi.spyOn(configLoader, 'readJunoConfig').mockResolvedValueOnce({
satellite: {}
} as unknown as JunoConfig);
vi.spyOn(configLoader, 'readJunoConfig').mockImplementation(
// eslint-disable-next-line require-await
async () => ({satellite: {}}) as unknown as JunoConfig
);

await expect(initConfig(args)).rejects.toThrow(
'Your project needs a Satellite for production. Create one at https://console.juno.build and set its ID in your configuration file.'
);
});

it('throws if readJunoConfig returns undefined', async () => {
vi.spyOn(configLoader, 'readJunoConfig').mockResolvedValue(undefined as unknown as JunoConfig);

await expect(initConfig(args)).rejects.toThrow('No configuration exported for production.');
});
});