Mocky Balboa and Astro
How to use Mocky Balboa with Astro.
≥ 4.0.0
Installation
- pnpm
- npm
- yarn
pnpm add -D @mocky-balboa/astro
npm install -D @mocky-balboa/astro
yarn add -D @mocky-balboa/astro
If you're not already using it, you'll need to install the @astrojs/node
adapter as well.
You can skip installing @astrojs/node
if you are only running tests against dev mode (not recommended outside of local development).
- pnpm
- npm
- yarn
pnpm add -D @astrojs/node
npm install -D @astrojs/node
yarn add -D @astrojs/node
Usage
Dev mode
Everything needed to setup the integration is included in the @mocky-balboa/astro
integration which can be used in your Astro configuration file.
- TypeScript
- JavaScript
import { defineConfig } from "astro/config";
import node from "@astrojs/node";
import mockyBalboa from "@mocky-balboa/astro";
// https://astro.build/config
export default defineConfig({
integrations: [mockyBalboa()],
// You need to use the node adapter to build the server for running tests against
// If you are only running tests in dev mode (not recommended outside of local development),
// then you don't need to use the node adapter
adapter: node({
// Make sure to build the server as middleware
mode: "middleware",
}),
});
import { defineConfig } from "astro/config";
import node from "@astrojs/node";
import mockyBalboa from "@mocky-balboa/astro";
// https://astro.build/config
export default defineConfig({
integrations: [mockyBalboa()],
// You need to use the node adapter to build the server for running tests against
// If you are only running tests in dev mode (not recommended outside of local development),
// then you don't need to use the node adapter
adapter: node({
// Make sure to build the server as middleware
mode: "middleware",
}),
});
You can disable the module by setting enabled
to false
or just by simply removing the integration from your Astro configuration.
- TypeScript
- JavaScript
import { defineConfig } from "astro/config";
import mockyBalboa from "@mocky-balboa/astro";
// https://astro.build/config
export default defineConfig({
integrations: [mockyBalboa({ enabled: false })],
});
import { defineConfig } from "astro/config";
import mockyBalboa from "@mocky-balboa/astro";
// https://astro.build/config
export default defineConfig({
integrations: [mockyBalboa({ enabled: false })],
});
Build and serve
Build your Astro application ensuring the @mocky-balboa/astro
integration is enabled in your Astro configuration.
- pnpm
- npm
- yarn
pnpm astro build
npm astro build
yarn astro build
Now serve your Astro application using the mocky-balboa-astro
command.
- pnpm
- npm
- yarn
pnpm mocky-balboa-astro
npm mocky-balboa-astro
yarn mocky-balboa-astro
Run mocky-balboa-astro --help
for usage options or see below for all options.
Usage: mocky-balboa-astro [options] [dist-dir]
Starts a Node.js http server powered by Express for your Astro application as well as the necessary mocky-balboa servers
Arguments:
dist-dir Path to the directory where your Astro application is built (default: "dist")
Options:
-p, --port [port] Port to run the server on (default: "3000")
--websocket-port [websocketPort] Port to run the WebSocket server on (default: "58152")
-h, --hostname [hostname] Hostname to bind the server to (default: "0.0.0.0")
-t, --timeout [timeout] Timeout in milliseconds for the mock server to receive a response from the client (default: "5000")
--https Enable https server. Either https or http server is run, not both. When no --https-cert and --https-key are
provided, a self-signed certificate will be automatically generated.
--https-cert [certPath] Optional path to the https certificate file
--https-ca [caPath] Optional path to the https Certificate Authority file
--https-key [keyPath] Optional path to the https key file
-b, --base [base] Change this based on your astro.config.mjs, `base` option. They should match. (default: "/")
--help display help for command