-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
82aa5c8
commit 83fa727
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}}!'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |