-
Notifications
You must be signed in to change notification settings - Fork 53
fix(jsx-email): port preview deploy and asset-path fixes #387
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
base: next/v3
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { access, readFile, rm } from 'node:fs/promises'; | ||
| import os from 'node:os'; | ||
| import { join, resolve } from 'node:path'; | ||
|
|
||
| import { execa } from 'execa'; | ||
|
|
||
| describe('cli: preview --build-path', async () => { | ||
| const outRelational = './.test/build-path'; | ||
| const outAbsolute = resolve(__dirname, outRelational); | ||
| const templatePath = './.test/.deploy/emails'; | ||
| const isWindows = os.platform() === 'win32'; | ||
|
|
||
| beforeAll(async () => { | ||
| await rm(outAbsolute, { force: true, recursive: true }); | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| await rm(outAbsolute, { force: true, recursive: true }); | ||
| }); | ||
|
|
||
| if (!isWindows) { | ||
| test('relative build path writes to an absolute path derived from the original cwd', async () => { | ||
| await execa({ cwd: __dirname, shell: true })`email create BatmanEmail --out ${templatePath} `; | ||
| const { stdout } = await execa({ | ||
| cwd: __dirname, | ||
| shell: true | ||
| })`email preview ${templatePath} --build-path ${outRelational}`; | ||
|
|
||
| console.log(stdout); | ||
|
|
||
| await access(join(outAbsolute, 'index.html')); | ||
|
|
||
| const html = await readFile(join(outAbsolute, 'index.html'), 'utf8'); | ||
| expect(html).toContain('<div id="root"></div>'); | ||
| }, 60e3); | ||
|
Comment on lines
+21
to
+35
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 non-Windows test invokes It would be more robust to:
This is especially important because you set a long timeout (60s) and use SuggestionHarden the test to avoid hanging on long-running preview processes. If Example: const res = await execa({ cwd: __dirname, shell: true })
`email preview ${templatePath} --build-path ${outRelational} --no-open`;
expect(res.exitCode).toBe(0);If there is a dedicated build-only option (e.g. Reply with "@CharlieHelps yes please" if you'd like me to add a commit with this suggestion. |
||
| } | ||
|
|
||
| if (isWindows) { | ||
| test('errors when Vite root and temp build path are on different drives (Windows)', async () => { | ||
| await execa({ cwd: __dirname, shell: true })`email create BatmanEmail --out ${templatePath} `; | ||
| await expect( | ||
| execa({ | ||
| cwd: __dirname, | ||
| shell: true | ||
| })`email preview ${templatePath} --build-path ${outRelational}` | ||
| ).rejects.toThrow( | ||
| /Temporary directory drive letter different than root directory drive letter/ | ||
| ); | ||
| }, 60e3); | ||
| } | ||
|
Comment on lines
+38
to
+50
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 Windows branch expects a drive-letter mismatch error when running If the intent is to validate the cross-drive failure mode, the test should either (a) simulate differing drives by controlling the temp directory location, or (b) unit-test the drive-letter guard logic with injected paths. As-is, this can be flaky or always-skip the real mismatch condition depending on environment. SuggestionMake the Windows test deterministic by decoupling it from the machine’s actual temp-drive layout. Options:
export const assertSameDriveOnWindows = (root: string, tempDir: string) => {
// ... throw AssertionError ...
};Then in CLI tests, validate the integration path uses the temp dir.
Reply with "@CharlieHelps yes please" if you’d like me to add a commit that refactors the guard for deterministic testing and updates this test accordingly. |
||
| }); | ||
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.
This test suite uses
describe(..., async () => { ... }). In Vitest/Jest-style runners,describecallbacks are expected to be synchronous; returning a Promise can lead to subtle scheduling issues and hooks not registering as expected.Additionally, the test has a
console.log(stdout)which will add noise to CI output and can hide real failures.Finally, the
email create ...step writes intotemplatePath, but the cleanup only removesoutAbsolute. If the test runs multiple times (or on failure),.test/.deploymay accumulate files and create flakiness.Suggestion
Make the
describecallback synchronous, removeconsole.log, and clean up the template output directory as well.Reply with "@CharlieHelps yes please" if you'd like me to add a commit with this suggestion.