0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-27 22:19:04 -05:00

[ci] format

This commit is contained in:
Mads Erik Forberg 2024-01-03 13:21:03 +00:00 committed by astrobot-houston
parent 769826edbd
commit f85cb1fab6
5 changed files with 24 additions and 17 deletions

View file

@ -64,13 +64,17 @@ export type {
} from '../assets/types.js';
export type { RemotePattern } from '../assets/utils/remotePattern.js';
export type { SSRManifest } from '../core/app/types.js';
export type { AstroCookies, AstroCookieSetOptions, AstroCookieGetOptions } from '../core/cookies/index.js';
export type {
AstroCookies,
AstroCookieSetOptions,
AstroCookieGetOptions,
} from '../core/cookies/index.js';
export interface AstroBuiltinProps {
'client:load'?: boolean;
'client:idle'?: boolean;
'client:media'?: string;
'client:visible'?: string|boolean;
'client:visible'?: string | boolean;
'client:only'?: boolean | string;
}

View file

@ -15,7 +15,7 @@ export interface AstroCookieSetOptions {
export interface AstroCookieGetOptions {
decode?: (value: string) => string;
};
}
type AstroCookieDeleteOptions = Pick<AstroCookieSetOptions, 'domain' | 'path'>;
@ -102,7 +102,10 @@ class AstroCookies implements AstroCookiesInterface {
* @param key The cookie to get.
* @returns An object containing the cookie value as well as convenience methods for converting its value.
*/
get(key: string, options: AstroCookieGetOptions | undefined = undefined): AstroCookie | undefined {
get(
key: string,
options: AstroCookieGetOptions | undefined = undefined
): AstroCookie | undefined {
// Check for outgoing Set-Cookie values first
if (this.#outgoing?.has(key)) {
let [serializedValue, , isSetValue] = this.#outgoing.get(key)!;

View file

@ -4,4 +4,4 @@ export {
getSetCookiesFromResponse,
responseHasCookies,
} from './response.js';
export type { AstroCookieSetOptions, AstroCookieGetOptions } from "./cookies.js";
export type { AstroCookieSetOptions, AstroCookieGetOptions } from './cookies.js';

View file

@ -17,27 +17,27 @@ describe('astro/src/core/cookies', () => {
});
it('gets the cookie value with default decode', () => {
const url = 'http://localhost';
const url = 'http://localhost';
const req = new Request('http://example.com/', {
headers: {
cookie: `url=${encodeURIComponent(url)}`,
},
});
const cookies = new AstroCookies(req);
// by default decodeURIComponent is used on the value
// by default decodeURIComponent is used on the value
expect(cookies.get('url').value).to.equal(url);
});
it('gets the cookie value with custom decode', () => {
const url = 'http://localhost';
const url = 'http://localhost';
const req = new Request('http://example.com/', {
headers: {
cookie: `url=${encodeURIComponent(url)}`,
},
});
const cookies = new AstroCookies(req);
// set decode to the identity function to prevent decodeURIComponent on the value
expect(cookies.get('url', { decode: o => o }).value).to.equal(encodeURIComponent(url));
// set decode to the identity function to prevent decodeURIComponent on the value
expect(cookies.get('url', { decode: (o) => o }).value).to.equal(encodeURIComponent(url));
});
it("Returns undefined is the value doesn't exist", () => {

View file

@ -18,23 +18,23 @@ describe('astro/src/core/cookies', () => {
it('Sets a cookie value that can be serialized w/ defaultencodeURIComponent behavior', () => {
let req = new Request('http://example.com/');
let cookies = new AstroCookies(req);
const url = 'http://localhost/path';
const url = 'http://localhost/path';
cookies.set('url', url);
let headers = Array.from(cookies.headers());
expect(headers).to.have.a.lengthOf(1);
// by default cookie value is URI encoded
// by default cookie value is URI encoded
expect(headers[0]).to.equal(`url=${encodeURIComponent(url)}`);
});
it('Sets a cookie value that can be serialized w/ custom encode behavior', () => {
let req = new Request('http://example.com/');
let cookies = new AstroCookies(req);
const url = 'http://localhost/path';
// set encode option to the identity function
cookies.set('url', url, { encode: o => o });
const url = 'http://localhost/path';
// set encode option to the identity function
cookies.set('url', url, { encode: (o) => o });
let headers = Array.from(cookies.headers());
expect(headers).to.have.a.lengthOf(1);
// no longer URI encoded
// no longer URI encoded
expect(headers[0]).to.equal(`url=${url}`);
});