Skip to content

Commit f18f404

Browse files
committed
refactor: ♻️ move around tests and text
1 parent 4a31e86 commit f18f404

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

src/helpers/get-public-env.spec.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,6 @@ describe('getPublicEnv()', () => {
2222
delete process.env.NEXT_PUBLIC_BAZ;
2323
});
2424

25-
it('should show an info message after reading the environment', () => {
26-
getPublicEnv();
27-
28-
expect(infoSpy).toHaveBeenCalledWith(
29-
`${chalk.cyan(
30-
`info`
31-
)} - [next-runtime-env] - Read environment variables prefixed with 'NEXT_PUBLIC_' from process.env.`
32-
);
33-
});
34-
3525
it('should return an allow-listed value', () => {
3626
process.env.NEXT_PUBLIC_FOO = 'foo';
3727

@@ -76,4 +66,14 @@ describe('getPublicEnv()', () => {
7666
NEXT_PUBLIC_BAZ: 'baz',
7767
});
7868
});
69+
70+
it('should show an info message after reading the environment', () => {
71+
getPublicEnv();
72+
73+
expect(infoSpy).toHaveBeenCalledWith(
74+
`${chalk.cyan(
75+
`info`
76+
)} - [next-runtime-env] - Read environment variables prefixed with 'NEXT_PUBLIC_' from process.env.`
77+
);
78+
});
7979
});

src/helpers/write-browser-env.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const path = `${base}/public`;
1010
const file = `${path}/__ENV.js`;
1111
const message = `${chalk.cyan(
1212
`info`
13-
)} - [next-runtime-env] - Wrote browser runtime environment variables to ${file}`;
13+
)} - [next-runtime-env] - Wrote browser runtime environment variables to '${file}'.`;
1414

1515
beforeAll(() => {
1616
infoSpy.mockImplementation();

src/helpers/write-browser-env.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ export function writeBrowserEnv(env: NodeJS.ProcessEnv) {
1414

1515
fs.writeFileSync(path, content);
1616

17-
log.info(`Wrote browser runtime environment variables to ${path}`);
17+
log.info(`Wrote browser runtime environment variables to '${path}'.`);
1818
}

src/utils/log.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
/* eslint-disable no-console */
2-
31
import chalk from 'chalk';
42

53
const libraryName = '[next-runtime-env]';
6-
const librarySeperator = '-';
7-
const libraryPrefix = `${libraryName} ${librarySeperator}`;
4+
const librarySeparator = '-';
5+
const libraryPrefix = `${libraryName} ${librarySeparator}`;
86

97
const prefixes = {
8+
// Double space before the dash aligns messages in the terminal and improves readability.
109
warn: `${chalk.yellow(`warn`)} - ${libraryPrefix}`,
11-
info: `${chalk.cyan(`info`)} - ${libraryPrefix}`, // Double space before the dash aligns messages in the terminal and improves readability.
10+
info: `${chalk.cyan(`info`)} - ${libraryPrefix}`,
1211
};
1312

1413
export function warn(message: string) {
14+
// eslint-disable-next-line no-console
1515
console.warn(`${prefixes.warn} ${message}`);
1616
}
1717

1818
export function info(message: string) {
19+
// eslint-disable-next-line no-console
1920
console.info(`${prefixes.info} ${message}`);
2021
}

0 commit comments

Comments
 (0)