refactor: cleaning up how URLs are resolved in e2e tests
This commit is contained in:
parent
aa2910030b
commit
b7db93ccc3
3 changed files with 7 additions and 23 deletions
|
@ -18,8 +18,8 @@ test.afterAll(async ({ astro }) => {
|
|||
await devServer.stop();
|
||||
});
|
||||
|
||||
test('Tailwind CSS', async ({ page }) => {
|
||||
await page.goto(`localhost:${devServer.address.port}/`);
|
||||
test('Tailwind CSS', async ({ page, astro }) => {
|
||||
await page.goto(astro.resolveUrl('/'));
|
||||
|
||||
await test.step('body', async () => {
|
||||
const body = page.locator('body');
|
||||
|
|
|
@ -1,25 +1,5 @@
|
|||
import { loadFixture as baseLoadFixture } from '../test/test-utils.js';
|
||||
|
||||
/**
|
||||
* Load Astro fixture
|
||||
* @param {AstroConfig} inlineConfig Astro config partial (note: must specify `root`)
|
||||
* @returns {Promise<Fixture>} The fixture. Has the following properties:
|
||||
* .config - Returns the final config. Will be automatically passed to the methods below:
|
||||
*
|
||||
* Build
|
||||
* .build() - Async. Builds into current folder (will erase previous build)
|
||||
* .readFile(path) - Async. Read a file from the build.
|
||||
*
|
||||
* Dev
|
||||
* .startDevServer() - Async. Starts a dev server at an available port. Be sure to call devServer.stop() before test exit.
|
||||
* .fetch(url) - Async. Returns a URL from the prevew server (must have called .preview() before)
|
||||
*
|
||||
* Preview
|
||||
* .preview() - Async. Starts a preview server. Note this can’t be running in same fixture as .dev() as they share ports. Also, you must call `server.close()` before test exit
|
||||
*
|
||||
* Clean-up
|
||||
* .clean() - Async. Removes the project’s dist folder.
|
||||
*/
|
||||
export function loadFixture(inlineConfig) {
|
||||
if (!inlineConfig || !inlineConfig.root)
|
||||
throw new Error("Must provide { root: './fixtures/...' }");
|
||||
|
|
|
@ -25,6 +25,7 @@ polyfill(globalThis, {
|
|||
*
|
||||
* @typedef {Object} Fixture
|
||||
* @property {typeof build} build
|
||||
* @property {(url: string) => string} resolveUrl
|
||||
* @property {(url: string, opts: any) => Promise<Response>} fetch
|
||||
* @property {(path: string) => Promise<string>} readFile
|
||||
* @property {(path: string) => Promise<string[]>} readdir
|
||||
|
@ -93,6 +94,8 @@ export async function loadFixture(inlineConfig) {
|
|||
},
|
||||
};
|
||||
|
||||
const resolveUrl = (url) => `http://${'127.0.0.1'}:${config.server.port}${url.replace(/^\/?/, '/')}`;
|
||||
|
||||
return {
|
||||
build: (opts = {}) => build(config, { mode: 'development', logging, telemetry, ...opts }),
|
||||
startDevServer: async (opts = {}) => {
|
||||
|
@ -101,8 +104,9 @@ export async function loadFixture(inlineConfig) {
|
|||
return devResult;
|
||||
},
|
||||
config,
|
||||
resolveUrl,
|
||||
fetch: (url, init) =>
|
||||
fetch(`http://${'127.0.0.1'}:${config.server.port}${url.replace(/^\/?/, '/')}`, init),
|
||||
fetch(resolveUrl(url), init),
|
||||
preview: async (opts = {}) => {
|
||||
const previewServer = await preview(config, { logging, telemetry, ...opts });
|
||||
return previewServer;
|
||||
|
|
Loading…
Reference in a new issue