Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion biome.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/2.4.2/schema.json",
"$schema": "https://biomejs.dev/schemas/2.4.10/schema.json",
"files": {
"includes": [
"**",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
},
"devDependencies": {
"@astrojs/check": "^0.9.5",
"@biomejs/biome": "2.4.2",
"@biomejs/biome": "2.4.10",
"@changesets/changelog-github": "^0.5.2",
"@changesets/cli": "^2.29.8",
"@flue/cli": "^0.0.47",
Expand Down
26 changes: 12 additions & 14 deletions packages/astro/test/astro-component-bundling.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,18 @@ describe('Component bundling', () => {
await fixture.build();
});

it(
'should treeshake FooComponent',
{ skip: 'Not sure how this can possibly work, we bundle the module as an entrypoint.' },
async () => {
const astroChunkDir = await fixture.readdir('/_astro');
const manyComponentsChunkName = astroChunkDir.find((chunk) =>
chunk.startsWith('ManyComponents'),
);
const manyComponentsChunkContent = await fixture.readFile(
`/_astro/${manyComponentsChunkName}`,
);
assert.equal(manyComponentsChunkContent.includes('FooComponent'), false);
},
);
it('should treeshake FooComponent', {
skip: 'Not sure how this can possibly work, we bundle the module as an entrypoint.',
}, async () => {
const astroChunkDir = await fixture.readdir('/_astro');
const manyComponentsChunkName = astroChunkDir.find((chunk) =>
chunk.startsWith('ManyComponents'),
);
const manyComponentsChunkContent = await fixture.readFile(
`/_astro/${manyComponentsChunkName}`,
);
assert.equal(manyComponentsChunkContent.includes('FooComponent'), false);
});

it('should not include Astro components in client bundles', async () => {
const html = await fixture.readFile('/astro-in-client/index.html');
Expand Down
144 changes: 66 additions & 78 deletions packages/astro/test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,54 +14,50 @@ describe('astro cli', () => {
});

// Flaky test, in CI it exceeds the timeout most of the times
it.skip(
'astro check --watch reports errors on modified files',
{
timeout: 35000,
},
async () => {
let messageResolve;
const messagePromise = new Promise((resolve) => {
messageResolve = resolve;
});
const oneErrorContent = 'foobar';
it.skip('astro check --watch reports errors on modified files', {
timeout: 35000,
}, async () => {
let messageResolve;
const messagePromise = new Promise((resolve) => {
messageResolve = resolve;
});
const oneErrorContent = 'foobar';

/** @type {import('./test-utils').Fixture} */
const fixture = await loadFixture({
root: './fixtures/astro-check-watch/',
});
const logs = [];
/** @type {import('./test-utils').Fixture} */
const fixture = await loadFixture({
root: './fixtures/astro-check-watch/',
});
const logs = [];

const checkServer = await fixture.check({
flags: { watch: true },
logging: {
level: 'info',
dest: new Writable({
objectMode: true,
write(event, _, callback) {
logs.push({ ...event, message: stripVTControlCharacters(event.message) });
if (event.message.includes('1 error')) {
messageResolve(logs);
}
callback();
},
}),
},
});
await checkServer.watch();
const pagePath = join(fileURLToPath(fixture.config.root), 'src/pages/index.astro');
const pageContent = readFileSync(pagePath, 'utf-8');
await fs.writeFile(pagePath, oneErrorContent);
const messages = await messagePromise;
await fs.writeFile(pagePath, pageContent);
await checkServer.stop();
const diagnostics = messages.filter(
(m) => m.type === 'diagnostics' && m.message.includes('Result'),
);
assert.equal(diagnostics[0].message.includes('0 errors'), true);
assert.equal(diagnostics[1].message.includes('1 error'), true);
},
);
const checkServer = await fixture.check({
flags: { watch: true },
logging: {
level: 'info',
dest: new Writable({
objectMode: true,
write(event, _, callback) {
logs.push({ ...event, message: stripVTControlCharacters(event.message) });
if (event.message.includes('1 error')) {
messageResolve(logs);
}
callback();
},
}),
},
});
await checkServer.watch();
const pagePath = join(fileURLToPath(fixture.config.root), 'src/pages/index.astro');
const pageContent = readFileSync(pagePath, 'utf-8');
await fs.writeFile(pagePath, oneErrorContent);
const messages = await messagePromise;
await fs.writeFile(pagePath, pageContent);
await checkServer.stop();
const diagnostics = messages.filter(
(m) => m.type === 'diagnostics' && m.message.includes('Result'),
);
assert.equal(diagnostics[0].message.includes('0 errors'), true);
assert.equal(diagnostics[1].message.includes('1 error'), true);
});

it('astro --version', async () => {
const pkgURL = new URL('../package.json', import.meta.url);
Expand All @@ -72,39 +68,31 @@ describe('astro cli', () => {
assert.equal(result.stdout.includes(pkgVersion), true);
});

it(
'astro check no errors',
{
timeout: 35000,
},
async () => {
const projectRootURL = new URL('./fixtures/astro-check-no-errors/', import.meta.url);
const result = await cli(
'check',
'--root',
fileURLToPath(projectRootURL),
'--noSync',
).getResult();
it('astro check no errors', {
timeout: 35000,
}, async () => {
const projectRootURL = new URL('./fixtures/astro-check-no-errors/', import.meta.url);
const result = await cli(
'check',
'--root',
fileURLToPath(projectRootURL),
'--noSync',
).getResult();

assert.equal(result.stdout.includes('0 errors'), true);
},
);
assert.equal(result.stdout.includes('0 errors'), true);
});

it(
'astro check has errors',
{
timeout: 35000,
},
async () => {
const projectRootURL = new URL('./fixtures/astro-check-errors/', import.meta.url);
const result = await cli(
'check',
'--root',
fileURLToPath(projectRootURL),
'--noSync',
).getResult();
it('astro check has errors', {
timeout: 35000,
}, async () => {
const projectRootURL = new URL('./fixtures/astro-check-errors/', import.meta.url);
const result = await cli(
'check',
'--root',
fileURLToPath(projectRootURL),
'--noSync',
).getResult();

assert.equal(result.stdout.includes('1 error'), true);
},
);
assert.equal(result.stdout.includes('1 error'), true);
});
});
14 changes: 6 additions & 8 deletions packages/astro/test/custom-404-implicit-rerouting.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,12 @@ for (const caseNumber of [1, 2, 3, 4, 5]) {
});

// IMPORTANT: never skip
it(
'prod server stays responsive for case number ' + caseNumber,
{ timeout: 3000 },
async () => {
const response = await app.render(new Request('https://example.com/alvsibdlvjks'));
assert.equal(response.status, 404);
},
);
it('prod server stays responsive for case number ' + caseNumber, {
timeout: 3000,
}, async () => {
const response = await app.render(new Request('https://example.com/alvsibdlvjks'));
assert.equal(response.status, 404);
});
});
});
}
55 changes: 27 additions & 28 deletions packages/astro/test/hmr-markdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,31 @@ describe('HMR: Markdown updates', () => {
await devServer.stop();
});

it(
'should update HTML when markdown changes',
{ skip: isWindows, todo: 'HMR tests hang on Windows' },
async () => {
let response = await fixture.fetch('/');
assert.equal(response.status, 200);
let html = await response.text();
assert.ok(html.includes('Original content'));

response = await fixture.fetch('/blog/post');
assert.equal(response.status, 200);
html = await response.text();
assert.ok(html.includes('Original content'));

await fixture.editFile(markdownPath, UPDATED_CONTENT);
await fixture.onNextDataStoreChange();

response = await fixture.fetch('/');
assert.equal(response.status, 200);
html = await response.text();
assert.ok(html.includes('Updated content'));

response = await fixture.fetch('/blog/post');
assert.equal(response.status, 200);
html = await response.text();
assert.ok(html.includes('Updated content'));
},
);
it('should update HTML when markdown changes', {
skip: isWindows,
todo: 'HMR tests hang on Windows',
}, async () => {
let response = await fixture.fetch('/');
assert.equal(response.status, 200);
let html = await response.text();
assert.ok(html.includes('Original content'));

response = await fixture.fetch('/blog/post');
assert.equal(response.status, 200);
html = await response.text();
assert.ok(html.includes('Original content'));

await fixture.editFile(markdownPath, UPDATED_CONTENT);
await fixture.onNextDataStoreChange();

response = await fixture.fetch('/');
assert.equal(response.status, 200);
html = await response.text();
assert.ok(html.includes('Updated content'));

response = await fixture.fetch('/blog/post');
assert.equal(response.status, 200);
html = await response.text();
assert.ok(html.includes('Updated content'));
});
});
84 changes: 41 additions & 43 deletions packages/astro/test/hmr-new-page.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,52 +50,50 @@ describe('HMR: New page detection', () => {
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');
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');
});

// 3. Wait for HMR to process the change
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));
}

// 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);
// 1. Verify the page is accessible
let response = await fixture.fetch('/new-page');
assert.equal(response.status, 200, 'Page should exist before deletion');

// 3. Wait for HMR to process the change
await new Promise((resolve) => setTimeout(resolve, 2000));
// 2. Delete the page file
await fs.promises.unlink(newPagePath);

// 4. Verify the page now returns 404
response = await fixture.fetch('/new-page');
assert.equal(response.status, 404, 'Page should return 404 after deletion');
},
);
// 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');
});
});
Loading
Loading