hmr-new-page.test.js — astro Source File
Architecture documentation for hmr-new-page.test.js, a javascript file in the astro codebase. 7 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR a144d0e5_d6ab_288a_92d8_c2f5761bf069["hmr-new-page.test.js"] 0a624eac_945e_c9e8_c9de_3feb9de2dd15["test-utils.js"] a144d0e5_d6ab_288a_92d8_c2f5761bf069 --> 0a624eac_945e_c9e8_c9de_3feb9de2dd15 dd4f09ce_3fd7_8295_f616_8876cda4555c["loadFixture"] a144d0e5_d6ab_288a_92d8_c2f5761bf069 --> dd4f09ce_3fd7_8295_f616_8876cda4555c e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"] a144d0e5_d6ab_288a_92d8_c2f5761bf069 --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607 e16a223b_37f3_6b25_1ee1_2b7bcb9d9415["node:fs"] a144d0e5_d6ab_288a_92d8_c2f5761bf069 --> e16a223b_37f3_6b25_1ee1_2b7bcb9d9415 c52a5f83_66e3_37d7_9ebb_767f7129bc62["node:path"] a144d0e5_d6ab_288a_92d8_c2f5761bf069 --> c52a5f83_66e3_37d7_9ebb_767f7129bc62 d9a92db9_c95e_9165_13ac_24b3d859d946["node:url"] a144d0e5_d6ab_288a_92d8_c2f5761bf069 --> d9a92db9_c95e_9165_13ac_24b3d859d946 6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"] a144d0e5_d6ab_288a_92d8_c2f5761bf069 --> 6b0635f9_51ea_77aa_767b_7857878e98a6 style a144d0e5_d6ab_288a_92d8_c2f5761bf069 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { after, before, describe, it } from 'node:test';
import { isWindows, loadFixture } from './test-utils.js';
const NEW_PAGE_CONTENT = `---
---
<html>
<head><title>New Page</title></head>
<body><h1>New Page Created via HMR</h1></body>
</html>
`;
describe('HMR: New page detection', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
/** @type {import('./test-utils').DevServer} */
let devServer;
/** @type {string} */
let newPagePath;
before(async () => {
fixture = await loadFixture({ root: './fixtures/hmr-new-page/' });
devServer = await fixture.startDevServer();
// Compute path for the new page we'll create during tests
const fixtureRoot = fileURLToPath(new URL('./fixtures/hmr-new-page/', import.meta.url));
newPagePath = path.join(fixtureRoot, 'src/pages/new-page.astro');
});
after(async () => {
await devServer.stop();
// Clean up: remove the new page if it exists
try {
await fs.promises.unlink(newPagePath);
} catch {
// File doesn't exist, that's fine
}
});
it('should return 200 for index page', async () => {
const response = await fixture.fetch('/');
assert.equal(response.status, 200);
});
it('should return 404 for non-existent page', async () => {
const response = await fixture.fetch('/new-page');
assert.equal(response.status, 404);
});
it(
'should detect a new page without server restart',
{ skip: isWindows, todo: 'I hangs on windows' },
async () => {
// 1. Verify the page doesn't exist yet
let response = await fixture.fetch('/new-page');
assert.equal(response.status, 404, 'Page should not exist initially');
// 2. Create the new page file
await fs.promises.writeFile(newPagePath, NEW_PAGE_CONTENT, 'utf-8');
// 3. Wait for HMR to process the change
await new Promise((resolve) => setTimeout(resolve, 2000));
// 4. Verify the new page is now accessible
response = await fixture.fetch('/new-page');
assert.equal(response.status, 200, 'Page should be accessible after creation');
const html = await response.text();
assert.ok(html.includes('New Page Created via HMR'), 'Page content should match');
},
);
it(
'should detect page removal without server restart',
{ skip: isWindows, todo: 'I hangs on windows' },
async () => {
// Ensure the page exists first (from previous test or create it)
if (!fs.existsSync(newPagePath)) {
await fs.promises.writeFile(newPagePath, NEW_PAGE_CONTENT, 'utf-8');
await new Promise((resolve) => setTimeout(resolve, 2000));
}
// 1. Verify the page is accessible
let response = await fixture.fetch('/new-page');
assert.equal(response.status, 200, 'Page should exist before deletion');
// 2. Delete the page file
await fs.promises.unlink(newPagePath);
// 3. Wait for HMR to process the change
await new Promise((resolve) => setTimeout(resolve, 2000));
// 4. Verify the page now returns 404
response = await fixture.fetch('/new-page');
assert.equal(response.status, 404, 'Page should return 404 after deletion');
},
);
});
Domain
Dependencies
- loadFixture
- node:fs
- node:path
- node:test
- node:url
- strict
- test-utils.js
Source
Frequently Asked Questions
What does hmr-new-page.test.js do?
hmr-new-page.test.js is a source file in the astro codebase, written in javascript. It belongs to the IntegrationAdapters domain.
What does hmr-new-page.test.js depend on?
hmr-new-page.test.js imports 7 module(s): loadFixture, node:fs, node:path, node:test, node:url, strict, test-utils.js.
Where is hmr-new-page.test.js in the architecture?
hmr-new-page.test.js is located at packages/astro/test/hmr-new-page.test.js (domain: IntegrationAdapters, directory: packages/astro/test).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free