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
550 changes: 173 additions & 377 deletions deno.lock

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion packages/fresh/src/dev/update_check_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,11 @@ Deno.test("migrates to last_shown property", async () => {
stdout: "piped",
}).output();

const { stdout } = getStdOutput(out);
const { stdout, stderr } = getStdOutput(out);
if (stdout === "") {
// deno-lint-ignore no-console
console.log(stderr);
}
expect(stdout).toMatch(/Fresh .* is available/);

const checkFileAfter = JSON.parse(
Expand Down
14 changes: 8 additions & 6 deletions packages/fresh/tests/test_utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@ export async function withBrowser(fn: (page: Page) => void | Promise<void>) {
}
}

export interface TestChildServerOptions {
cwd: string;
args: string[];
bin?: string;
env?: Record<string, string>;
}

export async function withChildProcessServer(
options: {
cwd: string;
args: string[];
bin?: string;
env?: Record<string, string>;
},
options: TestChildServerOptions,
fn: (address: string) => void | Promise<void>,
) {
const aborter = new AbortController();
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-vite/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"mime-db": "npm:mime-db@^1.54.0",
"preact": "npm:preact@^10.26.9",
"rollup-plugin-visualizer": "npm:rollup-plugin-visualizer@^6.0.3",
"vite": "npm:vite@^7.1.2",
"vite": "npm:vite@^7.1.3",
"vite-plugin-inspect": "npm:vite-plugin-inspect@^11.3.2"
}
}
6 changes: 5 additions & 1 deletion packages/plugin-vite/src/plugins/deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@ export function deno(): Plugin {
},
async configResolved() {
// TODO: Pass conditions
ssrLoader = await new Workspace({}).createLoader();
ssrLoader = await new Workspace({
platform: "node",
cachedOnly: true,
}).createLoader();
browserLoader = await new Workspace({
platform: "browser",
preserveJsx: true,
cachedOnly: true,
})
.createLoader();
},
Expand Down
105 changes: 33 additions & 72 deletions packages/plugin-vite/tests/build_test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import { expect } from "@std/expect";
import { waitForText, withBrowser } from "../../fresh/tests/test_utils.tsx";
import {
waitForText,
withBrowser,
withChildProcessServer,
} from "../../fresh/tests/test_utils.tsx";
import { buildVite, DEMO_DIR, FIXTURE_DIR, usingEnv } from "./test_utils.ts";
buildVite,
DEMO_DIR,
FIXTURE_DIR,
launchProd,
usingEnv,
} from "./test_utils.ts";
import * as path from "@std/path";

Deno.test({
name: "vite build - launches",
fn: async () => {
await using res = await buildVite(DEMO_DIR);

await withChildProcessServer(
{
cwd: res.tmp,
args: ["serve", "-A", "--port", "0", "_fresh/server.js"],
},
await launchProd(
{ cwd: res.tmp },
async (address) => {
const res = await fetch(address);
const text = await res.text();
Expand All @@ -33,11 +32,8 @@ Deno.test({
fn: async () => {
await using viteResult = await buildVite(DEMO_DIR);

await withChildProcessServer(
{
cwd: viteResult.tmp,
args: ["serve", "-A", "--port", "0", "_fresh/server.js"],
},
await launchProd(
{ cwd: viteResult.tmp },
async (address) => {
const res = await fetch(`${address}/test_static/foo.txt`);
const text = await res.text();
Expand All @@ -54,11 +50,8 @@ Deno.test({
fn: async () => {
await using res = await buildVite(DEMO_DIR);

await withChildProcessServer(
{
cwd: res.tmp,
args: ["serve", "-A", "--port", "0", "_fresh/server.js"],
},
await launchProd(
{ cwd: res.tmp },
async (address) => {
await withBrowser(async (page) => {
await page.goto(`${address}/tests/island_hooks`, {
Expand All @@ -83,11 +76,8 @@ Deno.test({
const fixture = path.join(FIXTURE_DIR, "no_static");
await using res = await buildVite(fixture);

await withChildProcessServer(
{
cwd: res.tmp,
args: ["serve", "-A", "--port", "0", "_fresh/server.js"],
},
await launchProd(
{ cwd: res.tmp },
async (address) => {
const res = await fetch(`${address}/ok`);
const text = await res.text();
Expand All @@ -105,11 +95,8 @@ Deno.test({
const fixture = path.join(FIXTURE_DIR, "no_islands");
await using res = await buildVite(fixture);

await withChildProcessServer(
{
cwd: res.tmp,
args: ["serve", "-A", "--port", "0", "_fresh/server.js"],
},
await launchProd(
{ cwd: res.tmp },
async (address) => {
const res = await fetch(`${address}`);
const text = await res.text();
Expand All @@ -127,11 +114,8 @@ Deno.test({
const fixture = path.join(FIXTURE_DIR, "no_routes");
await using res = await buildVite(fixture);

await withChildProcessServer(
{
cwd: res.tmp,
args: ["serve", "-A", "--port", "0", "_fresh/server.js"],
},
await launchProd(
{ cwd: res.tmp },
async (address) => {
const res = await fetch(`${address}`);
const text = await res.text();
Expand All @@ -148,11 +132,8 @@ Deno.test({
fn: async () => {
await using res = await buildVite(DEMO_DIR);

await withChildProcessServer(
{
cwd: res.tmp,
args: ["serve", "-A", "--port", "0", "_fresh/server.js"],
},
await launchProd(
{ cwd: res.tmp },
async (address) => {
await withBrowser(async (page) => {
await page.goto(`${address}/tests/mime`, {
Expand All @@ -173,11 +154,8 @@ Deno.test({
fn: async () => {
await using res = await buildVite(DEMO_DIR);

await withChildProcessServer(
{
cwd: res.tmp,
args: ["serve", "-A", "--port", "0", "_fresh/server.js"],
},
await launchProd(
{ cwd: res.tmp },
async (address) => {
await withBrowser(async (page) => {
await page.goto(`${address}/tests/assets`, {
Expand Down Expand Up @@ -207,11 +185,8 @@ Deno.test({
const fixture = path.join(FIXTURE_DIR, "tailwind_no_app");
await using res = await buildVite(fixture);

await withChildProcessServer(
{
cwd: res.tmp,
args: ["serve", "-A", "--port", "0", "_fresh/server.js"],
},
await launchProd(
{ cwd: res.tmp },
async (address) => {
await withBrowser(async (page) => {
await page.goto(`${address}`, {
Expand Down Expand Up @@ -240,11 +215,8 @@ Deno.test({
const fixture = path.join(FIXTURE_DIR, "tailwind_app");
await using res = await buildVite(fixture);

await withChildProcessServer(
{
cwd: res.tmp,
args: ["serve", "-A", "--port", "0", "_fresh/server.js"],
},
await launchProd(
{ cwd: res.tmp },
async (address) => {
await withBrowser(async (page) => {
await page.goto(`${address}`, {
Expand Down Expand Up @@ -272,11 +244,8 @@ Deno.test({
fn: async () => {
await using res = await buildVite(DEMO_DIR);

await withChildProcessServer(
{
cwd: res.tmp,
args: ["serve", "-A", "--port", "0", "_fresh/server.js"],
},
await launchProd(
{ cwd: res.tmp },
async (address) => {
await withBrowser(async (page) => {
await page.goto(`${address}/tests/partial`, {
Expand Down Expand Up @@ -315,15 +284,10 @@ Deno.test({
]
) {
using _ = usingEnv(key, revision);
// deno-lint-ignore no-console
console.log("Checking...", key, Deno.env.get(key));
await using res = await buildVite(DEMO_DIR);

await withChildProcessServer(
{
cwd: res.tmp,
args: ["serve", "-A", "--port", "0", "_fresh/server.js"],
},
await launchProd(
{ cwd: res.tmp },
async (address) => {
const res = await fetch(`${address}/tests/build_id`);
const text = await res.text();
Expand All @@ -346,11 +310,8 @@ Deno.test({
fn: async () => {
await using res = await buildVite(DEMO_DIR);

await withChildProcessServer(
{
cwd: res.tmp,
args: ["serve", "-A", "--port", "0", "_fresh/server.js"],
},
await launchProd(
{ cwd: res.tmp },
async (address) => {
const res = await fetch(`${address}/tests/dep_json`);
const json = await res.json();
Expand Down
28 changes: 27 additions & 1 deletion packages/plugin-vite/tests/test_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ export default defineConfig({
);

await withChildProcessServer(
{ cwd: tmp.dir, args: ["run", "-A", "npm:vite", "--port", "0"], env },
{
cwd: tmp.dir,
args: ["run", "-A", "--cached-only", "npm:vite", "--port", "0"],
env,
},
async (address) => await fn(address, tmp.dir),
);
}
Expand All @@ -85,6 +89,7 @@ export async function buildVite(fixtureDir: string) {
});

const builder = await createBuilder({
logLevel: "error",
root: fixtureDir,
build: {
emptyOutDir: true,
Expand Down Expand Up @@ -125,3 +130,24 @@ export function usingEnv(name: string, value: string) {
},
};
}

export interface ProdOptions {
cwd: string;
args?: string[];
bin?: string;
env?: Record<string, string>;
}

export async function launchProd(
options: ProdOptions,
fn: (address: string) => void | Promise<void>,
) {
return await withChildProcessServer(
{
cwd: options.cwd,
args: options.args ??
["serve", "-A", "--cached-only", "--port", "0", "_fresh/server.js"],
},
fn,
);
}
Loading