Skip to content
This repository has been archived by the owner on Feb 10, 2025. It is now read-only.

Commit

Permalink
chore(cloudflare): fixup migration issues
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderniebuhr committed Oct 16, 2023
1 parent c631438 commit 1f20071
Show file tree
Hide file tree
Showing 63 changed files with 1,610 additions and 746 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
timeout-minutes: 3
strategy:
matrix:
OS: [ubuntu-latest]
OS: [ubuntu-latest, windows-latest]
NODE_VERSION: [20]
fail-fast: true
steps:
Expand Down Expand Up @@ -108,7 +108,12 @@ jobs:
strategy:
matrix:
OS: [ubuntu-latest]
NODE_VERSION: [20.5.1]
NODE_VERSION: [18, 20.5.1]
include:
- os: macos-latest
NODE_VERSION: 18
- os: windows-latest
NODE_VERSION: 18.17.1
fail-fast: false
env:
NODE_VERSION: ${{ matrix.NODE_VERSION }}
Expand All @@ -135,4 +140,4 @@ jobs:
run: pnpm run build

- name: Test
run: pnpm run test
run: pnpm run test
19 changes: 8 additions & 11 deletions packages/cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,15 @@
"dist"
],
"scripts": {
"build": "astro-scripts build \"src/**/*.ts\" && tsc",
"build:ci": "astro-scripts build \"src/**/*.ts\"",
"dev": "astro-scripts dev \"src/**/*.ts\"",
"build": "tsc",
"test": "mocha --exit --timeout 30000 test/",
"test:match": "mocha --exit --timeout 30000 -g"
},
"dependencies": {
"@astrojs/underscore-redirects": "workspace:*",
"@astrojs/underscore-redirects": "^0.3.0",
"@cloudflare/workers-types": "^4.20230821.0",
"miniflare": "^3.20230918.0",
"miniflare": "3.20231010.0",
"@iarna/toml": "^2.2.5",
"@miniflare/cache": "^2.14.1",
"@miniflare/shared": "^2.14.1",
"@miniflare/storage-memory": "^2.14.1",
"dotenv": "^16.3.1",
"esbuild": "^0.19.2",
"find-up": "^6.3.0",
Expand All @@ -51,13 +46,15 @@
"astro": "workspace:^3.3.0"
},
"devDependencies": {
"execa": "^8.0.1",
"fast-glob": "^3.3.1",
"@types/iarna__toml": "^2.0.2",
"astro": "workspace:*",
"astro-scripts": "workspace:*",
"strip-ansi": "^7.1.0",
"astro": "^3.2.3",
"chai": "^4.3.7",
"cheerio": "1.0.0-rc.12",
"mocha": "^10.2.0",
"wrangler": "^3.5.1"
"wrangler": "^3.11.0"
},
"publishConfig": {
"provenance": true
Expand Down
7 changes: 6 additions & 1 deletion packages/cloudflare/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,12 @@ export default function createIntegration(args?: Options): AstroIntegration {
vite.resolve ||= {};
vite.resolve.alias ||= {};

const aliases = [{ find: 'react-dom/server', replacement: 'react-dom/server.browser' }];
const aliases = [
{
find: 'react-dom/server',
replacement: 'react-dom/server.browser',
},
];

if (Array.isArray(vite.resolve.alias)) {
vite.resolve.alias = [...vite.resolve.alias, ...aliases];
Expand Down
50 changes: 50 additions & 0 deletions packages/cloudflare/test/_test-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { fileURLToPath } from "node:url";
import { execa } from "execa";
/**
* @typedef {{ stop: Promise<void>, port: number }} WranglerCLI
*/

const astroPath = fileURLToPath(
new URL("../node_modules/.bin/astro", import.meta.url)
);
/** Returns a process running the Astro CLI. */
export function astroCli(cwd, /** @type {string[]} */ ...args) {
const spawned = execa(astroPath, [...args], {
env: { ASTRO_TELEMETRY_DISABLED: true },
cwd: cwd,
});

spawned.stdout.setEncoding("utf8");

return spawned;
}

const wranglerPath = fileURLToPath(
new URL("../node_modules/wrangler/bin/wrangler.js", import.meta.url)
);
/** Returns a process running the Astro CLI. */
export function wranglerCli(cwd) {
const spawned = execa(
wranglerPath,
[
"pages",
"dev",
"dist",
"--port",
"8788",
"--compatibility-date",
new Date().toISOString().slice(0, 10),
"--log-level",
"info",
],
{
env: { CI: 1, CF_PAGES: 1 },
cwd: cwd,
}
);

spawned.stdout.setEncoding("utf8");
spawned.stderr.setEncoding("utf8");

return spawned;
}
39 changes: 0 additions & 39 deletions packages/cloudflare/test/basics.test.js

This file was deleted.

127 changes: 0 additions & 127 deletions packages/cloudflare/test/cf.test.js

This file was deleted.

82 changes: 82 additions & 0 deletions packages/cloudflare/test/dev-runtime.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { expect } from "chai";
import * as cheerio from "cheerio";
import { fileURLToPath } from "node:url";
import { astroCli } from "./_test-utils.js";

const root = new URL("./fixtures/dev-runtime/", import.meta.url);
describe("Runtime Astro Dev", () => {
let cli;
before(async () => {
cli = astroCli(fileURLToPath(root), "dev", "--host", "127.0.0.1");
await new Promise((resolve) => {
cli.stdout.on("data", (data) => {
if (data.includes("http://127.0.0.1:4321/")) {
resolve();
}
});
});
});

after((done) => {
cli.kill();
setTimeout(() => {
console.log("CLEANED");
done();
}, 1000);
});

it("exists", async () => {
let res = await fetch(`http://127.0.0.1:4321/`);
let html = await res.text();
let $ = cheerio.load(html);
expect($("#hasRuntime").text()).to.contain("true");
});

it("adds cf object", async () => {
let res = await fetch(`http://127.0.0.1:4321/`);
let html = await res.text();
let $ = cheerio.load(html);
expect($("#hasCF").text()).to.equal("true");
});

it("adds cache mocking", async () => {
let res = await fetch(`http://127.0.0.1:4321/caches`);
let html = await res.text();
let $ = cheerio.load(html);
expect($("#hasCACHE").text()).to.equal("true");
});

it("adds D1 mocking", async () => {
let res = await fetch(`http://127.0.0.1:4321/d1`);
let html = await res.text();
let $ = cheerio.load(html);
expect($("#hasDB").text()).to.equal("true");
expect($("#hasPRODDB").text()).to.equal("true");
expect($("#hasACCESS").text()).to.equal("true");
});

it("adds R2 mocking", async () => {
let res = await fetch(`http://127.0.0.1:4321/r2`);
let html = await res.text();
let $ = cheerio.load(html);
expect($("#hasBUCKET").text()).to.equal("true");
expect($("#hasPRODBUCKET").text()).to.equal("true");
expect($("#hasACCESS").text()).to.equal("true");
});

it("adds KV mocking", async () => {
let res = await fetch(`http://127.0.0.1:4321/kv`);
let html = await res.text();
let $ = cheerio.load(html);
expect($("#hasKV").text()).to.equal("true");
expect($("#hasPRODKV").text()).to.equal("true");
expect($("#hasACCESS").text()).to.equal("true");
});

it("adds DO mocking", async () => {
let res = await fetch(`http://127.0.0.1:4321/do`);
let html = await res.text();
let $ = cheerio.load(html);
expect($("#hasDO").text()).to.equal("true");
});
});
Loading

0 comments on commit 1f20071

Please sign in to comment.