-
Notifications
You must be signed in to change notification settings - Fork 8
[APPS] Add e2e test and frontend/ archive prefix for apps plugin #290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2f65ec0
Add e2e test for apps plugin
sdkennedy2 09c8c23
Prefix frontend assets with frontend/ in archive and verify in e2e test
sdkennedy2 cd58f1c
Fix e2e upload test: persist nock capture to file for cross-worker ac…
sdkennedy2 3fed514
Bump e2e CI timeout from 10m to 15m
sdkennedy2 153792d
Bump e2e CI timeout to 30m
sdkennedy2 f0c56f8
Use os.tmpdir() for upload capture and @dd/core/helpers/fs
sdkennedy2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,157 @@ | ||
| // 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 { existsSync, outputJsonSync, readJsonSync } from '@dd/core/helpers/fs'; | ||
| import { verifyProjectBuild } from '@dd/tests/_playwright/helpers/buildProject'; | ||
| import type { TestOptions } from '@dd/tests/_playwright/testParams'; | ||
| import { test } from '@dd/tests/_playwright/testParams'; | ||
| import { defaultConfig } from '@dd/tools/plugins'; | ||
| import type { Page } from '@playwright/test'; | ||
| import JSZip from 'jszip'; | ||
| import nock from 'nock'; | ||
| import os from 'os'; | ||
| import path from 'path'; | ||
|
|
||
| // Have a similar experience to Jest. | ||
| const { expect, beforeAll, describe } = test; | ||
|
|
||
| const APP_IDENTIFIER = 'e2e-test-app-id'; | ||
| const APP_NAME = 'e2e-test-app'; | ||
| const CAPTURE_DIR = path.join(os.tmpdir(), 'dd-e2e-apps-plugin'); | ||
|
|
||
| // Mock the apps upload endpoint and write captured request to a file. | ||
| // We write to a file because Playwright workers are separate processes — | ||
| // only the worker that actually builds captures the nock request. | ||
| nock('https://api.datadoghq.com') | ||
| .post(new RegExp(`/api/unstable/app-builder-code/apps/.*/upload`)) | ||
| .reply(function handleUploadMock(uri, body) { | ||
| const captured = { | ||
| path: uri, | ||
| headers: this.req.headers as Record<string, string>, | ||
| body: typeof body === 'string' ? body : JSON.stringify(body), | ||
| }; | ||
| // Write to a known location so all workers can read it. | ||
| outputJsonSync(path.join(CAPTURE_DIR, 'upload-capture.json'), captured); | ||
| return [ | ||
| 200, | ||
| { | ||
| version_id: 'v-test-123', | ||
| application_id: 'app-test-123', | ||
| app_builder_id: 'builder-test-123', | ||
| }, | ||
| ]; | ||
| }) | ||
| .persist(); | ||
|
|
||
| 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'); | ||
| }; | ||
|
|
||
| // Read captured upload request from the shared temp file. | ||
| const readUploadCapture = () => { | ||
| const capturePath = path.join(CAPTURE_DIR, 'upload-capture.json'); | ||
| if (!existsSync(capturePath)) { | ||
| return null; | ||
| } | ||
| return readJsonSync(capturePath) as { | ||
| path: string; | ||
| headers: Record<string, string>; | ||
| body: string; | ||
| }; | ||
| }; | ||
|
|
||
| describe('Apps Plugin', () => { | ||
| // Build our fixture project with the apps plugin enabled and upload active. | ||
| beforeAll(async ({ publicDir, bundlers, suiteName }) => { | ||
| const source = path.resolve(__dirname, 'project'); | ||
| const destination = path.resolve(publicDir, suiteName); | ||
| await verifyProjectBuild(source, destination, bundlers, { | ||
| ...defaultConfig, | ||
| apps: { | ||
| enable: true, | ||
| dryRun: false, | ||
| identifier: APP_IDENTIFIER, | ||
| name: APP_NAME, | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| test('Should build and 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) => { | ||
| if (msg.type() !== 'log') { | ||
| return; | ||
| } | ||
| 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. | ||
| const bundleRequest = page.waitForResponse(`${testBaseUrl}/dist/${bundler}.js`); | ||
| await userFlow(testBaseUrl, page, bundler); | ||
| expect((await bundleRequest).ok()).toBe(true); | ||
|
|
||
| expect(logs).toEqual([`Hello from apps plugin, ${bundler}!`]); | ||
| expect(errors).toHaveLength(0); | ||
| }); | ||
|
|
||
| test('Should have uploaded assets to the apps intake', async () => { | ||
| // Read captured upload from the shared file written by the building worker. | ||
| const uploadRequest = readUploadCapture(); | ||
|
|
||
| // The upload happens during the build phase in beforeAll. | ||
| expect(uploadRequest).not.toBeNull(); | ||
|
|
||
| // Verify the upload URL contains the app identifier. | ||
| expect(uploadRequest!.path).toContain( | ||
| `/api/unstable/app-builder-code/apps/${APP_IDENTIFIER}/upload`, | ||
| ); | ||
|
|
||
| // Verify the origin headers are set. | ||
| expect(uploadRequest!.headers['dd-evp-origin']).toMatch(/-build-plugin_apps$/); | ||
| expect(uploadRequest!.headers['dd-evp-origin-version']).toBeDefined(); | ||
|
|
||
| // The body is hex-encoded multipart form data. Decode it to verify contents. | ||
| const decodedBody = Buffer.from(uploadRequest!.body, 'hex').toString('utf-8'); | ||
| expect(decodedBody).toContain(APP_NAME); | ||
| expect(decodedBody).toContain('datadog-apps-assets.zip'); | ||
|
|
||
| // Extract the zip from the multipart body and verify all files are under frontend/. | ||
| const bodyBuffer = Buffer.from(uploadRequest!.body, 'hex'); | ||
| const zipMagic = Buffer.from([0x50, 0x4b, 0x03, 0x04]); | ||
| const zipStart = bodyBuffer.indexOf(zipMagic); | ||
| expect(zipStart).toBeGreaterThanOrEqual(0); | ||
|
|
||
| const zip = await JSZip.loadAsync(bodyBuffer.subarray(zipStart)); | ||
| const filePaths = Object.keys(zip.files); | ||
| expect(filePaths.length).toBeGreaterThan(0); | ||
| for (const filePath of filePaths) { | ||
| expect(filePath).toMatch(/^frontend\//); | ||
| } | ||
| }); | ||
| }); |
This file contains hidden or 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>Apps Plugin Test</title> | ||
| </head> | ||
|
|
||
| <body> | ||
| <h1>Welcome to the {{bundler}} Apps Plugin Test</h1> | ||
| <p>This page verifies the build output works with the apps plugin enabled.</p> | ||
|
|
||
| <script src="./dist/{{bundler}}.js"></script> | ||
| </body> | ||
|
|
||
| </html> |
This file contains hidden or 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 from apps plugin, {{bundler}}!'); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an explanation for this increase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The e2e CI/CD job is very flaky. It can take between 5-30 minutes. It seems primarily because it can take a while to install playwright if it isn't cached.