-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: enable build caching for playwright tests (#2338)
Relates to #2321 - Move build step as precondition for all checks and tests in the pipeline to create cache and avoid downstream build failures. - Extracted shared playwright config into `@sit-onyx/shared` package as `PLAYWRIGHT_BASE_CONFIG` to reduce code duplications. - Pass playwright shard configuration from `playwright.config.ts` file instead of using CLI arguments. See beneath for more details: There was an issue where every shard executed a fresh build of all packages. The cause was the `--shard` cli argument that differs for every shard. Because [turbo considers](https://turbo.build/repo/docs/crafting-your-repository/caching#task-inputs) pass-through arguments in their hashing, there was always a hash mismatch. Unfortunately, turbo doesn't support changing this behavior. Luckily, playwright allows setting the sharding configuration via the `playwright.config.ts` file, where we can use environment variables. And because turbo can be configured to ignore specific environment variables, we can use them instead of CLI arguments.
- Loading branch information
Showing
18 changed files
with
135 additions
and
144 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
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
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 |
---|---|---|
@@ -1,42 +1,11 @@ | ||
import { defineConfig, devices } from "@playwright/experimental-ct-vue"; | ||
import { defineConfig } from "@playwright/experimental-ct-vue"; | ||
import { PLAYWRIGHT_BASE_CONFIG } from "@sit-onyx/shared/playwright.config.base"; | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
...PLAYWRIGHT_BASE_CONFIG, | ||
testDir: "./", | ||
testMatch: `**/*.ct.tsx`, | ||
/* Maximum time one test can run for. */ | ||
timeout: 10 * 1000, | ||
/* 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, | ||
/* In the CI pipeline it generates dot (for the stdout) and blob reports, locally only a html report is generated */ | ||
reporter: process.env.CI ? [["dot"], ["blob"]] : [["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", | ||
|
||
/* Port to use for Playwright component endpoint. */ | ||
ctPort: 3100, | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
{ name: "edge", use: { ...devices["Desktop Edge"], channel: "msedge" } }, | ||
{ | ||
name: "firefox", | ||
use: { ...devices["Desktop Firefox"] }, | ||
}, | ||
{ | ||
name: "webkit", | ||
use: { ...devices["Desktop Safari"] }, | ||
}, | ||
], | ||
}); |
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,84 @@ | ||
import { devices, PlaywrightTestConfig } from "@playwright/experimental-ct-vue"; | ||
import vue, { Options } from "@vitejs/plugin-vue"; | ||
|
||
export const vuePluginOptions: Options = { | ||
template: { | ||
compilerOptions: { | ||
// comments can cause issues for components where classes | ||
// are not merged correctly, e.g. when using `<OnyxIcon class="custom-class" />` | ||
comments: false, | ||
}, | ||
}, | ||
}; | ||
|
||
/** | ||
* Basic, shared playwright configuration | ||
* | ||
* See https://playwright.dev/docs/test-configuration | ||
*/ | ||
export const PLAYWRIGHT_BASE_CONFIG = { | ||
/** | ||
* SCREENSHOTS | ||
* | ||
* See: https://playwright.dev/docs/screenshots | ||
*/ | ||
snapshotDir: "./playwright/snapshots", | ||
// custom snapshotPathTemplate to remove the testFileName folder that we don't want | ||
snapshotPathTemplate: "{snapshotDir}/{testFileDir}/{arg}-{projectName}-{platform}{ext}", | ||
// we don't want to update snapshots on the local machine of each developer. | ||
// if you want to update snapshots for your branch, use the corresponding GitHub action: | ||
// https://github.com/SchwarzIT/onyx/actions/workflows/playwright-screenshots.yml | ||
ignoreSnapshots: !process.env.CI, | ||
updateSnapshots: process.env.PW_UPDATE_SNAPSHOTS ? "all" : "none", | ||
|
||
/** | ||
* SHARDING | ||
* | ||
* See: https://playwright.dev/docs/test-sharding | ||
*/ | ||
fullyParallel: true, | ||
// when (in the pipeline) the sharding environment variables are set, sharding is enabled | ||
shard: | ||
process.env.CI && process.env.PW_SHARD && process.env.PW_TOTAL_SHARDS | ||
? { | ||
current: +process.env.PW_SHARD, | ||
total: +process.env.PW_TOTAL_SHARDS, | ||
} | ||
: null, | ||
|
||
/** | ||
* FAILURE HANDLING | ||
* | ||
* See: https://playwright.dev/docs/test-retries | ||
*/ | ||
timeout: 20 * 1000, | ||
forbidOnly: !!process.env.CI, // fail build on CI if we left test.only in the source code | ||
retries: process.env.CI ? 1 : 0, // retry on CI only | ||
|
||
/** | ||
* REPORTERS | ||
* | ||
* See: https://playwright.dev/docs/test-reporters | ||
*/ | ||
/* In the CI pipeline it generates dot (for the stdout) and blob reports, locally only a html report is generated */ | ||
reporter: process.env.CI ? [["dot"], ["blob"]] : [["html", { open: "never" }]], | ||
use: { | ||
trace: process.env.CI ? "retain-on-failure" : "off", | ||
video: process.env.CI ? "retain-on-failure" : "off", | ||
ctPort: 3100, | ||
ctViteConfig: { | ||
plugins: [vue(vuePluginOptions)], | ||
}, | ||
}, | ||
|
||
/** | ||
* BROWSERS | ||
* | ||
* See: https://playwright.dev/docs/test-projects | ||
*/ | ||
projects: [ | ||
{ name: "edge", use: { ...devices["Desktop Edge"], channel: "msedge" } }, | ||
{ name: "firefox", use: { ...devices["Desktop Firefox"] } }, | ||
{ name: "webkit", use: { ...devices["Desktop Safari"] } }, | ||
], | ||
} as const satisfies PlaywrightTestConfig; |
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
Oops, something went wrong.