-
Notifications
You must be signed in to change notification settings - Fork 298
[Playground CLI] Add enableCookieStore argument to runCLI #2227
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
Conversation
What would be an example of a use-case? |
Writing integration tests for Playground. For example this test file used to work before we disabled the cookie store. Without a cookie store, I can't login the user with integration tests. |
Couldn't we use a test client that supports cookie headers instead? Cookie store won't work for tests involving more than one login session. |
Do you mean like a client specialized for testing, e.g., instead of I considered building a testing library, but it would still mostly be the same as |
Could you maybe explain what your concern is with expanding |
My concern is processing cookies differently in the test suite and outside of the test suite. How would we know if the tests are reliable? Cookies are typically handled by the client, not by the server. Multiple clients can co-exist with different sets of cookies. The client may also support domain– and path– specific cookies, when the server doesn't always see the domain or the path in the same way as the client.
I just mean a cookie-aware middleware, e.g. similar to this: const cliServer = await runCLI({
command: 'server',
});
const testClient = cookieAwareClient( cliServer.requestHandler );
const response = await testClient.request({
url: '/wp-login.php',
method: 'POST',
// ... login data ...
});
// testClient processes response cookies, saves them, and adds them to request headers
// for subsequent requests
|
Thanks, this context helps me a lot! What about this: a4e17ee? Instead of the Playground CLI setting the Cookie store, the PHPRequestHandler can have a |
@@ -237,4 +239,54 @@ describe('cli-run', () => { | |||
expect(await getDirectoryChecksum(tmpDir)).toBe(checksum); | |||
}); | |||
}); | |||
|
|||
describe.only('cookie store', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed, just demonstrates how to use the setCookieStore
method.
Note it must be separate from the request handler. Otherwise we can't write a test where two users send alternating requests. |
@adamziel and I chatted about this and concluded that there's no real need for a cookie-enabled client in Playground besides my use case. Because I already use |
Motivation for the change, related issues
In a recent PR, we disabled the cookie store for Playground CLI. This way, browsers can control cookies when running WordPress using the Playground CLI.
But when using
runCLI
for testing, the cookie store can be useful because it allows tests to store login cookies between requests.This PR proposes an
enableCookieStore
argument for therunCLI
function, enabling users to activate the cookie store.I considered adding an argument to the CLI, but I can't think of any use for enabling cookie stores when running it from the terminal.
Implementation details
runCLI
now accepts aenableCookieStore
argument. If the argument is set to true, the default cookie store will be used inside thePHPRequestHandler
. Otherwise, the cookie store will be disabled.Testing Instructions (or ideally a Blueprint)