Skip to content

Commit 000ca4c

Browse files
E2E Test Setup
1 parent 859c4cb commit 000ca4c

File tree

12 files changed

+411
-1
lines changed

12 files changed

+411
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ version.json
1212

1313
# Please, add your custom content below!
1414
.idea
15+
.env
1516

1617
# dependencies
1718
node_modules

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
//".devcontainer": true,
1212
".github": false,
1313
".vscode": false
14-
}
14+
},
1515
}

tests/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
# Playwright
3+
node_modules/
4+
/test-results/
5+
/playwright-report/
6+
/blob-report/
7+
/playwright/.cache/
8+
/allure-results
9+
/target

tests/config/main.config.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { PlaywrightTestConfig } from '@playwright/test';
2+
import { config as baseConfig } from './playwright.base.config';
3+
import { getReporters } from './reporters';
4+
5+
const localConfig: PlaywrightTestConfig = {
6+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
7+
reporter: getReporters('api-test'),
8+
...baseConfig,
9+
//globalSetup: require.resolve('./setup/globalSetup'),
10+
//globalTeardown: require.resolve('./setup/globalTeardown'),
11+
testIgnore: [],
12+
projects: [
13+
{
14+
name: 'sandbox',
15+
testMatch: 'tests/messages/get_single_letter/*.spec.ts',
16+
},
17+
],
18+
};
19+
20+
export default localConfig;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import type { PlaywrightTestConfig } from '@playwright/test';
2+
3+
const baseUrl = process.env.NHSD_APIM_PROXY_URL || 'http://localhost:3000/';
4+
const envMaxInstances = Number.parseInt(process.env.WORKERS_MAX_INST!) || 10;
5+
/**
6+
* See https://playwright.dev/docs/test-configuration.
7+
*/
8+
export const config: PlaywrightTestConfig = {
9+
testDir: '../sandbox/messages/get_single_letter/',
10+
testMatch: '*.spec.ts/',
11+
/* Maximum time one test can run for. */
12+
timeout: 60 * 1000,
13+
workers: envMaxInstances,
14+
expect: {
15+
/**
16+
* Maximum time expect() should wait for the condition to be met.
17+
* For example in `await expect(locator).toHaveText();`
18+
*/
19+
timeout: 5000,
20+
},
21+
/* Run tests in files in parallel */
22+
fullyParallel: true,
23+
/* Fail the build on CI if you accidentally left test.only in the source code. */
24+
forbidOnly: !!process.env.CI,
25+
/* Retry on CI only */
26+
retries: process.env.CI ? 2 : 0,
27+
28+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
29+
use: {
30+
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
31+
actionTimeout: 0,
32+
/* Base URL to use in actions like `await page.goto('/')`. */
33+
baseURL: baseUrl,
34+
ignoreHTTPSErrors: true,
35+
trace: 'on-first-retry',
36+
/* Slows down Playwright operations by the specified amount of milliseconds. */
37+
launchOptions: {
38+
slowMo: 0,
39+
},
40+
},
41+
};
42+
export default config;

tests/config/reporters.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import type { ReporterDescription } from '@playwright/test';
2+
3+
const resultsDir = process.env.RESULTS_DIR || 'results';
4+
const reportsDir = process.env.REPORTS_DIR || 'reports';
5+
6+
export function getReporters(allureFolder: string) {
7+
return [
8+
[
9+
'allure-playwright',
10+
{
11+
outputFolder: `./target/reports/allure-results/${allureFolder}`,
12+
detail: false,
13+
suiteTitle: true,
14+
open: 'always',
15+
environmentInfo: {
16+
E2E_NODE_VERSION: process.env.ENVIRONMENT,
17+
E2E_OS: process.platform,
18+
},
19+
},
20+
],
21+
[
22+
'html',
23+
{
24+
outputFolder: `../target/test-artifacts/${reportsDir}/html-report`,
25+
open: process.env.CI ? 'never' : 'on-failure',
26+
},
27+
],
28+
['list', { printSteps: true }],
29+
[
30+
'junit',
31+
{
32+
outputFile: `../target/test-artifacts/${resultsDir}/junit-results.xml`,
33+
},
34+
],
35+
[
36+
'json',
37+
{
38+
outputFile: `../target/test-artifacts/${resultsDir}/json-results.json`,
39+
},
40+
],
41+
] as ReporterDescription[];
42+
}

tests/constants/api_constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const LETTERS_ENDPOINT = 'letters';

tests/mtls/mtls_test.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { test, expect, request, APIRequestContext } from '@playwright/test';
2+
3+
// Assume you have your constants in a config file
4+
const PROXY_URL = process.env.PROXY_URL;
5+
6+
test('should fail when connecting without client certificate', async () => {
7+
8+
let apiContext: APIRequestContext | null = null;
9+
10+
try {
11+
apiContext = await request.newContext();
12+
const response = await apiContext.get(PROXY_URL!, {
13+
headers: { "X-Client-Id": "hello" }
14+
});
15+
16+
// Check if request succeeded or failed
17+
if (response.ok()) {
18+
throw new Error(
19+
`Expected connection failure, but got success with status ${response.status()}`
20+
);
21+
}
22+
// Assert on the actual error code returned by the gateway
23+
// For mTLS, often 401, 403, or 502 depending on infra config
24+
expect(response.ok()).toBeFalsy();
25+
26+
} catch (err: any) {
27+
// If the request truly fails at the TLS layer, Playwright will throw instead
28+
expect(err.message).toMatch(/SSL|certificate|ECONNRESET|socket/i);
29+
} finally {
30+
if (apiContext) {
31+
await apiContext.dispose();
32+
}
33+
}
34+
});

tests/package-lock.json

Lines changed: 179 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"author": "",
3+
"dependencies": {
4+
"allure-js-commons": "^3.3.3",
5+
"charenc": "^0.0.2",
6+
"crypt": "^0.0.2",
7+
"dotenv": "^17.2.2",
8+
"fsevents": "^2.3.2",
9+
"is-buffer": "^1.1.6",
10+
"md5": "^2.3.0",
11+
"playwright": "^1.54.2",
12+
"playwright-core": "^1.54.2",
13+
"undici-types": "^7.10.0"
14+
},
15+
"description": "",
16+
"devDependencies": {
17+
"@playwright/test": "^1.55.0",
18+
"@types/node": "^24.3.1",
19+
"allure-commandline": "^2.34.1",
20+
"allure-playwright": "^3.3.3"
21+
},
22+
"keywords": [],
23+
"license": "ISC",
24+
"main": "index.js",
25+
"name": "tests",
26+
"scripts": {
27+
"clean": "rimraf $(pwd)/target",
28+
"test": "playwright test tests --config=config/main.config.ts --max-failures=10"
29+
},
30+
"version": "1.0.0"
31+
}

0 commit comments

Comments
 (0)