From fa42b1cce6798fc9fdec588cb5457772e1d31490 Mon Sep 17 00:00:00 2001 From: George He Date: Tue, 3 Sep 2024 16:34:44 +0800 Subject: [PATCH] fix: flaky git test (#7883) --- .../tests/smoke/git-interactions.test.ts | 203 +++++++++--------- 1 file changed, 100 insertions(+), 103 deletions(-) diff --git a/packages/insomnia-smoke-test/tests/smoke/git-interactions.test.ts b/packages/insomnia-smoke-test/tests/smoke/git-interactions.test.ts index 4126e0eff7..089c120f76 100644 --- a/packages/insomnia-smoke-test/tests/smoke/git-interactions.test.ts +++ b/packages/insomnia-smoke-test/tests/smoke/git-interactions.test.ts @@ -1,114 +1,111 @@ -// import { test } from '../../playwright/test'; +import { test } from '../../playwright/test'; -// test('Git Interactions (clone, checkout branch, pull, push, stage changes, ...)', async ({ page }) => { -// const gitSyncSmokeTestToken = process.env.GIT_SYNC_SMOKE_TEST_TOKEN; +test('Git Interactions (clone, checkout branch, pull, push, stage changes, ...)', async ({ page }) => { + const gitSyncSmokeTestToken = process.env.GIT_SYNC_SMOKE_TEST_TOKEN; + test.setTimeout(60000); -// // read env variable to skip test -// if (!gitSyncSmokeTestToken) { -// console.log('Skipping, set GIT_SYNC_SMOKE_TEST_TOKEN to run, TIP: "gh auth login to get a token" and "export GIT_SYNC_SMOKE_TEST_TOKEN=$(gh auth token)"'); -// test.skip(); -// return; -// } + // read env variable to skip test + if (!gitSyncSmokeTestToken) { + console.log('Skipping, set GIT_SYNC_SMOKE_TEST_TOKEN to run, TIP: "gh auth login to get a token" and "export GIT_SYNC_SMOKE_TEST_TOKEN=$(gh auth token)"'); + test.skip(); + return; + } -// // generate a uuid string -// const testUUID = crypto.randomUUID(); + // generate a uuid string + const testUUID = crypto.randomUUID(); -// // git clone -// await page.waitForSelector('[data-test-git-enable="true"]'); -// await page.getByLabel('Clone git repository').click(); -// await page.getByRole('tab', { name: ' Git' }).click(); -// await page.getByPlaceholder('https://github.com/org/repo.git').fill('https://github.com/Kong/insomnia-git-example.git'); -// await page.getByPlaceholder('Name').fill('Test User'); -// await page.getByPlaceholder('Email').fill('test@test.com'); -// await page.getByPlaceholder('MyUser').fill('test'); -// await page.getByPlaceholder('88e7ee63b254e4b0bf047559eafe86ba9dd49507').fill(gitSyncSmokeTestToken); -// await page.getByTestId('git-repository-settings-modal__sync-btn').click(); -// // await page.waitForTimeout(5000); -// await page.getByLabel('Toggle preview').click(); + // git clone + await page.waitForSelector('[data-test-git-enable="true"]'); + await page.getByLabel('Clone git repository').click(); + await page.getByRole('tab', { name: ' Git' }).click(); + await page.getByPlaceholder('https://github.com/org/repo.git').fill('https://github.com/Kong/insomnia-git-example.git'); + await page.getByPlaceholder('Name').fill('Test User'); + await page.getByPlaceholder('Email').fill('test@test.com'); + await page.getByPlaceholder('MyUser').fill('test'); + await page.getByPlaceholder('88e7ee63b254e4b0bf047559eafe86ba9dd49507').fill(gitSyncSmokeTestToken); + await page.getByTestId('git-repository-settings-modal__sync-btn').click(); + await page.getByLabel('Toggle preview').click(); -// // switch branches -// await page.waitForTimeout(5000); -// // await page.waitForTimeout(60000000); -// await page.getByTestId('git-dropdown').click(); -// // await page.getByRole('button', { name: ' Branches' }).click(); -// await page.getByText('Branches').click(); -// await page.getByRole('cell', { name: 'main(current)' }).click(); -// await page.getByRole('cell', { name: 'abc' }).click(); -// await page.getByRole('row', { name: 'abc Checkout' }).getByRole('button').click(); -// await page.getByRole('cell', { name: 'abc(current)' }).click(); -// await page.getByRole('button', { name: 'Done' }).click(); + // switch branches + await page.getByTestId('git-dropdown').click(); + await page.getByText('Branches').click(); + await page.getByRole('cell', { name: 'main(current)' }).click(); + await page.getByRole('cell', { name: 'abc' }).click(); + await page.getByRole('row', { name: 'abc Checkout' }).getByRole('button').click(); + await page.getByRole('cell', { name: 'abc(current)' }).click(); + await page.getByRole('button', { name: 'Done' }).click(); -// // perform some changes and commit them -// await page.locator('pre').filter({ hasText: 'title: Endpoint Security' }).click(); -// await page.getByRole('textbox').fill(' test'); -// await page.getByTestId('git-dropdown').getByLabel('Git Sync').click(); -// await page.getByRole('button', { name: ' Commit' }).click(); -// await page.getByText('Modified Objects').click(); -// await page.getByText('ApiSpec').click(); -// await page.getByPlaceholder('A descriptive message to').click(); -// await page.getByPlaceholder('A descriptive message to').fill('example commit message'); -// await page.getByRole('dialog').getByText('abc').click(); -// await page.getByRole('button', { name: ' Commit' }).click(); -// await page.getByText('No changes to commit.').click(); -// await page.getByRole('button', { name: 'Close' }).click(); + // perform some changes and commit them + await page.locator('pre').filter({ hasText: 'title: Endpoint Security' }).click(); + await page.getByRole('textbox').fill(' test'); + await page.getByTestId('git-dropdown').click(); + await page.getByText('Commit').click(); + await page.getByText('Modified Objects').click(); + await page.getByText('ApiSpec').click(); + await page.getByPlaceholder('A descriptive message to').click(); + await page.getByPlaceholder('A descriptive message to').fill('example commit message'); + await page.getByRole('dialog').getByText('abc').click(); + await page.getByRole('button', { name: ' Commit' }).click(); + await page.getByText('No changes to commit.').click(); + await page.getByRole('button', { name: 'Close' }).click(); -// // switch back to main branch, which should not have said changes -// await page.getByTestId('git-dropdown').getByLabel('Git Sync').click(); -// await page.getByRole('button', { name: 'main' }).click(); -// await page.getByTestId('git-dropdown').getByLabel('Git Sync').click(); -// await page.getByRole('button', { name: ' Branches' }).click(); -// await page.getByRole('cell', { name: 'main(current)' }).click(); -// await page.getByRole('button', { name: 'Done' }).click(); -// await page.getByTestId('CodeEditor').getByText('Endpoint Security').click(); + // switch back to main branch, which should not have said changes + await page.getByTestId('git-dropdown').click(); + await page.getByText('main').click(); + await page.getByTestId('git-dropdown').click(); + await page.getByText('Branches').click(); + await page.getByRole('cell', { name: 'main(current)' }).click(); + await page.getByRole('button', { name: 'Done' }).click(); + await page.getByTestId('CodeEditor').getByText('Endpoint Security').click(); -// // switch to the branch with the changes and check if they are there -// await page.getByTestId('git-dropdown').getByLabel('Git Sync').click(); -// await page.getByRole('button', { name: 'abc' }).click(); -// await page.getByTestId('git-dropdown').getByLabel('Git Sync').click(); -// await page.getByRole('button', { name: ' Branches' }).click(); -// await page.getByRole('cell', { name: 'abc(current)' }).click(); -// await page.getByRole('button', { name: 'Done' }).click(); -// await page.getByText('Endpoint Security test').click(); + // switch to the branch with the changes and check if they are there + await page.getByTestId('git-dropdown').click(); + await page.getByText('abc').click(); + await page.getByTestId('git-dropdown').click(); + await page.getByText('Branches').click(); + await page.getByRole('cell', { name: 'abc(current)' }).click(); + await page.getByRole('button', { name: 'Done' }).click(); + await page.getByText('Endpoint Security test').click(); -// // check git history -// await page.getByTestId('git-dropdown').getByLabel('Git Sync').click(); -// await page.getByRole('button', { name: ' Fetch' }).click(); -// await page.getByTestId('git-dropdown').getByLabel('Git Sync').click(); -// await page.getByRole('button', { name: ' History' }).click(); -// await page.getByRole('cell', { name: 'example commit message' }).click(); -// await page.getByRole('cell', { name: 'just now' }).click(); -// await page.getByRole('button', { name: 'Done' }).click(); + // check git history + await page.getByTestId('git-dropdown').click(); + await page.getByText('Fetch').click(); -// // push changes test -// await page.getByTestId('git-dropdown').getByLabel('Git Sync').click(); -// await page.getByRole('button', { name: ' Branches' }).click(); -// await page.getByRole('cell', { name: 'abc(current)' }).click(); -// await page.getByRole('cell', { name: 'push-pull-test' }).click(); -// await page.getByRole('row', { name: 'push-pull-test Checkout' }).getByRole('button').click(); -// await page.getByRole('cell', { name: 'push-pull-test(current)' }).click(); -// await page.getByRole('button', { name: 'Done' }).click(); -// await page.getByTestId('workspace-debug').click(); -// await page.getByLabel('Create in collection').click(); -// await page.getByLabel('New Folder').click(); -// await page.getByLabel('Name', { exact: true }).click(); -// await page.getByLabel('Name', { exact: true }).fill(`My Folder ${testUUID}`); -// await page.getByRole('button', { name: 'Create', exact: true }).click(); -// await page.getByTestId('git-dropdown').getByLabel('Git Sync').click(); -// await page.getByRole('button', { name: ' Commit' }).click(); -// await page.getByRole('cell', { name: `My Folder ${testUUID}` }).locator('label').click(); -// await page.getByPlaceholder('A descriptive message to').click(); -// await page.getByPlaceholder('A descriptive message to').fill(`commit test ${testUUID}`); -// await page.getByText('Commit Changes').click(); -// await page.getByRole('button', { name: ' Commit' }).click(); -// await page.getByText('No changes to commit.').click(); -// await page.getByRole('button', { name: 'Close' }).click(); -// await page.getByTestId('git-dropdown').getByLabel('Git Sync').click(); -// await page.getByRole('button', { name: ' Push' }).click(); -// await page.getByTestId('git-dropdown').getByLabel('Git Sync').click(); -// await page.getByRole('button', { name: ' Fetch' }).click(); -// await page.getByTestId('git-dropdown').getByLabel('Git Sync').click(); -// await page.getByRole('button', { name: ' History' }).click(); -// await page.getByRole('cell', { name: `commit test ${testUUID}` }).click(); -// await page.getByRole('button', { name: 'Done' }).click(); + await page.getByTestId('git-dropdown').click(); + await page.getByText('History').click(); + await page.getByRole('cell', { name: 'example commit message' }).click(); + await page.getByRole('cell', { name: 'just now' }).click(); + await page.getByRole('button', { name: 'Done' }).click(); -// }); + // push changes test + await page.getByTestId('git-dropdown').click(); + await page.getByText('Branches').click(); + await page.getByRole('cell', { name: 'abc(current)' }).click(); + await page.getByRole('cell', { name: 'push-pull-test' }).click(); + await page.getByRole('row', { name: 'push-pull-test Checkout' }).getByRole('button').click(); + await page.getByRole('cell', { name: 'push-pull-test(current)' }).click(); + await page.getByRole('button', { name: 'Done' }).click(); + await page.getByTestId('workspace-debug').click(); + await page.getByLabel('Create in collection').click(); + await page.getByLabel('New Folder').click(); + await page.getByLabel('Name', { exact: true }).click(); + await page.getByLabel('Name', { exact: true }).fill(`My Folder ${testUUID}`); + await page.getByRole('button', { name: 'Create', exact: true }).click(); + await page.getByTestId('git-dropdown').click(); + await page.getByText('Commit').click(); + await page.getByRole('cell', { name: `My Folder ${testUUID}` }).locator('label').click(); + await page.getByPlaceholder('A descriptive message to').click(); + await page.getByPlaceholder('A descriptive message to').fill(`commit test ${testUUID}`); + await page.getByText('Commit Changes').click(); + await page.getByRole('button', { name: ' Commit' }).click(); + await page.getByText('No changes to commit.').click(); + await page.getByRole('button', { name: 'Close' }).click(); + await page.getByTestId('git-dropdown').click(); + await page.getByText('Push', { exact: true }).click(); + await page.getByTestId('git-dropdown').click(); + await page.getByText('Fetch').click(); + await page.getByTestId('git-dropdown').click(); + await page.getByText('History').click(); + await page.getByRole('cell', { name: `commit test ${testUUID}` }).click(); + await page.getByRole('button', { name: 'Done' }).click(); +});