-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Setup e2e tests for example and execute in CI
- Loading branch information
Showing
8 changed files
with
182 additions
and
3 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
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,59 @@ | ||
import { test, expect } from '@playwright/test'; | ||
|
||
test('Has Browser Tab Title', async ({ page }) => { | ||
await page.goto('/'); | ||
|
||
expect(await page.title()).toBe('NG-Remote-Config Example'); | ||
}); | ||
|
||
test('Has Title', async ({ page }) => { | ||
await page.goto('/'); | ||
|
||
expect(await page.locator('h1').innerText()).toContain( | ||
'NG-Remote-Config Example' | ||
); | ||
}); | ||
|
||
test("Has JSON Viewer for 'config.json'", async ({ page }) => { | ||
await page.goto('/'); | ||
|
||
expect(await page.locator('h2').first().innerText()).toContain('Config'); | ||
await expect(page.locator('app-editor').first()).toBeVisible(); | ||
}); | ||
|
||
test('Has same config as in config.json', async ({ page, request }) => { | ||
const response = await request.get('/assets/config.json'); | ||
expect(response.status()).toBe(200); | ||
|
||
const configJson = await response.json(); | ||
const configString = JSON.stringify(configJson, null, 2); // Formatting similar to the JSON pipe | ||
|
||
await page.goto('/'); | ||
|
||
const renderedJson = await page.locator('pre').first().textContent(); | ||
|
||
expect(renderedJson?.trim()).toBe(configString); | ||
}); | ||
|
||
test("Has JSON Viewer for 'features.json'", async ({ page }) => { | ||
await page.goto('/'); | ||
|
||
expect(await page.locator('h2').last().innerText()).toContain( | ||
'Feature Flags' | ||
); | ||
await expect(page.locator('app-editor').last()).toBeVisible(); | ||
}); | ||
|
||
test('Has same config as in features.json', async ({ page, request }) => { | ||
const response = await request.get('/assets/features.json'); | ||
expect(response.status()).toBe(200); | ||
|
||
const configJson = await response.json(); | ||
const configString = JSON.stringify(configJson, null, 2); // Formatting similar to the JSON pipe | ||
|
||
await page.goto('/'); | ||
|
||
const renderedJson = await page.locator('pre').last().textContent(); | ||
|
||
expect(renderedJson?.trim()).toBe(configString); | ||
}); |
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,13 @@ | ||
import { test, expect } from '@playwright/test'; | ||
|
||
test('has config file present and valid JSON', async ({ request }) => { | ||
const response = await request.get('/assets/config.json'); | ||
|
||
expect(response.status()).toBe(200); | ||
|
||
const responseBody = await response.text(); | ||
expect(() => JSON.parse(responseBody)).not.toThrow(); | ||
|
||
const json = JSON.parse(responseBody); | ||
expect(json).toHaveProperty('environment'); | ||
}); |
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,13 @@ | ||
import { test, expect } from '@playwright/test'; | ||
|
||
test('has feature config file present and valid JSON', async ({ request }) => { | ||
const response = await request.get('/assets/features.json'); | ||
|
||
expect(response.status()).toBe(200); | ||
|
||
const responseBody = await response.text(); | ||
expect(() => JSON.parse(responseBody)).not.toThrow(); | ||
|
||
const json = JSON.parse(responseBody); | ||
expect(json).toHaveProperty('isFeatureEnabled'); | ||
}); |
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
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,69 @@ | ||
import { defineConfig, devices } from '@playwright/test'; | ||
import { nxE2EPreset } from '@nx/playwright/preset'; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
import { workspaceRoot } from '@nx/devkit'; | ||
|
||
// For CI, you may want to set BASE_URL to the deployed application. | ||
const baseURL = process.env['BASE_URL'] || 'http://localhost:4200'; | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// require('dotenv').config(); | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
...nxE2EPreset(__filename, { testDir: './e2e' }), | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
baseURL, | ||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: 'on-first-retry', | ||
}, | ||
/* Run your local dev server before starting the tests */ | ||
webServer: { | ||
command: 'nx run ng-remote-config-example:serve', | ||
url: 'http://localhost:4200', | ||
reuseExistingServer: !process.env.CI, | ||
cwd: workspaceRoot, | ||
}, | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { ...devices['Desktop Chrome'] }, | ||
}, | ||
|
||
{ | ||
name: 'firefox', | ||
use: { ...devices['Desktop Firefox'] }, | ||
}, | ||
|
||
{ | ||
name: 'webkit', | ||
use: { ...devices['Desktop Safari'] }, | ||
}, | ||
|
||
// Uncomment for mobile browsers support | ||
/* { | ||
name: 'Mobile Chrome', | ||
use: { ...devices['Pixel 5'] }, | ||
}, | ||
{ | ||
name: 'Mobile Safari', | ||
use: { ...devices['iPhone 12'] }, | ||
}, */ | ||
|
||
// Uncomment for branded browsers | ||
/* { | ||
name: 'Microsoft Edge', | ||
use: { ...devices['Desktop Edge'], channel: 'msedge' }, | ||
}, | ||
{ | ||
name: 'Google Chrome', | ||
use: { ...devices['Desktop Chrome'], channel: 'chrome' }, | ||
} */ | ||
], | ||
}); |
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
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