-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b80fcaf
commit d45afb7
Showing
2 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
...__/lib/no-undeclared-env-vars/framework-inference/no-undeclared-env-vars.commonjs.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import path from "node:path"; | ||
import { RuleTester } from "eslint"; | ||
import { RULES } from "../../../../lib/constants"; | ||
import rule from "../../../../lib/rules/no-undeclared-env-vars"; | ||
|
||
const ruleTester = new RuleTester({ | ||
parserOptions: { ecmaVersion: 2020 }, | ||
}); | ||
|
||
const cwd = path.join( | ||
__dirname, | ||
"../../../../__fixtures__/framework-inference" | ||
); | ||
const nextJsFilename = path.join(cwd, "/apps/nextjs/index.js"); | ||
const viteFilename = path.join(cwd, "/apps/vite/index.js"); | ||
const options = (extra: Record<string, unknown> = {}) => ({ | ||
options: [ | ||
{ | ||
cwd, | ||
...extra, | ||
}, | ||
], | ||
}); | ||
|
||
ruleTester.run(RULES.noUndeclaredEnvVars, rule, { | ||
valid: [ | ||
{ | ||
code: `const { NEXT_PUBLIC_ZILTOID } = process.env;`, | ||
...options(), | ||
filename: nextJsFilename, | ||
}, | ||
{ | ||
code: `const { VITE_THINGS } = process.env;`, | ||
...options(), | ||
filename: viteFilename, | ||
}, | ||
], | ||
invalid: [ | ||
{ | ||
code: `const { NEXT_PUBLIC_ZILTOID } = process.env;`, | ||
...options(), | ||
filename: viteFilename, | ||
errors: [ | ||
{ | ||
message: | ||
"NEXT_PUBLIC_ZILTOID is not listed as a dependency in turbo.json", | ||
}, | ||
], | ||
}, | ||
{ | ||
code: `const { VITE_THINGS } = process.env;`, | ||
...options(), | ||
filename: nextJsFilename, | ||
errors: [ | ||
{ | ||
message: "VITE_THINGS is not listed as a dependency in turbo.json", | ||
}, | ||
], | ||
}, | ||
], | ||
}); |
61 changes: 61 additions & 0 deletions
61
...ts__/lib/no-undeclared-env-vars/framework-inference/no-undeclared-env-vars.module.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import path from "node:path"; | ||
import { RuleTester } from "eslint"; | ||
import { RULES } from "../../../../lib/constants"; | ||
import rule from "../../../../lib/rules/no-undeclared-env-vars"; | ||
|
||
const ruleTester = new RuleTester({ | ||
parserOptions: { ecmaVersion: 2020, sourceType: "module" }, | ||
}); | ||
|
||
const cwd = path.join( | ||
__dirname, | ||
"../../../../__fixtures__/framework-inference" | ||
); | ||
const nextJsFilename = path.join(cwd, "/apps/nextjs/index.js"); | ||
const viteFilename = path.join(cwd, "/apps/vite/index.js"); | ||
const options = (extra: Record<string, unknown> = {}) => ({ | ||
options: [ | ||
{ | ||
cwd, | ||
...extra, | ||
}, | ||
], | ||
}); | ||
|
||
ruleTester.run(RULES.noUndeclaredEnvVars, rule, { | ||
valid: [ | ||
{ | ||
code: `const { NEXT_PUBLIC_ZILTOID } = import.meta.env;`, | ||
...options(), | ||
filename: nextJsFilename, | ||
}, | ||
{ | ||
code: `const { VITE_THINGS } = import.meta.env;`, | ||
...options(), | ||
filename: viteFilename, | ||
}, | ||
], | ||
invalid: [ | ||
{ | ||
code: `const { NEXT_PUBLIC_ZILTOID } = import.meta.env;`, | ||
...options(), | ||
filename: viteFilename, | ||
errors: [ | ||
{ | ||
message: | ||
"NEXT_PUBLIC_ZILTOID is not listed as a dependency in turbo.json", | ||
}, | ||
], | ||
}, | ||
{ | ||
code: `const { VITE_THINGS } = import.meta.env;`, | ||
...options(), | ||
filename: nextJsFilename, | ||
errors: [ | ||
{ | ||
message: "VITE_THINGS is not listed as a dependency in turbo.json", | ||
}, | ||
], | ||
}, | ||
], | ||
}); |