import { env, createExecutionContext } from 'cloudflare:test';
const IncomingRequest = Request<unknown, IncomingRequestCfProperties>;
declare module "cloudflare:test" {
interface ProvidedEnv extends Env {}
}
describe('Testing environment', () => {
it('should have access to environment variables', async () => {
// Trying to use env variables for authorization
const headers = {
Authorization: `Bearer ${env.BYPASS_AUTH_TOKEN}`,
};
// Create the request
const request = new IncomingRequest(url, {
method: "GET",
headers,
});
// env.BYPASS_AUTH_TOKEN is undefined, making the Authorization header invalid
console.log(headers.Authorization); // "Bearer undefined"
// All other env variables also return undefined
console.log(env.API_KEY); // undefined
});
});
import { env, createExecutionContext } from 'cloudflare:test';
const IncomingRequest = Request<unknown, IncomingRequestCfProperties>;
declare module "cloudflare:test" {
interface ProvidedEnv extends Env {}
}
describe('Testing environment', () => {
it('should have access to environment variables', async () => {
// Trying to use env variables for authorization
const headers = {
Authorization: `Bearer ${env.BYPASS_AUTH_TOKEN}`,
};
// Create the request
const request = new IncomingRequest(url, {
method: "GET",
headers,
});
// env.BYPASS_AUTH_TOKEN is undefined, making the Authorization header invalid
console.log(headers.Authorization); // "Bearer undefined"
// All other env variables also return undefined
console.log(env.API_KEY); // undefined
});
});