-
Notifications
You must be signed in to change notification settings - Fork 53
fix(jsx-email): fix email check + --use-preview-props #389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,35 @@ | ||
| import { loadConfig } from '../../../../src/config.js'; | ||
| import { createRequire } from 'node:module'; | ||
| import { dirname } from 'node:path'; | ||
|
|
||
| import loglevelnext from 'loglevelnext'; | ||
|
|
||
| const require = createRequire(import.meta.url); | ||
|
|
||
| describe('loadConfig → mjs', async () => { | ||
| beforeEach(() => { | ||
| vi.restoreAllMocks(); | ||
| vi.resetModules(); | ||
|
|
||
| process.env.FORCE_COLOR = '1'; | ||
|
|
||
| const dotLogPath = require.resolve('@dot/log'); | ||
| const chalkPath = require.resolve('chalk', { paths: [dirname(dotLogPath)] }); | ||
|
|
||
| delete require.cache[dotLogPath]; | ||
| delete require.cache[chalkPath]; | ||
| require(chalkPath).level = 1; | ||
|
|
||
| delete (globalThis as any)[Symbol.for('jsx-email/global/config')]; | ||
| delete process.env.DOT_LOG_LEVEL; | ||
|
|
||
| for (const key of Object.keys(loglevelnext.loggers)) { | ||
| if (key === 'default') continue; | ||
| delete loglevelnext.loggers[key]; | ||
| } | ||
| }); | ||
|
Comment on lines
+9
to
+29
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There’s substantial repeated SuggestionExtract the repeated stabilization logic into a shared helper used by all config tests. Example: // test/helpers/reset-config-test-env.ts
export function resetConfigTestEnv() {
vi.restoreAllMocks();
vi.resetModules();
process.env.FORCE_COLOR = '1';
// …chalk/@dot/log cache reset…
// …global config + loglevelnext loggers reset…
}Then in each test file: import { resetConfigTestEnv } from '../helpers/reset-config-test-env';
beforeEach(resetConfigTestEnv);Reply with "@CharlieHelps yes please" if you'd like me to add a commit with this suggestion. |
||
|
|
||
| test('loadConfig', async () => { | ||
| const { loadConfig } = await import('../../../../src/config.js'); | ||
| const config = await loadConfig(__dirname); | ||
| expect(config).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { resolve } from 'node:path'; | ||
|
|
||
| import { execa } from 'execa'; | ||
| import strip from 'strip-ansi'; | ||
| import { describe, expect, test } from 'vitest'; | ||
|
|
||
| process.chdir(__dirname); | ||
|
|
||
| describe('cli', async () => { | ||
| test('email check supports --use-preview-props', async () => { | ||
| const templatePath = resolve(__dirname, './fixtures/check-preview-props.tsx'); | ||
|
|
||
| await expect( | ||
| execa({ cwd: __dirname, shell: true })`email check ${templatePath}` | ||
| ).rejects.toMatchObject({ | ||
| exitCode: 1 | ||
| }); | ||
|
|
||
| const { stdout } = await execa({ | ||
| cwd: __dirname, | ||
| shell: true | ||
| })`email check ${templatePath} --use-preview-props`; | ||
|
Comment on lines
+13
to
+22
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new test uses SuggestionAvoid await expect(execa('email', ['check', templatePath], { cwd: __dirname }))
.rejects.toMatchObject({ exitCode: 1 });
const { stdout } = await execa('email', ['check', templatePath, '--use-preview-props'], {
cwd: __dirname,
});Reply with "@CharlieHelps yes please" if you'd like me to add a commit with this suggestion.
Comment on lines
+7
to
+22
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This CLI test relies on It also depends on SuggestionPrefer running the CLI without a shell and avoid global const cwd = __dirname;
await expect(execa('email', ['check', templatePath], { cwd }))
.rejects.toMatchObject({ exitCode: 1 });
const { stdout } = await execa('email', ['check', templatePath, '--use-preview-props'], { cwd });and remove Reply with "@CharlieHelps yes please" if you’d like me to add a commit with this change. |
||
|
|
||
| const plain = strip(stdout); | ||
|
|
||
| expect(plain).toContain('Checking email template for Client Compatibility'); | ||
| expect(plain).toContain('Check Complete'); | ||
| expect(plain).not.toContain('noteLines'); | ||
| expect(plain).not.toContain('asshole'); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| interface PreviewProps { | ||
| label: string; | ||
| } | ||
|
|
||
| export const previewProps: PreviewProps = { | ||
| label: 'Preview props loaded' | ||
| }; | ||
|
|
||
| export const Template = ({ label }: PreviewProps) => <div>{label.toUpperCase()}</div>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatIssue()dereferencespositionwith non-null assertions (position!.start...). Ifcaniemailever yields an issue withoutposition,email checkwill crash while formatting output (i.e., during reporting, not during parsing). Given this is a CLI command, it’s better to degrade gracefully (e.g., show?:?) than throw.Also,
formatNotes()now returns a plain string while most other formatting useschalkTmpl; this is fine, but consider keeping the formatting approach consistent so future changes don’t accidentally double-escape/strip ANSI.Suggestion
Guard the
positionaccess and format a fallback location when it’s missing. For example:and use
locin the formatted line instead ofposition!.….Reply with "@CharlieHelps yes please" if you’d like me to add a commit with this change.