Skip to content

Commit d45afb7

Browse files
committed
adds tests for framework inference
1 parent b80fcaf commit d45afb7

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import path from "node:path";
2+
import { RuleTester } from "eslint";
3+
import { RULES } from "../../../../lib/constants";
4+
import rule from "../../../../lib/rules/no-undeclared-env-vars";
5+
6+
const ruleTester = new RuleTester({
7+
parserOptions: { ecmaVersion: 2020 },
8+
});
9+
10+
const cwd = path.join(
11+
__dirname,
12+
"../../../../__fixtures__/framework-inference"
13+
);
14+
const nextJsFilename = path.join(cwd, "/apps/nextjs/index.js");
15+
const viteFilename = path.join(cwd, "/apps/vite/index.js");
16+
const options = (extra: Record<string, unknown> = {}) => ({
17+
options: [
18+
{
19+
cwd,
20+
...extra,
21+
},
22+
],
23+
});
24+
25+
ruleTester.run(RULES.noUndeclaredEnvVars, rule, {
26+
valid: [
27+
{
28+
code: `const { NEXT_PUBLIC_ZILTOID } = process.env;`,
29+
...options(),
30+
filename: nextJsFilename,
31+
},
32+
{
33+
code: `const { VITE_THINGS } = process.env;`,
34+
...options(),
35+
filename: viteFilename,
36+
},
37+
],
38+
invalid: [
39+
{
40+
code: `const { NEXT_PUBLIC_ZILTOID } = process.env;`,
41+
...options(),
42+
filename: viteFilename,
43+
errors: [
44+
{
45+
message:
46+
"NEXT_PUBLIC_ZILTOID is not listed as a dependency in turbo.json",
47+
},
48+
],
49+
},
50+
{
51+
code: `const { VITE_THINGS } = process.env;`,
52+
...options(),
53+
filename: nextJsFilename,
54+
errors: [
55+
{
56+
message: "VITE_THINGS is not listed as a dependency in turbo.json",
57+
},
58+
],
59+
},
60+
],
61+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import path from "node:path";
2+
import { RuleTester } from "eslint";
3+
import { RULES } from "../../../../lib/constants";
4+
import rule from "../../../../lib/rules/no-undeclared-env-vars";
5+
6+
const ruleTester = new RuleTester({
7+
parserOptions: { ecmaVersion: 2020, sourceType: "module" },
8+
});
9+
10+
const cwd = path.join(
11+
__dirname,
12+
"../../../../__fixtures__/framework-inference"
13+
);
14+
const nextJsFilename = path.join(cwd, "/apps/nextjs/index.js");
15+
const viteFilename = path.join(cwd, "/apps/vite/index.js");
16+
const options = (extra: Record<string, unknown> = {}) => ({
17+
options: [
18+
{
19+
cwd,
20+
...extra,
21+
},
22+
],
23+
});
24+
25+
ruleTester.run(RULES.noUndeclaredEnvVars, rule, {
26+
valid: [
27+
{
28+
code: `const { NEXT_PUBLIC_ZILTOID } = import.meta.env;`,
29+
...options(),
30+
filename: nextJsFilename,
31+
},
32+
{
33+
code: `const { VITE_THINGS } = import.meta.env;`,
34+
...options(),
35+
filename: viteFilename,
36+
},
37+
],
38+
invalid: [
39+
{
40+
code: `const { NEXT_PUBLIC_ZILTOID } = import.meta.env;`,
41+
...options(),
42+
filename: viteFilename,
43+
errors: [
44+
{
45+
message:
46+
"NEXT_PUBLIC_ZILTOID is not listed as a dependency in turbo.json",
47+
},
48+
],
49+
},
50+
{
51+
code: `const { VITE_THINGS } = import.meta.env;`,
52+
...options(),
53+
filename: nextJsFilename,
54+
errors: [
55+
{
56+
message: "VITE_THINGS is not listed as a dependency in turbo.json",
57+
},
58+
],
59+
},
60+
],
61+
});

0 commit comments

Comments
 (0)