Files
vercel/packages/build-utils/test/unit.get-platform-env.test.ts
Sean Massa 0490a7733b [tests] install root typescript version 4.9.5 and standardize on that version (#9858)
This add a root-level `typescript` version that matches the one used throughout for VS Code (and other IDEs) to use when browsing the code. After this PR merges, you will be able to set VS Code's TypeScript version to match the project's version.

This will remove issues where the IDE says TypeScript compilation is good to go, but `pnpm build` disagrees.

If there's a better way to allow this, please suggest it!

---

To enable:

<img width="849" alt="Screenshot 2023-04-25 at 4 28 22 PM" src="https://user-images.githubusercontent.com/41545/234408245-205b3260-7b1d-4c43-a531-d616915dbefb.png">

Then:

<img width="1015" alt="Screenshot 2023-04-25 at 4 29 20 PM" src="https://user-images.githubusercontent.com/41545/234408271-4e7b4ec8-0be3-4743-afd7-813a267c0756.png">
2023-04-27 08:13:53 +00:00

46 lines
1.1 KiB
TypeScript
Vendored

import assert from 'assert';
import { getPlatformEnv } from '../src';
describe('Test `getPlatformEnv()`', () => {
it('should support `VERCEL_` prefix', () => {
try {
assert.equal(undefined, getPlatformEnv('FOO'));
process.env.VERCEL_FOO = 'bar';
assert.equal('bar', getPlatformEnv('FOO'));
} finally {
delete process.env.VERCEL_FOO;
}
});
it('should support `NOW_` prefix', () => {
try {
assert.equal(undefined, getPlatformEnv('FOO'));
process.env.NOW_FOO = 'bar';
assert.equal('bar', getPlatformEnv('FOO'));
} finally {
delete process.env.NOW_FOO;
}
});
it('should throw an error if both env vars exist', () => {
let err: Error | null = null;
try {
process.env.NOW_FOO = 'bar';
process.env.VERCEL_FOO = 'baz';
getPlatformEnv('FOO');
} catch (_err: unknown) {
err = _err as Error;
} finally {
delete process.env.NOW_FOO;
delete process.env.VERCEL_FOO;
}
assert(err);
assert.equal(
err!.message,
'Both "VERCEL_FOO" and "NOW_FOO" env vars are defined. Please only define the "VERCEL_FOO" env var.'
);
});
});