sessions.test.js — astro Source File
Architecture documentation for sessions.test.js, a javascript file in the astro codebase. 6 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 6e32da71_4d59_751f_de0a_380b0e3051c2["sessions.test.js"] c57448e9_39cb_8f2c_813c_f4c854683c87["../dist/index.js"] 6e32da71_4d59_751f_de0a_380b0e3051c2 --> c57448e9_39cb_8f2c_813c_f4c854683c87 635e1221_67bb_e784_624a_d6d63643872b["_test-utils.js"] 6e32da71_4d59_751f_de0a_380b0e3051c2 --> 635e1221_67bb_e784_624a_d6d63643872b 33b9a01d_12ac_568f_9775_9e80b35139cb["loadFixture"] 6e32da71_4d59_751f_de0a_380b0e3051c2 --> 33b9a01d_12ac_568f_9775_9e80b35139cb e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"] 6e32da71_4d59_751f_de0a_380b0e3051c2 --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607 6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"] 6e32da71_4d59_751f_de0a_380b0e3051c2 --> 6b0635f9_51ea_77aa_767b_7857878e98a6 ca52ff61_c81f_c2ca_81b6_5a678b65fd31["devalue"] 6e32da71_4d59_751f_de0a_380b0e3051c2 --> ca52ff61_c81f_c2ca_81b6_5a678b65fd31 style 6e32da71_4d59_751f_de0a_380b0e3051c2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import * as devalue from 'devalue';
import cloudflare from '../dist/index.js';
import { loadFixture } from './_test-utils.js';
describe('sessions', () => {
let fixture;
let previewServer;
before(async () => {
fixture = await loadFixture({
root: './fixtures/sessions/',
});
await fixture.build();
previewServer = await fixture.preview();
});
after(async () => {
await previewServer.stop();
});
it('can regenerate session cookies upon request', async () => {
const firstResponse = await fixture.fetch('/regenerate', { method: 'GET' });
const firstHeaders = firstResponse.headers.get('set-cookie').split(',');
const firstSessionId = firstHeaders[0].split(';')[0].split('=')[1];
const secondResponse = await fixture.fetch('/regenerate', {
method: 'GET',
headers: {
cookie: `astro-session=${firstSessionId}`,
},
});
const secondHeaders = secondResponse.headers.get('set-cookie').split(',');
const secondSessionId = secondHeaders[0].split(';')[0].split('=')[1];
assert.notEqual(firstSessionId, secondSessionId);
});
it('can save session data by value', async () => {
const firstResponse = await fixture.fetch('/update', { method: 'GET' });
const firstValue = await firstResponse.json();
assert.equal(firstValue.previousValue, 'none');
const firstHeaders = firstResponse.headers.get('set-cookie').split(',');
const firstSessionId = firstHeaders[0].split(';')[0].split('=')[1];
const secondResponse = await fixture.fetch('/update', {
method: 'GET',
headers: {
cookie: `astro-session=${firstSessionId}`,
},
});
const secondValue = await secondResponse.json();
assert.equal(secondValue.previousValue, 'expected');
});
it('can save and restore URLs in session data', async () => {
const firstResponse = await fixture.fetch('/_actions/addUrl', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ favoriteUrl: 'https://domain.invalid' }),
});
assert.equal(firstResponse.ok, true);
const firstHeaders = firstResponse.headers.get('set-cookie').split(',');
const firstSessionId = firstHeaders[0].split(';')[0].split('=')[1];
const data = devalue.parse(await firstResponse.text());
assert.equal(data.message, 'Favorite URL set to https://domain.invalid/ from nothing');
const secondResponse = await fixture.fetch('/_actions/addUrl', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
cookie: `astro-session=${firstSessionId}`,
},
body: JSON.stringify({ favoriteUrl: 'https://example.com' }),
});
const secondData = devalue.parse(await secondResponse.text());
assert.equal(
secondData.message,
'Favorite URL set to https://example.com/ from https://domain.invalid/',
);
});
});
describe('sessions with custom binding name', () => {
let fixture;
before(async () => {
fixture = await loadFixture({
root: './fixtures/sessions/',
adapter: cloudflare({
sessionKVBindingName: 'CUSTOM_SESSION',
}),
});
});
it('can build with custom session binding name', async () => {
await assert.doesNotReject(
async () => {
await fixture.build();
},
undefined,
'Building with custom session binding name should not throw an error',
);
});
});
Domain
Dependencies
- ../dist/index.js
- _test-utils.js
- devalue
- loadFixture
- node:test
- strict
Source
Frequently Asked Questions
What does sessions.test.js do?
sessions.test.js is a source file in the astro codebase, written in javascript. It belongs to the CoreAstro domain.
What does sessions.test.js depend on?
sessions.test.js imports 6 module(s): ../dist/index.js, _test-utils.js, devalue, loadFixture, node:test, strict.
Where is sessions.test.js in the architecture?
sessions.test.js is located at packages/integrations/cloudflare/test/sessions.test.js (domain: CoreAstro, directory: packages/integrations/cloudflare/test).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free