-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcli.strict.e2e.test.ts
More file actions
91 lines (74 loc) · 2.71 KB
/
Copy pathcli.strict.e2e.test.ts
File metadata and controls
91 lines (74 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { describe, it, expect, beforeAll, afterAll, afterEach } from 'vitest';
import fs from 'fs';
import path from 'path';
import { makeTmpDir, rmrf } from '../utils/fs-helpers.js';
import { buildOnce, runCli, cleanupBuild } from '../utils/cli-helpers.js';
const tmpDirs: string[] = [];
beforeAll(() => {
buildOnce();
});
afterAll(() => {
cleanupBuild();
});
afterEach(() => {
while (tmpDirs.length) {
const dir = tmpDirs.pop();
if (dir) rmrf(dir);
}
});
function tmpDir() {
const dir = makeTmpDir();
tmpDirs.push(dir);
return dir;
}
describe('--strict mode', () => {
it('fails on unused variables', () => {
const cwd = tmpDir();
fs.writeFileSync(path.join(cwd, '.env'), 'UNUSED=1\n');
fs.writeFileSync(path.join(cwd, '.env.example'), ''); // no usages
const res = runCli(cwd, ['--strict']);
expect(res.status).toBe(1);
expect(res.stdout).toContain('⚠️ Unused in codebase');
});
it('fails on duplicate variables in .env', () => {
const cwd = tmpDir();
fs.writeFileSync(path.join(cwd, '.env'), 'FOO=1\nFOO=2\n');
fs.writeFileSync(path.join(cwd, '.env.example'), 'FOO=\n');
const res = runCli(cwd, ['--strict']);
expect(res.status).toBe(1);
expect(res.stdout).toContain('⚠️ Duplicate keys');
});
it('fails on duplicate variables in .env.example', () => {
const cwd = tmpDir();
fs.writeFileSync(path.join(cwd, '.env'), 'FOO=1\n');
fs.writeFileSync(path.join(cwd, '.env.example'), 'FOO=\nFOO=\n');
const res = runCli(cwd, ['--strict', '--example', '.env.example']);
expect(res.status).toBe(1);
expect(res.stdout).toContain('⚠️ Duplicate keys in .env.example');
});
it('succeeds when there are no warnings', () => {
const cwd = tmpDir();
fs.writeFileSync(path.join(cwd, '.env'), '');
fs.writeFileSync(path.join(cwd, '.gitignore'), '.env');
const res = runCli(cwd, ['--strict']);
expect(res.status).toBe(0);
});
});
describe('--strict mode with --compare', () => {
it('fails on duplicate variables in .env', () => {
const cwd = tmpDir();
fs.writeFileSync(path.join(cwd, '.env'), 'FOO=1\nFOO=2\n');
fs.writeFileSync(path.join(cwd, '.env.example'), 'FOO=\n');
const res = runCli(cwd, ['--strict', '--compare']);
expect(res.status).toBe(1);
expect(res.stdout).toContain('⚠️ Duplicate keys');
});
it('fails on duplicate variables in .env.example', () => {
const cwd = tmpDir();
fs.writeFileSync(path.join(cwd, '.env'), 'FOO=1\n');
fs.writeFileSync(path.join(cwd, '.env.example'), 'FOO=\nFOO=\n');
const res = runCli(cwd, ['--strict', '--compare']);
expect(res.status).toBe(1);
expect(res.stdout).toContain('⚠️ Duplicate keys in .env.example');
});
});