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 packages/astro/src/core/dev/restart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async function restartContainerInPlace(container: Container): Promise<AstroSetti

interface CreateContainerWithAutomaticRestart {
inlineConfig?: AstroInlineConfig;
fs: typeof nodeFs;
fs?: typeof nodeFs;
}

interface Restart {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import { loadFixture } from './test-utils.js';
import { type DevServer, type Fixture, loadFixture } from './test-utils.js';

describe('base configuration', () => {
describe('with trailingSlash: "never"', () => {
let fixture;
let devServer;
let fixture: Fixture;
let devServer: DevServer;

before(async () => {
fixture = await loadFixture({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
import { type DevServer, type Fixture, loadFixture } from './test-utils.js';

describe('dev container', () => {
describe('basic rendering', () => {
let fixture;
let devServer;
let fixture: Fixture;
let devServer: DevServer;

before(async () => {
fixture = await loadFixture({
Expand All @@ -29,8 +29,8 @@ describe('dev container', () => {
});

describe('injected dynamic routes', () => {
let fixture;
let devServer;
let fixture: Fixture;
let devServer: DevServer;

before(async () => {
fixture = await loadFixture({
Expand Down Expand Up @@ -68,8 +68,8 @@ describe('dev container', () => {
});

describe('injected 404 route', () => {
let fixture;
let devServer;
let fixture: Fixture;
let devServer: DevServer;

before(async () => {
fixture = await loadFixture({
Expand Down Expand Up @@ -118,8 +118,8 @@ describe('dev container', () => {
});

describe('public/ with base', () => {
let fixture;
let devServer;
let fixture: Fixture;
let devServer: DevServer;

before(async () => {
fixture = await loadFixture({
Expand All @@ -145,8 +145,8 @@ describe('dev container', () => {
});

describe('public/ without base', () => {
let fixture;
let devServer;
let fixture: Fixture;
let devServer: DevServer;

before(async () => {
fixture = await loadFixture({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// @ts-check
import assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
import { type DevServer, type Fixture, loadFixture } from './test-utils.js';

describe('Dev pipeline - error pages', () => {
describe('Custom 404', () => {
let fixture;
let devServer;
let fixture: Fixture;
let devServer: DevServer;

before(async () => {
fixture = await loadFixture({
Expand Down Expand Up @@ -44,8 +43,8 @@ describe('Dev pipeline - error pages', () => {
});

describe('Custom 500', () => {
let fixture;
let devServer;
let fixture: Fixture;
let devServer: DevServer;

before(async () => {
fixture = await loadFixture({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
import { type DevServer, type Fixture, loadFixture } from './test-utils.js';

describe('core/render chunk', () => {
let fixture;
let devServer;
let fixture: Fixture;
let devServer: DevServer;

before(async () => {
fixture = await loadFixture({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
import { type DevServer, type Fixture, loadFixture } from './test-utils.js';

describe('core/render components', () => {
let fixture;
let devServer;
let fixture: Fixture;
let devServer: DevServer;

before(async () => {
fixture = await loadFixture({
Expand Down Expand Up @@ -36,7 +36,7 @@ describe('core/render components', () => {
const html = await res.text();
const $ = cheerio.load(html);

const check = (name) => JSON.parse($(name).text() || '{}');
const check = (name: string) => JSON.parse($(name).text() || '{}');

const Class = check('#class');
const ClassList = check('#class-list');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import * as assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import { loadFixture } from './test-utils.js';
import { type DevServer, type Fixture, loadFixture } from './test-utils.js';

describe('vite-plugin-astro-server', () => {
describe('url', () => {
/** @type {import('./test-utils.js').Fixture} */
let fixture;
/** @type {import('./test-utils.js').DevServer} */
let devServer;
let fixture: Fixture;
let devServer: DevServer;

before(async () => {
fixture = await loadFixture({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import * as assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import fs from 'node:fs';
import path from 'node:path';
import { describe, it } from 'node:test';
import { fileURLToPath } from 'node:url';
import type { AstroInlineConfig } from 'astro';
import type { Container } from '../dist/core/dev/container.js';
import { createContainerWithAutomaticRestart, startContainer } from '../dist/core/dev/index.js';

const fixtureDir = fileURLToPath(new URL('./fixtures/dev-container/', import.meta.url));

/** @type {import('astro').AstroInlineConfig} */
const defaultInlineConfig = {
const defaultInlineConfig: AstroInlineConfig = {
logLevel: 'silent',
};

function isStarted(container) {
function isStarted(container: Container) {
return !!container.viteServer.httpServer?.listening;
}

/**
* Safely clean up a file that a test may have created inside the fixture.
* No-ops if the file doesn't exist.
*/
function cleanupFile(relPath) {
function cleanupFile(relPath: string) {
try {
fs.unlinkSync(path.join(fixtureDir, relPath));
} catch {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { getDevRouteScripts } from '../dist/vite-plugin-routes/index.js';

type RouteScripts = Parameters<typeof getDevRouteScripts>[1];

describe('getDevRouteScripts', () => {
it('returns empty array when command is build', () => {
const scripts = [{ stage: 'page', content: 'console.log("page")' }];
const scripts: RouteScripts = [{ stage: 'page', content: 'console.log("page")' }];
const result = getDevRouteScripts('build', scripts);
assert.deepEqual(result, []);
});
Expand All @@ -15,7 +17,7 @@ describe('getDevRouteScripts', () => {
});

it('includes external page script entry when page-stage scripts exist', () => {
const scripts = [{ stage: 'page', content: 'import "alpinejs"' }];
const scripts: RouteScripts = [{ stage: 'page', content: 'import "alpinejs"' }];
const result = getDevRouteScripts('dev', scripts);

assert.equal(result.length, 1);
Expand All @@ -26,7 +28,7 @@ describe('getDevRouteScripts', () => {
});

it('collapses multiple page scripts into a single external entry', () => {
const scripts = [
const scripts: RouteScripts = [
{ stage: 'page', content: 'import "alpinejs"' },
{ stage: 'page', content: 'import "other"' },
];
Expand All @@ -37,7 +39,7 @@ describe('getDevRouteScripts', () => {
});

it('includes head-inline scripts with their content', () => {
const scripts = [{ stage: 'head-inline', content: 'console.log("inline")' }];
const scripts: RouteScripts = [{ stage: 'head-inline', content: 'console.log("inline")' }];
const result = getDevRouteScripts('dev', scripts);

assert.equal(result.length, 1);
Expand All @@ -48,7 +50,7 @@ describe('getDevRouteScripts', () => {
});

it('includes both page and head-inline scripts together', () => {
const scripts = [
const scripts: RouteScripts = [
{ stage: 'page', content: 'import "alpinejs"' },
{ stage: 'head-inline', content: 'console.log("inline1")' },
{ stage: 'head-inline', content: 'console.log("inline2")' },
Expand All @@ -71,7 +73,7 @@ describe('getDevRouteScripts', () => {
});

it('ignores before-hydration and page-ssr stage scripts', () => {
const scripts = [
const scripts: RouteScripts = [
{ stage: 'before-hydration', content: 'console.log("hydration")' },
{ stage: 'page-ssr', content: 'console.log("ssr")' },
];
Expand All @@ -81,7 +83,7 @@ describe('getDevRouteScripts', () => {
});

it('ignores non-relevant stages while still collecting page and head-inline', () => {
const scripts = [
const scripts: RouteScripts = [
{ stage: 'before-hydration', content: 'console.log("hydration")' },
{ stage: 'page', content: 'import "alpinejs"' },
{ stage: 'page-ssr', content: 'console.log("ssr")' },
Expand Down
Loading