Home / File/ custom-client-directives.test.js — astro Source File

custom-client-directives.test.js — astro Source File

Architecture documentation for custom-client-directives.test.js, a javascript file in the astro codebase. 5 imports, 0 dependents.

File javascript E2ETesting TestFixtures 5 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  0f73a651_d35e_b6e6_5487_2bad4a73cff5["custom-client-directives.test.js"]
  be670a78_841c_46e5_0af5_c5c328869ecb["test-adapter.js"]
  0f73a651_d35e_b6e6_5487_2bad4a73cff5 --> be670a78_841c_46e5_0af5_c5c328869ecb
  2ca394f6_a63d_3921_1f12_c5a979ea0039["test-utils.js"]
  0f73a651_d35e_b6e6_5487_2bad4a73cff5 --> 2ca394f6_a63d_3921_1f12_c5a979ea0039
  e27f6887_ea47_dd44_7933_5faa0f6bcf4d["testFactory"]
  0f73a651_d35e_b6e6_5487_2bad4a73cff5 --> e27f6887_ea47_dd44_7933_5faa0f6bcf4d
  c373140e_7fdf_7fff_8884_991b85bc22b5["waitForHydrate"]
  0f73a651_d35e_b6e6_5487_2bad4a73cff5 --> c373140e_7fdf_7fff_8884_991b85bc22b5
  f8fbe851_c5d6_c4ee_c044_67a751668c18["test"]
  0f73a651_d35e_b6e6_5487_2bad4a73cff5 --> f8fbe851_c5d6_c4ee_c044_67a751668c18
  style 0f73a651_d35e_b6e6_5487_2bad4a73cff5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { expect } from '@playwright/test';
import testAdapter from '../test/test-adapter.js';
import { testFactory, waitForHydrate } from './test-utils.js';

const test = testFactory(import.meta.url, {
	root: './fixtures/custom-client-directives/',
});

test.describe('Custom Client Directives - dev', () => {
	let devServer;

	test.beforeAll(async ({ astro }) => {
		devServer = await astro.startDevServer();
	});

	test.afterAll(async () => {
		await devServer.stop();
	});

	testClientDirectivesShared();
});

test.describe('Custom Client Directives - build static', () => {
	let previewServer;

	test.beforeAll(async ({ astro }) => {
		await astro.build();
		previewServer = await astro.preview();
	});

	test.afterAll(async () => {
		await previewServer.stop();
	});

	testClientDirectivesShared();
});

test.describe('Custom Client Directives - build server', () => {
	let previewServer;

	test.beforeAll(async ({ astro }) => {
		await astro.build({
			adapter: testAdapter({
				extendAdapter: {
					adapterFeatures: {
						buildOutput: 'static',
					},
				},
			}),
		});
		previewServer = await astro.preview();
	});

	test.afterAll(async () => {
		await previewServer.stop();
	});

	testClientDirectivesShared();
});

function testClientDirectivesShared() {
	test('client:click should work', async ({ astro, page }) => {
		await page.goto(astro.resolveUrl('/'));

		const incrementBtn = page.locator('#client-click .increment');
		const counterValue = page.locator('#client-click pre');

		await expect(counterValue).toHaveText('0');

		// Component only hydrates on first click
		await Promise.all([waitForHydrate(page, counterValue), incrementBtn.click()]);

		// Since first click only triggers hydration, this should stay 0
		await expect(counterValue).toHaveText('0');
		await incrementBtn.click();
		// Hydrated, this should be 1
		await expect(counterValue).toHaveText('1');
	});

	test('client:password should work', async ({ astro, page }) => {
		await page.goto(astro.resolveUrl('/'));

		const incrementBtn = page.locator('#client-password .increment');
		const counterValue = page.locator('#client-password pre');

		await expect(counterValue).toHaveText('0');
		await incrementBtn.click();
		// Not hydrated, so this should stay 0
		await expect(counterValue).toHaveText('0');

		// Type super cool password to activate password!
		await Promise.all([waitForHydrate(page, counterValue), page.keyboard.type('hunter2')]);

		await incrementBtn.click();
		// Hydrated, this should be 1
		await expect(counterValue).toHaveText('1');
	});

	test('Client directives should be passed options correctly', async ({ astro, page }) => {
		await page.goto(astro.resolveUrl('/'));

		const optionsContent = page.locator('#client-has-options pre');
		await waitForHydrate(page, optionsContent);

		const clientOptions = page.locator('#options');
		await expect(clientOptions).toHaveText(
			'Passed options are: {"message":"Hello! I was passed as an option"}',
		);
	});
}

Domain

Subdomains

Frequently Asked Questions

What does custom-client-directives.test.js do?
custom-client-directives.test.js is a source file in the astro codebase, written in javascript. It belongs to the E2ETesting domain, TestFixtures subdomain.
What functions are defined in custom-client-directives.test.js?
custom-client-directives.test.js defines 1 function(s): testClientDirectivesShared.
What does custom-client-directives.test.js depend on?
custom-client-directives.test.js imports 5 module(s): test, test-adapter.js, test-utils.js, testFactory, waitForHydrate.
Where is custom-client-directives.test.js in the architecture?
custom-client-directives.test.js is located at packages/astro/e2e/custom-client-directives.test.js (domain: E2ETesting, subdomain: TestFixtures, directory: packages/astro/e2e).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free