-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cherry-pick(#35062): do not compute git diff on non! PRs
- Loading branch information
1 parent
12835d6
commit 9e9f0d1
Showing
8 changed files
with
129 additions
and
68 deletions.
There are no files selected for viewing
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
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
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
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
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
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 |
---|---|---|
|
@@ -1232,10 +1232,7 @@ for (const useIntermediateMergeReport of [true, false] as const) { | |
|
||
const result = await runInlineTest(files, { reporter: 'dot,html' }, { | ||
PLAYWRIGHT_HTML_OPEN: 'never', | ||
GITHUB_ACTIONS: '1', | ||
GITHUB_REPOSITORY: 'microsoft/playwright-example-for-test', | ||
GITHUB_SERVER_URL: 'https://playwright.dev', | ||
GITHUB_SHA: 'example-sha', | ||
...ghaCommitEnv(), | ||
}); | ||
|
||
await showReport(); | ||
|
@@ -1262,23 +1259,9 @@ for (const useIntermediateMergeReport of [true, false] as const) { | |
const baseDir = await writeFiles(files); | ||
await initGitRepo(baseDir); | ||
|
||
const eventPath = path.join(baseDir, 'event.json'); | ||
await fs.promises.writeFile(eventPath, JSON.stringify({ | ||
pull_request: { | ||
title: 'My PR', | ||
number: 42, | ||
base: { ref: 'main' }, | ||
}, | ||
})); | ||
|
||
const result = await runInlineTest(files, { reporter: 'dot,html' }, { | ||
PLAYWRIGHT_HTML_OPEN: 'never', | ||
GITHUB_ACTIONS: '1', | ||
GITHUB_REPOSITORY: 'microsoft/playwright-example-for-test', | ||
GITHUB_RUN_ID: 'example-run-id', | ||
GITHUB_SERVER_URL: 'https://playwright.dev', | ||
GITHUB_SHA: 'example-sha', | ||
GITHUB_EVENT_PATH: eventPath, | ||
...(await ghaPullRequestEnv(baseDir)) | ||
}); | ||
|
||
await showReport(); | ||
|
@@ -2746,31 +2729,34 @@ for (const useIntermediateMergeReport of [true, false] as const) { | |
await expect(page.locator('.tree-item', { hasText: 'stdout' })).toHaveCount(1); | ||
}); | ||
|
||
test('should show AI prompt', async ({ runInlineTest, writeFiles, showReport, page }) => { | ||
test('should include diff in AI prompt', async ({ runInlineTest, writeFiles, showReport, page }) => { | ||
const files = { | ||
'uncommitted.txt': `uncommitted file`, | ||
'playwright.config.ts': `export default {}`, | ||
'example.spec.ts': ` | ||
import { test, expect } from '@playwright/test'; | ||
test('sample', async ({ page }) => { | ||
await page.setContent('<button>Click me</button>'); | ||
expect(2).toBe(3); | ||
expect(2).toBe(2); | ||
}); | ||
`, | ||
}; | ||
const baseDir = await writeFiles(files); | ||
await initGitRepo(baseDir); | ||
await writeFiles({ | ||
'example.spec.ts': ` | ||
import { test, expect } from '@playwright/test'; | ||
test('sample', async ({ page }) => { | ||
await page.setContent('<button>Click me</button>'); | ||
expect(2).toBe(3); | ||
});` | ||
}); | ||
await execGit(baseDir, ['checkout', '-b', 'pr_branch']); | ||
await execGit(baseDir, ['commit', '-am', 'changes']); | ||
|
||
const result = await runInlineTest(files, { reporter: 'dot,html' }, { | ||
const result = await runInlineTest({}, { reporter: 'dot,html' }, { | ||
PLAYWRIGHT_HTML_OPEN: 'never', | ||
GITHUB_ACTIONS: '1', | ||
GITHUB_REPOSITORY: 'microsoft/playwright-example-for-test', | ||
GITHUB_RUN_ID: 'example-run-id', | ||
GITHUB_SERVER_URL: 'https://playwright.dev', | ||
GITHUB_SHA: 'example-sha', | ||
GITHUB_REF_NAME: '42/merge', | ||
GITHUB_BASE_REF: 'HEAD~1', | ||
PLAYWRIGHT_COPY_PROMPT: '1', | ||
...(await ghaPullRequestEnv(baseDir)), | ||
}); | ||
|
||
expect(result.exitCode).toBe(1); | ||
|
@@ -2786,6 +2772,24 @@ for (const useIntermediateMergeReport of [true, false] as const) { | |
expect(prompt, 'contains snapshot').toContain('- button "Click me"'); | ||
expect(prompt, 'contains diff').toContain(`+ expect(2).toBe(3);`); | ||
}); | ||
|
||
test('should not show prompt for empty timeout error', async ({ runInlineTest, showReport, page }) => { | ||
const result = await runInlineTest({ | ||
'uncommitted.txt': `uncommitted file`, | ||
'playwright.config.ts': `export default {}`, | ||
'example.spec.ts': ` | ||
import { test, expect } from '@playwright/test'; | ||
test('sample', async ({ page }) => { | ||
test.setTimeout(2000); | ||
await page.setChecked('input', true); | ||
}); | ||
`, | ||
}, { reporter: 'dot,html' }, { PLAYWRIGHT_HTML_OPEN: 'never' }); | ||
expect(result.exitCode).toBe(1); | ||
await showReport(); | ||
await page.getByRole('link', { name: 'sample' }).click(); | ||
await expect(page.getByRole('button', { name: 'Copy prompt' })).toHaveCount(1); | ||
}); | ||
}); | ||
} | ||
|
||
|
@@ -2797,19 +2801,45 @@ function readAllFromStream(stream: NodeJS.ReadableStream): Promise<Buffer> { | |
}); | ||
} | ||
|
||
async function initGitRepo(baseDir) { | ||
const execGit = async (args: string[]) => { | ||
const { code, stdout, stderr } = await spawnAsync('git', args, { stdio: 'pipe', cwd: baseDir }); | ||
if (!!code) | ||
throw new Error(`Non-zero exit of:\n$ git ${args.join(' ')}\nConsole:\nstdout:\n${stdout}\n\nstderr:\n${stderr}\n\n`); | ||
return; | ||
async function execGit(baseDir: string, args: string[]) { | ||
const { code, stdout, stderr } = await spawnAsync('git', args, { stdio: 'pipe', cwd: baseDir }); | ||
if (!!code) | ||
throw new Error(`Non-zero exit of:\n$ git ${args.join(' ')}\nConsole:\nstdout:\n${stdout}\n\nstderr:\n${stderr}\n\n`); | ||
return; | ||
} | ||
|
||
async function initGitRepo(baseDir: string) { | ||
await execGit(baseDir, ['init']); | ||
await execGit(baseDir, ['config', '--local', 'user.email', '[email protected]']); | ||
await execGit(baseDir, ['config', '--local', 'user.name', 'William']); | ||
await execGit(baseDir, ['checkout', '-b', 'main']); | ||
await execGit(baseDir, ['add', 'playwright.config.ts']); | ||
await execGit(baseDir, ['commit', '-m', 'init']); | ||
await execGit(baseDir, ['add', '*.ts']); | ||
await execGit(baseDir, ['commit', '-m', 'chore(html): make this test look nice']); | ||
} | ||
|
||
function ghaCommitEnv() { | ||
return { | ||
GITHUB_ACTIONS: '1', | ||
GITHUB_REPOSITORY: 'microsoft/playwright-example-for-test', | ||
GITHUB_SERVER_URL: 'https://playwright.dev', | ||
GITHUB_SHA: 'example-sha', | ||
}; | ||
} | ||
|
||
await execGit(['init']); | ||
await execGit(['config', '--local', 'user.email', '[email protected]']); | ||
await execGit(['config', '--local', 'user.name', 'William']); | ||
await execGit(['add', 'playwright.config.ts']); | ||
await execGit(['commit', '-m', 'init']); | ||
await execGit(['add', '*.ts']); | ||
await execGit(['commit', '-m', 'chore(html): make this test look nice']); | ||
async function ghaPullRequestEnv(baseDir: string) { | ||
const eventPath = path.join(baseDir, 'event.json'); | ||
await fs.promises.writeFile(eventPath, JSON.stringify({ | ||
pull_request: { | ||
title: 'My PR', | ||
number: 42, | ||
base: { sha: 'main' }, | ||
}, | ||
})); | ||
return { | ||
...ghaCommitEnv(), | ||
GITHUB_RUN_ID: 'example-run-id', | ||
GITHUB_EVENT_PATH: eventPath, | ||
}; | ||
} |
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
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