Skip to content

Commit

Permalink
Add a smoke test
Browse files Browse the repository at this point in the history
  • Loading branch information
yoannmoinet committed Feb 10, 2025
1 parent 82aa5c8 commit 83fa727
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/tests/src/e2e/smokeTest/project/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/svg+xml" sizes="21x21" href="data:image/svg+xml,">
<title>Basic HTML Page</title>
</head>

<body>
<h1>Welcome to the {{bundler}} Home page</h1>
<p>This is just some simple text.</p>

<script src="./dist/{{bundler}}.js"></script>
</body>

</html>
5 changes: 5 additions & 0 deletions packages/tests/src/e2e/smokeTest/project/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-Present Datadog, Inc.

console.log('Hello, {{bundler}}!');
65 changes: 65 additions & 0 deletions packages/tests/src/e2e/smokeTest/smokeTest.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-Present Datadog, Inc.

import { verifyProjectBuild } from '@dd/tests/_playwright/helpers/buildProject';
import type { TestOptions } from '@dd/tests/_playwright/testParams';
import { test } from '@dd/tests/_playwright/testParams';
import type { Page } from '@playwright/test';
import path from 'path';

// Have a similar experience to Jest.
const { expect, beforeAll, describe } = test;

const userFlow = async (url: string, page: Page, bundler: TestOptions['bundler']) => {
// Navigate to our page.
await page.goto(`${url}/index.html?context_bundler=${bundler}`);
await page.waitForSelector('body');
};

describe('Browser SDK injection', () => {
// Build our fixture project.
beforeAll(async ({ publicDir, bundlers, suiteName }) => {
const source = path.resolve(__dirname, 'project');
const destination = path.resolve(publicDir, suiteName);
await verifyProjectBuild(source, destination, bundlers);
});

test('Should load the page without errors', async ({
page,
bundler,
browserName,
suiteName,
devServerUrl,
}) => {
const errors: string[] = [];
const testBaseUrl = `${devServerUrl}/${suiteName}`;

// Listen for errors on the page.
page.on('pageerror', (error) => errors.push(error.message));
page.on('response', async (response) => {
if (!response.ok()) {
const url = response.request().url();
const prefix = `[${bundler} ${browserName} ${response.status()}]`;
errors.push(`${prefix} ${url}`);
}
});

// Verify that we do log the expected things.
const logs: string[] = [];
page.on('console', async (msg) => {
for (const arg of msg.args()) {
// eslint-disable-next-line no-await-in-loop
logs.push(await arg.jsonValue());
}
});

// It should load the correct bundler file too.
const bundleRequest = page.waitForResponse(`${testBaseUrl}/dist/${bundler}.js`);
await userFlow(testBaseUrl, page, bundler);
expect((await bundleRequest).ok()).toBe(true);

expect(logs).toEqual([`Hello, ${bundler}!`]);
expect(errors).toHaveLength(0);
});
});

0 comments on commit 83fa727

Please sign in to comment.