Skip to content

Commit ee7bb53

Browse files
CCM-11724: test timeouts (#651)
Co-authored-by: ben.hansell1 <[email protected]>
1 parent 464fc44 commit ee7bb53

File tree

10 files changed

+127
-20
lines changed

10 files changed

+127
-20
lines changed

.github/actions/test-types.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"api",
44
"event",
55
"ui-component",
6-
"ui-e2e"
6+
"ui-e2e",
7+
"ui-user-timeout"
78
]

scripts/tests/test.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ test-ui-e2e: # Run tests from scripts/tests/ui-e2e.sh @Testing
3232
test-api: # Run tests from scripts/tests/api.sh @Testing
3333
make _test name="api"
3434

35+
test-ui-user-timeout: # Run tests from scripts/tests/ui-user-timeout.sh @Testing
36+
make _test name="ui-user-timeout"
37+
3538
test-event: # Run tests from scripts/tests/event.sh @Testing
3639
make _test name="event"
3740

@@ -45,6 +48,7 @@ test: # Run all the test tasks @Testing
4548
test-ui-e2e \
4649
test-api \
4750
test-accessibility \
51+
test-ui-user-timeout \
4852

4953
_test:
5054
set -e
@@ -65,5 +69,6 @@ ${VERBOSE}.SILENT: \
6569
test-ui-component \
6670
test-api \
6771
test-ui-e2e \
72+
test-ui-user-timeout \
6873
test-unit \
6974
test-event \

scripts/tests/ui-user-timeout.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
cd "$(git rev-parse --show-toplevel)"
5+
npx playwright install --with-deps > /dev/null
6+
cd tests/test-team
7+
TEST_EXIT_CODE=0
8+
npm run test:user-timeout || TEST_EXIT_CODE=$?
9+
echo "TEST_EXIT_CODE=$TEST_EXIT_CODE"
10+
11+
mkdir -p ../acceptance-test-report
12+
cp -r ./playwright-report ../acceptance-test-report
13+
[[ -e test-results ]] && cp -r ./test-results ../acceptance-test-report
14+
15+
exit $TEST_EXIT_CODE

tests/test-team/config/component/component.config.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import baseConfig from '../playwright.config';
44

55
const buildCommand = [
66
'INCLUDE_AUTH_PAGES=true',
7-
// 'NEXT_PUBLIC_TIME_TILL_LOGOUT_SECONDS=25',
8-
// 'NEXT_PUBLIC_PROMPT_SECONDS_BEFORE_LOGOUT=5',
97
'npm run build && npm run start',
108
].join(' ');
119

@@ -40,21 +38,6 @@ export default defineConfig({
4038
dependencies: ['component:setup'],
4139
teardown: 'component:teardown',
4240
},
43-
/*{
44-
name: 'modal',
45-
testMatch: 'template-mgmt-logout-warning.component.modal.spec.ts',
46-
use: {
47-
screenshot: 'only-on-failure',
48-
baseURL: 'http://localhost:3000',
49-
...devices['Desktop Chrome'],
50-
headless: true,
51-
storageState: path.resolve(__dirname, '../.auth/user.json'),
52-
},
53-
timeout: 60_000,
54-
dependencies: ['component:setup'],
55-
teardown: 'component:teardown',
56-
fullyParallel: true, // make these sets of tests parallel due to their slow nature.
57-
},*/
5841
{
5942
name: 'component:teardown',
6043
testMatch: 'component.teardown.ts',

tests/test-team/config/e2e/e2e.config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import baseConfig from '../playwright.config';
44

55
const buildCommand = [
66
'INCLUDE_AUTH_PAGES=true',
7-
'NEXT_PUBLIC_TIME_TILL_LOGOUT_SECONDS=900',
8-
'NEXT_PUBLIC_PROMPT_SECONDS_BEFORE_LOGOUT=5',
97
'npm run build && npm run start',
108
].join(' ');
119

tests/test-team/config/global.setup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { randomUUID } from 'node:crypto';
22

33
async function globalSetup() {
44
process.env.PLAYWRIGHT_RUN_ID = randomUUID();
5+
console.log(`=== RunId: ${process.env.PLAYWRIGHT_RUN_ID} ===`);
56
}
67

78
export default globalSetup;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import path from 'node:path';
2+
import { defineConfig, devices } from '@playwright/test';
3+
import baseConfig from '../playwright.config';
4+
5+
const buildCommand = [
6+
'INCLUDE_AUTH_PAGES=true',
7+
'NEXT_PUBLIC_TIME_TILL_LOGOUT_SECONDS=25',
8+
'NEXT_PUBLIC_PROMPT_SECONDS_BEFORE_LOGOUT=5',
9+
'npm run build && npm run start',
10+
].join(' ');
11+
12+
export default defineConfig({
13+
...baseConfig,
14+
15+
timeout: 30_000, // 30 seconds in the playwright default
16+
expect: {
17+
timeout: 10_000, // default is 5 seconds. After creating and previewing sometimes the load is slow on a cold start
18+
},
19+
projects: [
20+
{
21+
name: 'component:setup',
22+
testMatch: 'component.setup.ts',
23+
use: {
24+
baseURL: 'http://localhost:3000',
25+
...devices['Desktop Chrome'],
26+
headless: true,
27+
screenshot: 'only-on-failure',
28+
},
29+
},
30+
{
31+
name: 'modal',
32+
testMatch: 'template-mgmt-logout-warning.component.modal.spec.ts',
33+
use: {
34+
screenshot: 'only-on-failure',
35+
baseURL: 'http://localhost:3000',
36+
...devices['Desktop Chrome'],
37+
headless: true,
38+
storageState: path.resolve(__dirname, '../.auth/user.json'),
39+
},
40+
timeout: 60_000,
41+
dependencies: ['component:setup'],
42+
teardown: 'component:teardown',
43+
fullyParallel: true, // make these sets of tests parallel due to their slow nature.
44+
},
45+
{
46+
name: 'component:teardown',
47+
testMatch: 'component.teardown.ts',
48+
},
49+
],
50+
/* Run your local dev server before starting the tests */
51+
webServer: {
52+
timeout: 2 * 60 * 1000, // 2 minutes
53+
command: buildCommand,
54+
cwd: path.resolve(__dirname, '../../../..'),
55+
url: 'http://localhost:3000/templates/create-and-submit-templates',
56+
reuseExistingServer: !process.env.CI,
57+
stderr: 'pipe',
58+
},
59+
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Playwright setting up Auth -> https://playwright.dev/docs/auth
3+
*/
4+
5+
import path from 'node:path';
6+
import { test as setup } from '@playwright/test';
7+
import { BackendConfigHelper } from 'nhs-notify-web-template-management-util-backend-config';
8+
import { TemplateMgmtSignInPage } from '../../pages/templates-mgmt-login-page';
9+
import {
10+
createAuthHelper,
11+
testUsers,
12+
} from '../../helpers/auth/cognito-auth-helper';
13+
14+
setup('component test setup', async ({ page }) => {
15+
const backendConfig = BackendConfigHelper.fromTerraformOutputsFile(
16+
path.join(__dirname, '..', '..', '..', '..', 'sandbox_tf_outputs.json')
17+
);
18+
19+
BackendConfigHelper.toEnv(backendConfig);
20+
21+
const auth = createAuthHelper();
22+
23+
await auth.setup();
24+
25+
const user = await auth.getTestUser(testUsers.User1.userId);
26+
27+
const loginPage = new TemplateMgmtSignInPage(page);
28+
29+
await loginPage.loadPage();
30+
31+
await loginPage.cognitoSignIn(user);
32+
33+
await page.waitForURL('/templates/create-and-submit-templates');
34+
35+
await page.context().storageState({
36+
path: path.resolve(__dirname, '..', '.auth', 'user.json'),
37+
});
38+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { test as teardown } from '@playwright/test';
2+
import { createAuthHelper } from '../../helpers/auth/cognito-auth-helper';
3+
4+
teardown('component test teardown', async () => {
5+
await createAuthHelper().teardown();
6+
});

tests/test-team/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"test:api": "playwright test --project api -c config/api/api.config.ts",
3333
"test:event": "playwright test -c config/event/event.config.ts",
3434
"test:e2e": "playwright test --project e2e -c config/e2e/e2e.config.ts",
35+
"test:user-timeout": "playwright test -c config/user-timeout/user-timeout.config.ts",
3536
"test:local-ui": "playwright test -c config/component/component.config.ts",
3637
"test:unit": "echo \"Unit tests not required\"",
3738
"typecheck": "tsc --noEmit"

0 commit comments

Comments
 (0)