Skip to content

Commit a414f1a

Browse files
authored
Merge pull request #112 from MalathiBalaraman31/test/sveltekit-private-env-valid
test(sveltekit): allow private env vars in +page.server.ts
2 parents 60db215 + abef96e commit a414f1a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/e2e/frameworks/cli.sveltekit.e2e.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,31 @@ describe('SvelteKit environment variable usage rules', () => {
179179
expect(res.stdout).toContain('Private env vars should only be used in server files like +page.server.ts');
180180
});
181181

182+
it('does not warn when using $env/static/private in +page.server.ts', () => {
183+
const cwd = tmpDir();
184+
makeSvelteKitProject(cwd);
185+
186+
fs.writeFileSync(
187+
path.join(cwd, 'src/routes/+page.server.ts'),
188+
`import { SECRET_KEY } from '$env/static/private/SECRET_KEY';
189+
190+
export function load() {
191+
return {
192+
secret: SECRET_KEY
193+
};
194+
}`
195+
);
196+
197+
fs.writeFileSync(path.join(cwd, '.env'), 'SECRET_KEY=123');
198+
199+
const res = runCli(cwd, ['--scan-usage']);
200+
201+
expect(res.status).toBe(0);
202+
expect(res.stdout).not.toContain('Private env vars');
203+
expect(res.stdout).not.toContain('warning');
204+
});
205+
206+
182207
it('warns when PUBLIC_ variable is used inside private env import', () => {
183208
const cwd = tmpDir();
184209
makeSvelteKitProject(cwd);

0 commit comments

Comments
 (0)