-
Notifications
You must be signed in to change notification settings - Fork 81
feat: add hmr and fix dev tests #199
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
07d286b
1fe802c
d146424
142144c
e7ae011
b692b9c
8ce6a67
65d2c75
a455b2d
7bfb8d5
61d3c31
3356052
124fba6
27e45bf
8a94c71
cd1858e
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,5 @@ | ||
| --- | ||
| "@workflow/sveltekit": patch | ||
| --- | ||
|
|
||
| Use hotUpdate for HMR in sveltekit |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@workflow/nitro": patch | ||
| --- | ||
|
|
||
| Add HMR to nitro integration |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| import fs from 'fs/promises'; | ||
| import path from 'path'; | ||
| import { afterEach, describe, expect, test } from 'vitest'; | ||
| import { getWorkbenchAppPath } from './utils'; | ||
|
|
||
| export interface DevTestConfig { | ||
| generatedStepPath: string; | ||
| generatedWorkflowPath: string; | ||
| apiFilePath: string; | ||
| apiFileImportPath: string; | ||
| /** The workflow file to modify for testing HMR. Defaults to '3_streams.ts' */ | ||
| testWorkflowFile?: string; | ||
| } | ||
|
|
||
| function getConfigFromEnv(): DevTestConfig | null { | ||
| const envConfig = process.env.DEV_TEST_CONFIG; | ||
| if (envConfig) { | ||
| try { | ||
| return JSON.parse(envConfig); | ||
| } catch (e) { | ||
| console.error('Failed to parse DEV_TEST_CONFIG:', e); | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| export function createDevTests(config?: DevTestConfig) { | ||
| const finalConfig = config || getConfigFromEnv(); | ||
| if (!finalConfig) { | ||
| throw new Error( | ||
| 'No dev test config provided via parameter or DEV_TEST_CONFIG env var' | ||
| ); | ||
| } | ||
| describe('dev e2e', () => { | ||
| const appPath = getWorkbenchAppPath(); | ||
| const generatedStep = path.join(appPath, finalConfig.generatedStepPath); | ||
| const generatedWorkflow = path.join( | ||
| appPath, | ||
| finalConfig.generatedWorkflowPath | ||
| ); | ||
| const testWorkflowFile = finalConfig.testWorkflowFile ?? '3_streams.ts'; | ||
| const restoreFiles: Array<{ path: string; content: string }> = []; | ||
|
|
||
| afterEach(async () => { | ||
| await Promise.all( | ||
| restoreFiles.map(async (item) => { | ||
| if (item.content === '') { | ||
| await fs.unlink(item.path); | ||
| } else { | ||
| await fs.writeFile(item.path, item.content); | ||
| } | ||
| }) | ||
| ); | ||
| restoreFiles.length = 0; | ||
| }); | ||
|
|
||
| test('should rebuild on workflow change', { timeout: 10_000 }, async () => { | ||
|
Check failure on line 57 in packages/core/e2e/dev.test.ts
|
||
| const workflowFile = path.join(appPath, 'workflows', testWorkflowFile); | ||
|
|
||
| const content = await fs.readFile(workflowFile, 'utf8'); | ||
|
|
||
| await fs.writeFile( | ||
| workflowFile, | ||
| `${content} | ||
|
|
||
| export async function myNewWorkflow() { | ||
| 'use workflow' | ||
| return 'hello world' | ||
| } | ||
| ` | ||
| ); | ||
| restoreFiles.push({ path: workflowFile, content }); | ||
|
|
||
| while (true) { | ||
| try { | ||
| const workflowContent = await fs.readFile(generatedWorkflow, 'utf8'); | ||
| expect(workflowContent).toContain('myNewWorkflow'); | ||
| break; | ||
| } catch (_) { | ||
| await new Promise((res) => setTimeout(res, 1_000)); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| test('should rebuild on step change', { timeout: 10_000 }, async () => { | ||
|
Check failure on line 85 in packages/core/e2e/dev.test.ts
|
||
| const stepFile = path.join(appPath, 'workflows', testWorkflowFile); | ||
|
|
||
| const content = await fs.readFile(stepFile, 'utf8'); | ||
|
|
||
| await fs.writeFile( | ||
| stepFile, | ||
| `${content} | ||
|
|
||
| export async function myNewStep() { | ||
| 'use step' | ||
| return 'hello world' | ||
| } | ||
| ` | ||
| ); | ||
| restoreFiles.push({ path: stepFile, content }); | ||
|
|
||
| while (true) { | ||
| try { | ||
| const workflowContent = await fs.readFile(generatedStep, 'utf8'); | ||
| expect(workflowContent).toContain('myNewStep'); | ||
| break; | ||
| } catch (_) { | ||
| await new Promise((res) => setTimeout(res, 1_000)); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| test( | ||
| 'should rebuild on adding workflow file', | ||
| { timeout: 10_000 }, | ||
| async () => { | ||
| const workflowFile = path.join(appPath, 'workflows', 'new-workflow.ts'); | ||
|
|
||
| await fs.writeFile( | ||
| workflowFile, | ||
| `export async function newWorkflowFile() { | ||
| 'use workflow' | ||
| return 'hello world' | ||
| } | ||
| ` | ||
| ); | ||
| restoreFiles.push({ path: workflowFile, content: '' }); | ||
| const apiFile = path.join(appPath, finalConfig.apiFilePath); | ||
|
|
||
| const apiFileContent = await fs.readFile(apiFile, 'utf8'); | ||
| restoreFiles.push({ path: apiFile, content: apiFileContent }); | ||
|
|
||
| await fs.writeFile( | ||
| apiFile, | ||
| `import '${finalConfig.apiFileImportPath}/workflows/new-workflow'; | ||
| ${apiFileContent}` | ||
| ); | ||
|
|
||
| while (true) { | ||
| try { | ||
| const workflowContent = await fs.readFile( | ||
| generatedWorkflow, | ||
| 'utf8' | ||
| ); | ||
| expect(workflowContent).toContain('newWorkflowFile'); | ||
| break; | ||
| } catch (_) { | ||
| await new Promise((res) => setTimeout(res, 1_000)); | ||
| } | ||
| } | ||
| } | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| // Run tests with environment-based config if this file is executed directly | ||
| if (process.env.DEV_TEST_CONFIG) { | ||
| createDevTests(); | ||
| } | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.