loqatevars
Version:
Locate JavaScript files with 'const' or 'process.env' usage in LLM-generated codebases
53 lines (47 loc) • 1.69 kB
JavaScript
const { analyzeConstUsage } = require('../lib/utils');
const fs = require('fs-extra');
describe('indirect-env tests', () => {
it('should detect direct process.env access', async () => {
const code = `const value = process.env.TEST_VAR;`;
const result = analyzeConstUsage(code, 'test.js');
expect(result.hasProcessEnv).toBe(true);
});
it('should detect const env = process.env pattern', async () => {
const code = `
const env = process.env;
console.log(env.TEST_VAR);
`;
const result = analyzeConstUsage(code, 'test.js');
expect(result.hasProcessEnv).toBe(true);
});
it('should detect destructured env access', async () => {
const code = `
const { env } = process;
console.log(env.TEST_VAR);
`;
const result = analyzeConstUsage(code, 'test.js');
expect(result.hasProcessEnv).toBe(true);
});
it('should detect deep destructured env access', async () => {
const code = `
const { env: myEnv } = process;
console.log(myEnv.TEST_VAR);
`;
const result = analyzeConstUsage(code, 'test.js');
expect(result.hasProcessEnv).toBe(true);
});
it('should detect dynamic access process["env"]', async () => {
const code = `const value = process['env'].TEST_VAR;`;
const result = analyzeConstUsage(code, 'test.js');
expect(result.hasProcessEnv).toBe(true);
});
it('should detect ES module imports as importConst', async () => {
const code = `
import fs from 'fs';
import { something } from 'module';
`;
const result = analyzeConstUsage(code, 'test.js');
expect(result.importConst).toBe(2);
expect(result.variableConst).toBe(0);
});
});