-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add test app and component to check all platform features #9
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,74 @@ | ||
| import { Command } from 'commander'; | ||
| import { resolve } from 'node:path'; | ||
| import { existsSync, rmSync, mkdirSync } from 'node:fs'; | ||
| import { spawnSync } from 'node:child_process'; | ||
|
|
||
| export const createTestsCommand = new Command('create-tests') | ||
| .argument( | ||
| '<directory>', | ||
| 'Parent directory for both projects (required to prevent accidental deletion)', | ||
| ) | ||
| .option('--app-name <name>', 'Name of the test app project', 'test-app') | ||
| .option( | ||
| '--component-name <name>', | ||
| 'Name of the test component project', | ||
| 'test-component', | ||
| ) | ||
| .description( | ||
| 'Scaffold both a test app (--template test) and a test cloud component (--template cloud-test)', | ||
| ) | ||
| .action( | ||
| async ( | ||
| directory: string, | ||
| opts: { appName: string; componentName: string }, | ||
| ) => { | ||
| const parentDir = resolve(process.cwd(), directory); | ||
| const bin = process.argv[1]; // path to the thatopen CLI entry point | ||
|
|
||
| // Clean up previous test suite if it exists | ||
| if (existsSync(parentDir)) { | ||
| console.log(`Removing existing directory "${directory}"...`); | ||
| rmSync(parentDir, { recursive: true, force: true }); | ||
| } | ||
| mkdirSync(parentDir, { recursive: true }); | ||
|
|
||
| console.log('Creating test suite...'); | ||
| console.log(''); | ||
|
|
||
| // 1 ── Test App | ||
| console.log(`── Creating test app "${opts.appName}" ──`); | ||
| const appResult = spawnSync( | ||
| process.execPath, | ||
| [bin, 'create', opts.appName, '-t', 'test'], | ||
| { cwd: parentDir, stdio: 'inherit' }, | ||
| ); | ||
| if (appResult.status !== 0) { | ||
| process.exit(appResult.status ?? 1); | ||
| } | ||
|
|
||
| console.log(''); | ||
|
|
||
| // 2 ── Test Cloud Component | ||
| console.log(`── Creating test component "${opts.componentName}" ──`); | ||
| const compResult = spawnSync( | ||
| process.execPath, | ||
| [bin, 'create', opts.componentName, '-t', 'cloud-test'], | ||
| { cwd: parentDir, stdio: 'inherit' }, | ||
| ); | ||
| if (compResult.status !== 0) { | ||
| process.exit(compResult.status ?? 1); | ||
| } | ||
|
|
||
| console.log(''); | ||
| console.log('Test suite ready!'); | ||
| console.log(''); | ||
| console.log('Quick start:'); | ||
| console.log( | ||
| ` 1. cd ${opts.componentName} && npm run run # Run the test component locally`, | ||
| ); | ||
| console.log( | ||
| ` 2. cd ${opts.appName} && npm run dev # Start the test app`, | ||
| ); | ||
| console.log(''); | ||
| }, | ||
| ); | ||
This file contains hidden or 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
This file contains hidden or 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,96 @@ | ||
| import { Command } from 'commander'; | ||
| import { resolve } from 'node:path'; | ||
| import { spawn } from 'node:child_process'; | ||
|
|
||
| export const serveTestsCommand = new Command('serve-tests') | ||
| .argument( | ||
| '<directory>', | ||
| 'Parent directory containing both projects', | ||
| ) | ||
| .option('--app-name <name>', 'Name of the test app project', 'test-app') | ||
| .option( | ||
| '--component-name <name>', | ||
| 'Name of the test component project', | ||
| 'test-component', | ||
| ) | ||
| .option('--app-port <port>', 'Port for the app bundle server', '4000') | ||
| .option('--component-port <port>', 'Port for the component local server', '4001') | ||
| .description( | ||
| 'Serve both the test app (thatopen serve) and the test component (thatopen local-server) in parallel', | ||
| ) | ||
| .action( | ||
| async ( | ||
| directory: string, | ||
| opts: { | ||
| appName: string; | ||
| componentName: string; | ||
| appPort: string; | ||
| componentPort: string; | ||
| }, | ||
| ) => { | ||
| const parentDir = resolve(process.cwd(), directory); | ||
| const bin = process.argv[1]; | ||
|
|
||
| const appDir = resolve(parentDir, opts.appName); | ||
| const componentDir = resolve(parentDir, opts.componentName); | ||
|
|
||
| console.log('Starting test suite servers...'); | ||
| console.log(''); | ||
|
|
||
| const children: ReturnType<typeof spawn>[] = []; | ||
|
|
||
| // Helper: spawn a child with prefixed stdout/stderr | ||
| function startProcess( | ||
| label: string, | ||
| cwd: string, | ||
| args: string[], | ||
| ) { | ||
| const child = spawn(process.execPath, [bin, ...args], { | ||
| cwd, | ||
| stdio: ['ignore', 'pipe', 'pipe'], | ||
| }); | ||
|
|
||
| const prefix = `[${label}]`; | ||
|
|
||
| child.stdout.on('data', (data: Buffer) => { | ||
| for (const line of data.toString().split('\n')) { | ||
| if (line) console.log(`${prefix} ${line}`); | ||
| } | ||
| }); | ||
|
|
||
| child.stderr.on('data', (data: Buffer) => { | ||
| for (const line of data.toString().split('\n')) { | ||
| if (line) console.error(`${prefix} ${line}`); | ||
| } | ||
| }); | ||
|
|
||
| child.on('exit', (code) => { | ||
| console.log(`${prefix} exited with code ${code}`); | ||
| }); | ||
|
|
||
| children.push(child); | ||
| } | ||
|
|
||
| // 1 — Component local-server (start first so it's ready when the app connects) | ||
| startProcess('component', componentDir, [ | ||
| 'local-server', | ||
| '--port', | ||
| opts.componentPort, | ||
| ]); | ||
|
|
||
| // 2 — App serve | ||
| startProcess('app', appDir, ['serve', '--port', opts.appPort]); | ||
|
|
||
| console.log(`[component] ${componentDir} → http://localhost:${opts.componentPort}`); | ||
| console.log(`[app] ${appDir} → http://localhost:${opts.appPort}`); | ||
| console.log(''); | ||
|
|
||
| // Forward SIGINT to children | ||
| process.on('SIGINT', () => { | ||
| for (const child of children) { | ||
| child.kill('SIGINT'); | ||
| } | ||
| setTimeout(() => process.exit(0), 500); | ||
| }); | ||
| }, | ||
| ); |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Suggestion: I believe if someone calls
thatopen create-testswithout any arguments in their repo root this would nuke the repository. Deleting the subdirectories only could be safer in this case or we could force the argument to make it a bit safer.