-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add UI tests to
create fuels
template (#3104)
* feat: add ui testing to `create-fuels` template * add changeset * fix changeset * add to nextjs template too * update changeset * restructure folders * update some paths * add to docs * Update pnpm-lock.yaml * Update tests-validate.sh * update path in test * update other tests too * fix tests-validate.sh * revert contract-ids.json * update test file path * use `webServer` to start servers * add comment * move tests from e2e to integration * rename npm scripts * remove playwright-report --------- Co-authored-by: Chad Nehemiah <chad.nehemiah94@gmail.com>
- Loading branch information
Showing
32 changed files
with
345 additions
and
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"create-fuels": patch | ||
--- | ||
|
||
feat: add UI tests to `create fuels` template |
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 |
---|---|---|
|
@@ -31,4 +31,7 @@ src/sway-api/scripts | |
src/sway-api/index.ts | ||
|
||
sway-programs/**/out | ||
.turbo | ||
.turbo | ||
|
||
playwright-report | ||
test-results |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { defineConfig, devices } from '@playwright/test'; | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
testDir: './test/ui', | ||
/* Run tests in files in parallel */ | ||
fullyParallel: true, | ||
/* Fail the build on CI if you accidentally left test.only in the source code. */ | ||
forbidOnly: !!process.env.CI, | ||
/* Retry on CI only */ | ||
retries: process.env.CI ? 2 : 0, | ||
/* Opt out of parallel tests on CI. */ | ||
workers: process.env.CI ? 1 : undefined, | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: [['html', { open: 'never' }]], | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: 'on-first-retry', | ||
}, | ||
timeout: 60000, | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { ...devices['Desktop Chrome'] }, | ||
}, | ||
], | ||
webServer: [ | ||
{ | ||
command: 'pnpm run original:dev', | ||
port: 5173, | ||
reuseExistingServer: !process.env.CI, | ||
}, | ||
{ | ||
command: 'pnpm run fuels:dev', | ||
port: 4000, | ||
reuseExistingServer: !process.env.CI, | ||
} | ||
] | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
# This script installs the necessary dependencies for the UI tests and runs them. | ||
|
||
pnpm exec playwright install --with-deps > /dev/null 2>&1 | ||
pnpm exec playwright test | ||
TEST_RESULT=$? | ||
|
||
exit $TEST_RESULT |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { test, expect } from '@playwright/test'; | ||
|
||
const WEB_SERVER_URL = 'http://localhost:5173'; | ||
|
||
test.extend({ | ||
page: async ({ page }, use) => { | ||
await page.evaluate(() => window.localStorage.clear()); | ||
await use(page); | ||
}, | ||
}); | ||
|
||
test('counter contract - increment function call works properly', async ({ page }) => { | ||
await page.goto(WEB_SERVER_URL, { waitUntil: 'networkidle' }); | ||
|
||
await page.waitForTimeout(2000); | ||
|
||
const topUpWalletButton = page.getByText('Top-up Wallet'); | ||
await topUpWalletButton.click(); | ||
|
||
await page.waitForTimeout(2000); | ||
|
||
const initialCounterValue = +(page.getByTestId('counter').textContent); | ||
|
||
const incrementButton = page.getByText('Increment Counter'); | ||
await incrementButton.click(); | ||
|
||
await page.waitForTimeout(2000); | ||
|
||
const counterValueAfterIncrement = +(page.getByTestId('counter').textContent); | ||
expect(+(counterValueAfterIncrement)).toEqual(+initialCounterValue + 1); | ||
}); | ||
|
||
// #region decrement-counter-ui-test | ||
test('counter contract - decrement function call works properly', async ({ page }) => { | ||
await page.goto(WEB_SERVER_URL, { waitUntil: 'networkidle' }); | ||
|
||
await page.waitForTimeout(2000); // These timeouts are needed to ensure that we wait for transactions to be mined | ||
|
||
const topUpWalletButton = page.getByText('Top-up Wallet'); | ||
await topUpWalletButton.click(); | ||
|
||
await page.waitForTimeout(2000); | ||
|
||
const initialCounterValue = +(page.getByTestId('counter').textContent); | ||
|
||
const decrementButton = page.getByText('Decrement Counter'); | ||
await decrementButton.click(); | ||
|
||
await page.waitForTimeout(2000); | ||
|
||
const counterValueAfterDecrement = +(page.getByTestId('counter').textContent); | ||
expect(+(counterValueAfterDecrement)).toEqual(+initialCounterValue - 1); | ||
}); | ||
// #endregion decrement-counter-ui-test |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -40,4 +40,7 @@ src/sway-api/scripts | |
src/sway-api/index.ts | ||
|
||
sway-programs/**/out | ||
.turbo | ||
.turbo | ||
|
||
test-results | ||
playwright-report |
Oops, something went wrong.