-
Notifications
You must be signed in to change notification settings - Fork 6k
Parallel tests #3664
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
Merged
Parallel tests #3664
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ba0364a
Run each e2e test in a new workspace
code-asher add55ec
Import utils as a group in tests
code-asher 49c4481
Move onLine to utilities
code-asher da4de43
Spawn a code-server instance for each test suite
code-asher f2fa770
Centralize credential handling
code-asher 49c7cc6
Retain failed e2e videos only
code-asher 43c6ffc
Remove login steps from logout test
code-asher 2238d73
Fix occasional logout failure
code-asher 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
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 |
---|---|---|
@@ -1,12 +1,71 @@ | ||
import { field, logger } from "@coder/logger" | ||
import { test as base } from "@playwright/test" | ||
import { CodeServer } from "./models/CodeServer" | ||
import { CodeServer, CodeServerPage } from "./models/CodeServer" | ||
|
||
export const test = base.extend<{ codeServerPage: CodeServer }>({ | ||
codeServerPage: async ({ page }, use) => { | ||
const codeServer = new CodeServer(page) | ||
await codeServer.navigate() | ||
await use(codeServer) | ||
/** | ||
* Wraps `test.describe` to create and manage an instance of code-server. If you | ||
* don't use this you will need to create your own code-server instance and pass | ||
* it to `test.use`. | ||
* | ||
* If `includeCredentials` is `true` page requests will be authenticated. | ||
*/ | ||
export const describe = (name: string, includeCredentials: boolean, fn: (codeServer: CodeServer) => void) => { | ||
code-asher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
test.describe(name, () => { | ||
// This will spawn on demand so nothing is necessary on before. | ||
const codeServer = new CodeServer(name) | ||
|
||
// Kill code-server after the suite has ended. This may happen even without | ||
// doing it explicitly but it seems prudent to be sure. | ||
test.afterAll(async () => { | ||
await codeServer.close() | ||
}) | ||
|
||
const storageState = JSON.parse(process.env.STORAGE || "{}") | ||
|
||
// Sanity check to ensure the cookie is set. | ||
code-asher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const cookies = storageState?.cookies | ||
if (includeCredentials && (!cookies || cookies.length !== 1 || !!cookies[0].key)) { | ||
logger.error("no cookies", field("storage", JSON.stringify(cookies))) | ||
throw new Error("no credentials to include") | ||
} | ||
|
||
test.use({ | ||
// Makes `codeServer` and `authenticated` available to the extend call | ||
// below. | ||
codeServer, | ||
authenticated: includeCredentials, | ||
// This provides a cookie that authenticates with code-server. | ||
storageState: includeCredentials ? storageState : {}, | ||
}) | ||
|
||
fn(codeServer) | ||
}) | ||
} | ||
|
||
interface TestFixtures { | ||
authenticated: boolean | ||
codeServer: CodeServer | ||
codeServerPage: CodeServerPage | ||
} | ||
|
||
/** | ||
* Create a test that spawns code-server if necessary and ensures the page is | ||
* ready. | ||
*/ | ||
export const test = base.extend<TestFixtures>({ | ||
authenticated: false, | ||
codeServer: undefined, // No default; should be provided through `test.use`. | ||
codeServerPage: async ({ authenticated, codeServer, page }, use) => { | ||
// It's possible code-server might prevent navigation because of unsaved | ||
// changes (seems to happen based on timing even if no changes have been | ||
// made too). In these cases just accept. | ||
page.on("dialog", (d) => d.accept()) | ||
code-asher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const codeServerPage = new CodeServerPage(codeServer, page) | ||
await codeServerPage.setup(authenticated) | ||
await use(codeServerPage) | ||
}, | ||
}) | ||
|
||
/** Shorthand for test.expect. */ | ||
export const expect = test.expect |
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
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.
Uh oh!
There was an error while loading. Please reload this page.