Skip to content

Commit 7391c09

Browse files
committed
feat: test for 'undefined'
1 parent 5d85a2f commit 7391c09

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

app-config-webpack/src/index.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,29 @@ describe('frontend-webpack-project example', () => {
231231
});
232232
});
233233

234+
it('fills in undefined for currentEnvironment', async () => {
235+
process.env.APP_CONFIG = JSON.stringify({ externalApiUrl: 'https://localhost:3999' });
236+
process.env.APP_CONFIG_ENV = '';
237+
238+
await new Promise<void>((done, reject) => {
239+
webpack([createOptions({}, true)], (err, stats) => {
240+
if (err) return reject(err);
241+
if (!stats) return reject(new Error('no stats'));
242+
if (stats.hasErrors()) reject(stats.toString());
243+
244+
const { children } = stats.toJson({ source: true });
245+
const [{ modules = [] }] = children || [];
246+
247+
expect(
248+
modules.some(({ source }) => source?.includes('export function currentEnvironment()')),
249+
).toBe(true);
250+
expect(modules.some(({ source }) => source?.includes('return undefined;'))).toBe(true);
251+
252+
done();
253+
});
254+
});
255+
});
256+
234257
it.skip('does not bundle the validateConfig function', async () => {
235258
process.env.APP_CONFIG = JSON.stringify({ externalApiUrl: 'https://localhost:3999' });
236259

app-config-webpack/src/loader.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ const loader = function AppConfigLoader(this: Loader) {
6868

6969
generatedText = `${generatedText}
7070
export function currentEnvironment() {
71-
return ${JSON.stringify(
72-
currentEnvironment(
73-
asEnvOptions(environmentOverride, environmentAliases, environmentSourceNames),
74-
),
75-
)};
71+
return ${
72+
JSON.stringify(
73+
currentEnvironment(
74+
asEnvOptions(environmentOverride, environmentAliases, environmentSourceNames),
75+
),
76+
) ?? 'undefined'
77+
};
7678
}
7779
`;
7880

0 commit comments

Comments
 (0)